Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
166 lines (145 loc) · 5.47 KB
/
Copy pathscript.js
File metadata and controls
166 lines (145 loc) · 5.47 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const navToggle = document.querySelector(".nav-toggle");
const siteNav = document.querySelector(".site-nav");
const siteHeader = document.querySelector(".site-header");
const navLinks = document.querySelectorAll(".site-nav a");
const reveals = document.querySelectorAll(".reveal");
const playButtons = document.querySelectorAll("[data-video]");
const videoDialog = document.querySelector("#video-dialog");
const dialogVideo = document.querySelector("#dialog-video");
const dialogTitle = document.querySelector("#video-dialog-title");
const dialogClose = document.querySelector(".dialog-close");
const heroVideo = document.querySelector(".hero-frame video");
const copyButtons = document.querySelectorAll("[data-copy]");
const toast = document.querySelector(".toast");
const currentYear = document.querySelector("#current-year");
const homeBrandLinks = document.querySelectorAll('.brand[href="#top"]');
homeBrandLinks.forEach((link) => {
link.addEventListener("click", (event) => {
event.preventDefault();
closeNavigation();
window.history.replaceState(null, "", `${window.location.pathname}${window.location.search}`);
window.scrollTo({
top: 0,
behavior: window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth",
});
});
});
const closeNavigation = () => {
if (!navToggle || !siteNav) return;
navToggle.setAttribute("aria-expanded", "false");
navToggle.setAttribute("aria-label", "Open navigation");
siteNav.classList.remove("is-open");
};
if (navToggle && siteNav) {
navToggle.addEventListener("click", () => {
const isOpen = navToggle.getAttribute("aria-expanded") === "true";
navToggle.setAttribute("aria-expanded", String(!isOpen));
navToggle.setAttribute("aria-label", isOpen ? "Open navigation" : "Close navigation");
siteNav.classList.toggle("is-open", !isOpen);
});
navLinks.forEach((link) => link.addEventListener("click", closeNavigation));
document.addEventListener("click", (event) => {
if (siteNav.classList.contains("is-open") && !siteNav.contains(event.target) && !navToggle.contains(event.target)) {
closeNavigation();
}
});
}
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") closeNavigation();
});
const updateHeader = () => {
if (siteHeader) siteHeader.classList.toggle("is-scrolled", window.scrollY > 24);
};
updateHeader();
window.addEventListener("scroll", updateHeader, { passive: true });
reveals.forEach((item) => {
if (item.dataset.delay) item.style.setProperty("--delay", `${item.dataset.delay}ms`);
});
if ("IntersectionObserver" in window) {
const revealObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("is-visible");
revealObserver.unobserve(entry.target);
}
});
},
{ threshold: 0.12, rootMargin: "0px 0px -4% 0px" },
);
reveals.forEach((item) => revealObserver.observe(item));
} else {
reveals.forEach((item) => item.classList.add("is-visible"));
}
const closeVideoDialog = () => {
if (!videoDialog || !dialogVideo) return;
dialogVideo.pause();
dialogVideo.removeAttribute("src");
dialogVideo.load();
if (videoDialog.open) videoDialog.close();
document.body.classList.remove("has-dialog");
if (heroVideo) heroVideo.play().catch(() => {});
};
playButtons.forEach((button) => {
button.addEventListener("click", () => {
if (!videoDialog || !dialogVideo || !dialogTitle) return;
dialogTitle.textContent = button.dataset.title || "Gameplay";
dialogVideo.src = button.dataset.video;
document.body.classList.add("has-dialog");
if (heroVideo) heroVideo.pause();
videoDialog.showModal();
dialogVideo.play().catch(() => {});
});
});
if (dialogClose) dialogClose.addEventListener("click", closeVideoDialog);
if (videoDialog) {
videoDialog.addEventListener("click", (event) => {
const bounds = videoDialog.getBoundingClientRect();
const clickedOutside = event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom;
if (clickedOutside) closeVideoDialog();
});
videoDialog.addEventListener("cancel", (event) => {
event.preventDefault();
closeVideoDialog();
});
}
let toastTimer;
const showToast = () => {
if (!toast) return;
toast.classList.add("is-visible");
window.clearTimeout(toastTimer);
toastTimer = window.setTimeout(() => toast.classList.remove("is-visible"), 2200);
};
const copyText = async (value) => {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(value);
return;
}
const temporaryInput = document.createElement("textarea");
temporaryInput.value = value;
temporaryInput.setAttribute("readonly", "");
temporaryInput.style.position = "fixed";
temporaryInput.style.opacity = "0";
document.body.appendChild(temporaryInput);
temporaryInput.select();
document.execCommand("copy");
temporaryInput.remove();
};
copyButtons.forEach((button) => {
button.addEventListener("click", async () => {
try {
await copyText(button.dataset.copy);
const status = button.querySelector("i");
if (status) {
status.textContent = "Copied";
window.setTimeout(() => {
status.textContent = "Copy";
}, 2200);
}
showToast();
} catch {
window.prompt("Copy Discord username:", button.dataset.copy);
}
});
});
if (currentYear) currentYear.textContent = String(new Date().getFullYear());