-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
89 lines (77 loc) · 3.04 KB
/
script.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
const root = document.querySelector(":root");
setInterval(updateRandomCSSVariables, 10);
function updateRandomCSSVariables() {
// console.log(Math.random());
root.style.setProperty("--random-time", `${Math.random()}s`);
root.style.setProperty("--random-rotation", `${Math.random()}deg`);
root.style.setProperty("--random-length", `${Math.random()}em`);
root.style.setProperty("--random-number", Math.random());
}
document.querySelectorAll(".switch").forEach(e => {
e.addEventListener("click", () => {
if (e.classList.contains("on")) {
e.classList.add("off");
e.classList.remove("on");
} else {
e.classList.add("on");
e.classList.remove("off");
}
const switchType = e.parentElement.classList[0];
document.body.classList.contains(switchType)
? document.body.classList.remove(switchType)
: document.body.classList.add(switchType);
if (switchType === "nerd") nerdToggle(document.body.classList.contains("nerd"));
});
});
// nerd mode
function nerdToggle(nerdMode) {
const directionBinarywards = nerdMode ? "to" : "from";
// iterate through all elements (small amount so who cares how, right?)
// for every element that has text directly inside, tun that text through textToBinary()
document.querySelectorAll("*").forEach(e => {
if (
e.childNodes[0]?.nodeType === Node.TEXT_NODE &&
!binaryConvert(e.childNodes[0]?.nodeValue, "to").match(/1010 (100000)+/)
) {
const textNode = e.childNodes[0];
textNode.nodeValue = binaryConvert(textNode.nodeValue, directionBinarywards);
}
});
}
function binaryConvert(text, directionBinarywards) {
if (directionBinarywards === "to") {
return text
.split("")
.map(c => c.charCodeAt(0).toString(2))
.join(" ");
} else if (directionBinarywards === "from") {
return text
.split(" ")
.map(bin => String.fromCharCode(parseInt(bin, 2)))
.join("");
} else throw new Error("🐗🏿🤯🏼");
}
const phoneLink = document.querySelector(".contact-phone > a");
phoneLink.innerText = atob("KzEgKDQwMikgOTE1LTM3ODc=");
phoneLink.setAttribute("href", atob("dGVsOjQwMjkxNTM3ODc="));
document.querySelectorAll("*").forEach(e => {
e.addEventListener("mouseover", () => {
e.style.setProperty("--static-random-number", Math.random());
});
});
// if js enabled, dynamic scroll thingy
let scrollButton = document.createElement("button");
scrollButton.setAttribute("type", "button");
scrollButton.addEventListener("click", () => {
window.scrollBy({
top: window.innerHeight,
left: 0,
behavior: "smooth",
});
console.debug(window.innerHeight);
});
let buttonImage = document.createElement("img");
buttonImage.setAttribute("src", "./icons/down.svg");
buttonImage.setAttribute("alt", "down arrow icon");
scrollButton.appendChild(buttonImage);
document.querySelector(".scroll-down").appendChild(scrollButton);