21 lines
No EOL
859 B
JavaScript
21 lines
No EOL
859 B
JavaScript
// [x-copy-query="<query selector>"]
|
|
// [x-inner-text] - will use innerText
|
|
(() => {
|
|
function updateCopy() {
|
|
document.querySelectorAll("[x-copy-query]:not([x1-copy-uuid])")
|
|
.forEach(e => {
|
|
let uuid = new Date().getTime().toString(36);
|
|
e.setAttribute("x1-copy-uuid", uuid);
|
|
if (e.hasAttribute("x-inner-text")) {
|
|
e.innerText = document.querySelector(e.getAttribute("x-copy-query")).innerHTML
|
|
} else {
|
|
e.innerHTML = document.querySelector(e.getAttribute("x-copy-query")).innerHTML
|
|
}
|
|
})
|
|
}
|
|
|
|
window.x0?.registerModuleUpdateHook("copy", updateCopy);
|
|
window.x0?.registerModuleRemoveHook("copy", () => {
|
|
document.querySelectorAll("[x-copy-query]").forEach(e => e.innerHTML = "");
|
|
});
|
|
})() |