-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
189 lines (163 loc) · 5.64 KB
/
script.js
File metadata and controls
189 lines (163 loc) · 5.64 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
document.addEventListener("DOMContentLoaded", () => {
document.addEventListener("contextmenu", (e) => e.preventDefault(), {
capture: true,
});
document.addEventListener(
"keydown",
(e) => {
if (
e.key === "F12" ||
(e.ctrlKey &&
e.shiftKey &&
(e.key === "I" || e.key === "J" || e.key === "C" || e.key === "K")) ||
(e.ctrlKey &&
(e.key === "u" || e.key === "U" || e.key === "s" || e.key === "S"))
) {
e.preventDefault();
return false;
}
},
{ capture: true },
);
const header = document.querySelector(".header");
if (header) {
const handleScroll = () => {
header.classList.toggle("scrolled", window.scrollY > 50);
};
window.addEventListener("scroll", handleScroll, { passive: true });
handleScroll();
}
const toolsDropdown = document.getElementById("tools-dropdown");
if (toolsDropdown) {
const toggle = toolsDropdown.querySelector(".dropdown-toggle");
const closeDropdown = () => {
toolsDropdown.classList.remove("active");
if (toggle) toggle.setAttribute("aria-expanded", "false");
};
if (toggle) {
toggle.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
const isActive = toolsDropdown.classList.toggle("active");
toggle.setAttribute("aria-expanded", isActive.toString());
});
}
document.addEventListener("click", (e) => {
if (!toolsDropdown.contains(e.target)) {
closeDropdown();
}
});
toolsDropdown.addEventListener("mouseleave", () => {
closeDropdown();
});
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") closeDropdown();
});
}
const observerOptions = {
root: null,
rootMargin: "-50px 0px -50px 0px",
threshold: 0.15,
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("is-visible");
if (entry.target.classList.contains("stat-item")) {
const counter = entry.target.querySelector(".counter");
if (counter && !counter.classList.contains("counted")) {
animateCounter(counter);
counter.classList.add("counted");
}
}
}
});
}, observerOptions);
document.querySelectorAll(".animate-on-scroll").forEach((el) => {
observer.observe(el);
});
const revealIfNearViewport = () => {
document.querySelectorAll(".animate-on-scroll").forEach((el) => {
if (el.classList.contains("is-visible")) return;
const rect = el.getBoundingClientRect();
if (rect.top < window.innerHeight * 1.25 && rect.bottom > -50) {
el.classList.add("is-visible");
}
});
};
revealIfNearViewport();
window.addEventListener("scroll", revealIfNearViewport, { passive: true });
window.addEventListener("resize", revealIfNearViewport, { passive: true });
function animateCounter(el) {
const target = parseInt(el.getAttribute("data-target"), 10) || 0;
if (target === 0) return;
const duration = target <= 10 ? 650 : 1800;
const start = 0;
const startTime = performance.now();
const update = (currentTime) => {
const elapsed = currentTime - startTime;
const progress = Math.min(elapsed / duration, 1);
const eased = 1 - Math.pow(1 - progress, 3);
const currentValue = Math.round(start + (target - start) * eased);
el.textContent = currentValue.toLocaleString("en-US");
if (progress < 1) {
requestAnimationFrame(update);
} else {
el.textContent = target.toLocaleString("en-US");
}
};
requestAnimationFrame(update);
}
const yearEl = document.getElementById("current-year");
if (yearEl) {
yearEl.textContent = new Date().getFullYear();
}
const isSkinGrabberPage =
document.body?.classList?.contains("page-skingrabber") ?? false;
const isProtectedPage =
document.body?.classList?.contains("page-protected") ?? false;
if (isSkinGrabberPage || isProtectedPage) {
const stop = (e) => {
e.preventDefault();
e.stopPropagation();
return false;
};
document.addEventListener("copy", stop, { capture: true });
document.addEventListener("cut", stop, { capture: true });
document.addEventListener("paste", stop, { capture: true });
document.addEventListener("dragstart", stop, { capture: true });
document.addEventListener("selectstart", stop, { capture: true });
}
// Clean up URLs - remove .html extension
if (window.history.replaceState && window.location.pathname.endsWith('.html')) {
const cleanPath = window.location.pathname.replace(/\.html$/, '');
window.history.replaceState({}, '', cleanPath + window.location.search + window.location.hash);
}
const discordInviteCode = "BewvqAe3jb";
const memberCountEl = document.querySelector(".discord-member-count");
if (memberCountEl) {
fetch(
`https://discord.com/api/v10/invites/${discordInviteCode}?with_counts=true`,
)
.then((response) => {
if (!response.ok) throw new Error("Discord API error");
return response.json();
})
.then((data) => {
if (data?.approximate_member_count) {
const count = data.approximate_member_count;
memberCountEl.setAttribute("data-target", count);
if (
memberCountEl
.closest(".stat-item")
?.classList.contains("is-visible")
) {
animateCounter(memberCountEl);
}
}
})
.catch(() => {
memberCountEl.setAttribute("data-target", "1240");
});
}
});