deploy: eec73e9749
This commit is contained in:
35
script.js
Normal file
35
script.js
Normal file
@@ -0,0 +1,35 @@
|
||||
function findParent(el, find) {
|
||||
do {
|
||||
if (find(el)) {
|
||||
return el;
|
||||
}
|
||||
} while (el = el.parentElement);
|
||||
}
|
||||
|
||||
document.addEventListener("click", (e) => {
|
||||
const target = findParent(
|
||||
e.target,
|
||||
(el) => el instanceof HTMLButtonElement && el.dataset["copy"],
|
||||
);
|
||||
if (target) {
|
||||
navigator?.clipboard?.writeText(target.dataset["copy"]);
|
||||
target.classList.add("copied");
|
||||
setTimeout(() => target.classList.remove("copied"), 1000);
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener("load", () => {
|
||||
const usageSelector = document.getElementById("usageSelector");
|
||||
|
||||
document.addEventListener("mouseup", (e) => {
|
||||
if (
|
||||
findParent(
|
||||
e.target,
|
||||
(el) =>
|
||||
el.parentElement === usageSelector && el instanceof HTMLDivElement,
|
||||
)
|
||||
) {
|
||||
usageSelector.open = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user