x0/modules/copy.js

24 lines
962 B
JavaScript
Raw Normal View History

2023-12-24 00:32:43 +01:00
// [x-copy-query="<query selector>"]
// [x-inner-text] - will use innerText
(() => {
// TODO: make copy work with checksums because not uuid will not always cut it.
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
}
})
}
2023-12-24 03:05:55 +01:00
updateCopy();
window.x0?.registerModuleUpdateHook("copy", updateCopy);
window.x0?.registerModuleRemoveHook("copy", () => {
document.querySelectorAll("[x-copy-query]").forEach(e => e.innerHTML = "");
});
})()