-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
60 lines (55 loc) · 1.83 KB
/
script.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function copy(text) {
navigator.clipboard.writeText(text).then(r => console.log("Copy status", r));
Swal.fire({
icon: 'success',
showConfirmButton: false,
timer: 1500
})
}
if (localStorage.getItem("pref") === null) {
localStorage.setItem("pref", "FR");
}
let btns = document.getElementsByClassName("btn");
function keyDown(e) {
// this would test for whichever key is 40 (down arrow) and the ctrl key at the same time
if (e.key === "Shift") {
// call your function to do the thing
for (let i = 0; i < btns.length; i++) {
if(!btns[i].classList.contains("dont-change")) {
btns[i].textContent = btns[i].textContent.toUpperCase();
btns[i].addEventListener("click", function () {
copy(this.textContent)
});
}
}
}
}
function keyUp() {
for (let i = 0; i < btns.length; i++) {
if(!btns[i].classList.contains("dont-change")) {
btns[i].textContent = btns[i].textContent.toLowerCase();
btns[i].addEventListener("click", function () {
copy(this.textContent)
});
}
}
}
// register the handler
document.addEventListener('keydown', keyDown, false);
document.addEventListener('keyup', keyUp, false);
let radios = document.getElementsByClassName("radio");
for (let i = 0; i < radios.length; i++) {
radios[i].addEventListener("click", function () {
localStorage.setItem("pref", radios[i].id)
})
}
for (let i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function () {
copy(this.textContent)
});
}
registeredTabs = ["FR", "ES", "DE", "IT", "PT", "NL", "PL", "more", "about"];
let pref = localStorage.getItem("pref");
if(registeredTabs.includes(pref)) {
document.getElementById(pref).click();
}