-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
93 lines (76 loc) · 2.91 KB
/
script.js
File metadata and controls
93 lines (76 loc) · 2.91 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
(async () => {
const v1ModsList = document.getElementById("v1-mods");
if (v1ModsList) {
const classes = ["bg-black", "text-light", "list-group-item", "list-group-item-action", "list-group-item-dark", "clickable-copy", "hover-pulse"];
const v1Mods = await fetch("modloader/mods/v1.json").then(r => r.json());
for (let key in v1Mods) {
const mod = v1Mods[key];
const listEntry = document.createElement("li");
listEntry.classList.add(...classes);
listEntry.setAttribute("copy", key);
listEntry.innerHTML = `${mod.name} (${key})`
v1ModsList.appendChild(listEntry);
}
}
const links = document.getElementsByClassName("clickable-link");
for (var i = 0; i < links.length; i++) {
let link = links[i];
link.addEventListener("click", () => {
window.open(link.getAttribute("link"), "_blank");
let text = link.innerHTML;
link.innerHTML = "Opened!";
setTimeout(() => {
link.innerHTML = text;
}, 1000);
});
}
const copies = document.getElementsByClassName("clickable-copy");
for (var i = 0; i < copies.length; i++) {
let copy = copies[i];
copy.addEventListener("click", () => {
copyTextToClipboard(copy.getAttribute("copy"));
let text = copy.innerHTML;
copy.innerHTML = "Copied!";
setTimeout(() => {
copy.innerHTML = text;
}, 1000);
});
}
const hoverPulses = document.getElementsByClassName("hover-pulse");
for (let i = 0; i <= hoverPulses.length; i++) {
let hoverPulse = hoverPulses[i];
if (hoverPulse) {
hoverPulse.addEventListener("animationend", function(e) {
hoverPulse.classList.remove("hover-pulse-animation");
});
hoverPulse.addEventListener("mouseover", function(e) {
hoverPulse.classList.add("hover-pulse-animation")
});
}
}
function fallbackCopyTextToClipboard(text) {
var textArea = document.createElement("textarea");
textArea.value = text;
// Avoid scrolling to bottom
textArea.style.top = "0";
textArea.style.left = "0";
textArea.style.position = "fixed";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
var successful = document.execCommand("copy");
var msg = successful ? "successful" : "unsuccessful";
} catch (err) {
console.error("Fallback: Oops, unable to copy", err);
}
document.body.removeChild(textArea);
}
function copyTextToClipboard(text) {
if (!navigator.clipboard) {
fallbackCopyTextToClipboard(text);
return;
}
navigator.clipboard.writeText(text);
}
})();