-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (74 loc) · 2.3 KB
/
index.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function menuBarTimer() {
var modd = document.body.querySelector("#modd-option");
var mod = document.querySelector("#menu-bar");
var modHovered = false;
var moddHovered = false;
modd.addEventListener("mouseenter", () => {
modHovered = false;
mod.classList.add("block");
moddHovered = true;
try {
clearTimeout(moddTimeout);
} catch (e) {
}
});
modd.addEventListener("mouseleave", () => {
window.moddTimeout = setTimeout(() => {
if (!modHovered) {
mod.classList.remove("block");
moddHovered = false
}
}, 600);
});
mod.addEventListener("mouseenter", () => {
moddHovered = false;
mod.classList.add("block");
modHovered = true;
try {
clearTimeout(modTimeout);
} catch (e) {
}
});
mod.addEventListener("mouseleave", () => {
window.modTimeout = setTimeout(() => {
if (!moddHovered) {
mod.classList.remove("block");
modHovered = false
}
}, 600);
});
}
function copyText(text, customMessage = "Copied text to clipboard") {
navigator.clipboard.writeText(text);
toast(customMessage);
}
function toast(text, len = 3000) {
document.body.querySelectorAll("toast").forEach((e) => e.remove());
var toast = document.createElement("toast");
toast.textContent = text;
toast.style.animation = "fade " + len / 1000 + "s";
toast.addEventListener("click", () => toast.remove());
document.body.appendChild(toast);
setTimeout(() => {
try {
document.body.removeChild(toast);
} catch (e) { }
}, len);
}
function goTo(e) {
var eStyle = getComputedStyle(e);
var navBarStyle = getComputedStyle(document.getElementById("nav-bar"));
var offsetY = getCoords(e);
document.body.scrollBy({ behavior: "smooth", top: -(offsetY + parseInt(navBarStyle.height) + parseInt(eStyle.marginTop)) });
}
function getCoords(e) {
var offsetY = 0;
function c(el) {
offsetY = el.offsetY;
}
var click = new MouseEvent("click");
e.addEventListener("click", c,)
e.dispatchEvent(click);
e.removeEventListener("click", c)
return offsetY;
}