22 lines
No EOL
877 B
JavaScript
22 lines
No EOL
877 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
|
|
}
|
|
})
|
|
}
|
|
updateCopy();
|
|
|
|
window.x0?.registerModuleUpdateHook("copy", updateCopy);
|
|
window.x0?.registerModuleRemoveHook("copy", () => {
|
|
document.querySelectorAll("[x-copy-query]").forEach(e => e.innerHTML = "");
|
|
});
|
|
})() |