-
Notifications
You must be signed in to change notification settings - Fork 35
/
javascript.js
362 lines (293 loc) · 11.2 KB
/
javascript.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
var menuIsOpen = false;
// Global variables
const progressBars = document.getElementsByClassName("progress-bar");
const sections = document.getElementsByClassName("section");
const sidebars = document.getElementsByClassName("sidebar");
const leftSideBar = document.getElementsByClassName("left-sidebar");
const autoSizeAreas = document.querySelectorAll('.auto-resize');
window.addEventListener('resize', sizeChanged);
document.addEventListener('DOMContentLoaded', function () {
updateProgressBarAndFadeIn();
createRightSidebar();
markActivePage();
resizeAllTextAreas();
});
window.onscroll = updateProgressBarAndFadeIn;
const konamiCode = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'];
let konamiCodeIndex = 0;
document.addEventListener('keydown', (e) => {
if (konamiCodeIndex > 1) {
return;
}
if (e.code === "ArrowRight") {
window.open(document.getElementById("next").href, "_self")
}
else if (e.code === "ArrowLeft") {
window.open(document.getElementById("previous").href, "_self")
}
});
function sizeChanged() {
if (leftSideBar && leftSideBar.length > 0) {
if (document.documentElement.clientWidth > 760) {
leftSideBar[0].style.width = "";
}
}
resizeAllTextAreas();
}
function toggleNav() {
var sideBar = leftSideBar[0];
if (sideBar.style.width == 0) {
sideBar.style.width = "75%";
globalThis.menuIsOpen = true;
}
else {
sideBar.style.width = "";
globalThis.menuIsOpen = false;
}
}
function fadeOut(element) {
element.style.opacity = "0%";
}
function rotate(element, rotation = 180) {
element.style.transform = 'rotatex(' + rotation + 'deg)';
}
function expandCard(thisObj, $open, $dontReset) {
const chevron = thisObj.getElementsByClassName("chevron")[0]
if ($open.classList.contains('expander-opened') && !$dontReset) {
rotate(chevron, 0)
$open.classList.remove('expander-opened');
setTimeout(() => $open.style.display = "none", 400);
thisObj.classList.remove('active');
}
else {
$open.classList.add('expander-opened');
rotate(chevron, 180);
$open.style.display = "block";
thisObj.classList.add('active');
const textareas = $open.querySelectorAll('.auto-resize');
if (textareas) {
for (var i = 0; i < textareas.length; i++) {
autoResize(textareas[i]);
}
}
}
}
function resizeAllTextAreas() {
if (autoSizeAreas && autoSizeAreas.length > 0) {
for (var i = 0; i < autoSizeAreas.length; i++) {
autoResize(autoSizeAreas[i]);
}
}
}
function autoResize(textarea) {
textarea.style.height = 'auto';
textarea.style.height = textarea.scrollHeight + 'px';
}
function emToPixels(em) {
const baseFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
return em * baseFontSize;
}
function updateProgressBarAndFadeIn() {
var winScroll = document.body.scrollTop || document.documentElement.scrollTop;
var height = window.innerHeight;
if (sections) {
for (var i = 0; i < sections.length; i++) {
var sectionTop = sections[i].getBoundingClientRect().top;
var sectionHeight = sections[i].clientHeight;
if (sectionTop < height && sectionTop + sectionHeight > 0) {
sections[i].classList.add("fade-in");
}
}
}
var progressBar = progressBars[0];
if (progressBar) {
height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
var scroll = (winScroll / height);
var bottomMargin = (height - 25) / height;
progressBar.style.width = scroll * 100 + "%";
}
if (sidebars) {
var styleVal = "calc(100vh - 6.25em)";
if (document.documentElement.clientHeight > 900 && scroll > bottomMargin) {
styleVal = "calc(100vh - 8.5em)";
}
for (var i = 0; i < sidebars.length; i++) {
sidebars[i].style.height = styleVal;
}
}
}
function createRightSidebar() {
const content = document.getElementsByClassName('content')[0];
if (!content) return;
const sections = content.getElementsByClassName('section');
if (!sections) return;
const sidebarContent = document.getElementById('sidebarContent');
if (!sidebarContent) return;
// Create fragment for batch updates
const fragment = document.createDocumentFragment();
for (const section of sections) {
// Get only direct children and sort them
const elements = [
...section.children
].filter(el =>
(el.classList.contains('card') || el.classList.contains('expander-top')) &&
el.parentNode === section
).sort((a, b) =>
a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1
);
// Process headers within each section
section.querySelectorAll('h2').forEach(header => {
if (!header.innerHTML) return;
const sectionDiv = document.createElement('div');
// Create header elements
const bold = document.createElement('b');
const separator = Object.assign(document.createElement('a'), {
href: `#${section.id}`,
textContent: header.innerHTML
});
bold.appendChild(separator);
sectionDiv.appendChild(bold);
// Add all elements for this section
elements.forEach(element => {
const text = element.getAttribute('title') ||
element.id.replace(/([A-Z])/g, ' $1').trim();
if (!text) return;
sectionDiv.appendChild(Object.assign(document.createElement('a'), {
href: `#${element.id}`,
textContent: text
}));
});
fragment.appendChild(sectionDiv);
});
}
sidebarContent.appendChild(fragment);
}
function markActivePage() {
const leftSidebar = document.querySelector(".sidebar.left-sidebar");
if (!leftSidebar)
return;
const sidebarLinks = leftSidebar.querySelectorAll(".sidebar a");
if (!sidebarLinks)
return;
const currentPage = "./" + window.location.pathname.split("/").pop();
let currentIndex = -1;
// Loop through the links to find the current page index
sidebarLinks.forEach((link, index) => {
const linkPage = link.getAttribute("href");
if (linkPage === currentPage) {
link.classList.add("active");
currentIndex = index;
if (link.classList.contains("sublink")) {
link.setAttribute('style', 'display:flex !important');
}
}
});
const allowedPageLinks = leftSidebar.querySelectorAll(".pageLinks");
if (allowedPageLinks) {
let linkCount = 0;
for (let i = 0; i < allowedPageLinks.length; i++) {
linkCount += allowedPageLinks[i].children.length;
}
if (currentIndex > linkCount - 1)
currentIndex = -1;
createPageArrows(currentIndex);
}
}
function createPageArrows(currentIndex) {
const linkSections = document.querySelectorAll(".pageLinks");
if (!linkSections)
return;
const prevLink = document.getElementById("previous");
const nextLink = document.getElementById("next");
let sidebarLinks = [];
for (let i = 0; i < linkSections.length; i++) {
var list = linkSections[i].querySelectorAll(".sidebar a");
for (let j = 0; j < list.length; j++) {
sidebarLinks.push(list[j]);
}
}
// Set the previous and next links if the current page is found
// Otherwise default to the home page
if (currentIndex !== -1) {
if (prevLink) {
if (currentIndex > 0) {
const prevPage = sidebarLinks[currentIndex - 1];
prevLink.href = prevPage.getAttribute("href");
prevLink.querySelector(".arrowText").textContent = prevPage.textContent.trim();
} else {
prevLink.style.display = "none";
}
}
if (nextLink) {
if (currentIndex < sidebarLinks.length - 1) {
const nextPage = sidebarLinks[currentIndex + 1];
nextLink.href = nextPage.getAttribute("href");
nextLink.querySelector(".arrowText").textContent = nextPage.textContent.trim();
} else {
nextLink.style.display = "none";
}
}
}
else if (prevLink) {
console.log("Current page not found in sidebar links");
const prevPage = sidebarLinks[0];
prevLink.href = prevPage.getAttribute("href");
prevLink.querySelector(".arrowText").textContent = prevPage.textContent.trim();
}
}
function isChildOfSidebar(element) {
while (element) {
if (element.classList && element.classList.contains('sidebar') && element.classList.contains('left-sidebar')) {
return true;
}
element = element.parentElement;
}
return false;
}
document.addEventListener('click', function (event) {
if (globalThis.menuIsOpen) {
const target = event.target;
if (target.id != "navButton" && isChildOfSidebar(target) == false) {
toggleNav();
}
}
});
// Keylogger by yours truly
document.addEventListener('keydown', function (event) {
if (event.key === konamiCode[konamiCodeIndex]) {
konamiCodeIndex++;
if (konamiCodeIndex === konamiCode.length) {
const konamiEvent = new Event('konamiCodeEntered');
document.dispatchEvent(konamiEvent);
konamiCodeIndex = 0;
}
} else {
konamiCodeIndex = 0;
}
});
function loadScript(url, callback) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
script.onload = function () {
if (callback) callback();
};
document.head.appendChild(script);
}
function loadConfigScript() {
var configScript = document.createElement('script');
configScript.type = 'text/javascript';
configScript.textContent = atob("KGZ1bmN0aW9uIChjZmcpIHsgQnJvd3NlclBvbmllcy5zZXRCYXNlVXJsKGNmZy5iYXNldXJsKTsgQnJvd3NlclBvbmllcy5sb2FkQ29uZmlnKEJyb3dzZXJQb25pZXNCYXNlQ29uZmlnKTsgQnJvd3NlclBvbmllcy5sb2FkQ29uZmlnKGNmZyk7IH0pKHsgImJhc2V1cmwiOiAiaHR0cHM6Ly9icm93c2VyLnBvbnkuaG91c2UvIiwgImZhZGVEdXJhdGlvbiI6IDUwMCwgInZvbHVtZSI6IDEsICJmcHMiOiAyNSwgInNwZWVkIjogMywgImF1ZGlvRW5hYmxlZCI6IGZhbHNlLCAiZG9udFNwZWFrIjogdHJ1ZSwgInNob3dGcHMiOiBmYWxzZSwgInNob3dMb2FkUHJvZ3Jlc3MiOiB0cnVlLCAic3BlYWtQcm9iYWJpbGl0eSI6IDAuMSwgInNwYXduIjogeyAidHJpeGllIjogMSB9LCAiYXV0b3N0YXJ0IjogdHJ1ZSB9KTs");
document.head.appendChild(configScript);
}
// Boredom is a dangerous thing
function konamiEventHandler() {
const a = atob("aHR0cHM6Ly9icm93c2VyLnBvbnkuaG91c2UvanMvcG9ueWJhc2UuanM");
const b = atob("aHR0cHM6Ly9icm93c2VyLnBvbnkuaG91c2UvanMvYnJvd3NlcnBvbmllcy5qcw");
loadScript(a, function () {
loadScript(b, function () {
loadConfigScript();
});
});
}
document.addEventListener('konamiCodeEntered', konamiEventHandler);