/
clipboard.js
38 lines (34 loc) · 1.03 KB
/
clipboard.js
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
36
37
38
import contact from "../../data/contact.json";
/*
#########################
Copy PGP key to clipboard
#########################
*/
export function clipboardCopy() {
const copyBtns = document.getElementsByClassName("js-btn-copy");
if (copyBtns) {
const btnsArr = Array.from(copyBtns);
btnsArr.forEach((btn) => {
btn.addEventListener("click", function () {
let str = "";
if (btn.classList.contains("js-data-long_id")) {
str = contact.pgp_long_id;
} else {
str = contact.pgp_fingerprint;
}
const textArea = document.createElement("textarea");
textArea.style.position = "absolute";
textArea.style.top = "-9999px";
textArea.value = str;
document.body.appendChild(textArea);
textArea.select();
document.execCommand("copy");
document.body.removeChild(textArea);
btn.classList.add("js-copied");
setTimeout(function () {
btn.classList.remove("js-copied");
}, 2500);
});
});
}
}