-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (32 loc) · 824 Bytes
/
Copy pathscript.js
File metadata and controls
35 lines (32 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
}
});
});