-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
160 lines (135 loc) · 4.73 KB
/
main.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
import "./style.css";
let start; // Date.now()
let end; // Date.now() + duration
let progress = 0; // Percentage displayed on BSoD
let interval; // The updateProgress() interval
let intervalsToWait = 0; // Intervals to pause updating progress.
let intervalsToZoom = 0; // Intervals to not pause updating progress.
let fullscreened = false;
function updateProgress() {
interval = setInterval(() => {
const current = Date.now();
if (current >= end) {
progress = 100;
document.querySelector("#progress-percentage").textContent = "100";
console.log("BSOD done!");
clearInterval(interval);
setTimeout(() => {
document.querySelector("main").style.setProperty("display", "none");
document.body.style.removeProperty("background-color");
if (fullscreened) {
const exitFullscreen = document.exitFullscreen || document.webkitExitFullscreen;
exitFullscreen.call(document);
}
}, 1000);
}
if (intervalsToZoom >= 1) {
intervalsToZoom--;
} else if (intervalsToWait >= 1) {
intervalsToWait--;
return;
}
const percent = (current - start) / (end - start);
const percentSquared = percent ** 2;
progress = Math.min(100, Math.max(
100 * ((percentSquared / ((2 * (percentSquared - percent)) + 1)) + ((Math.random() * 0.1) - 0.08)),
progress, // Make sure progress doesn't go down
));
if (Math.random() * percent > 0.6) {
intervalsToZoom = Math.round(Math.random() * 10) + 1;
console.log("zooming " + intervalsToZoom);
} else {
intervalsToWait = Math.round((Math.random() * (Math.min(((end - current) / 100) - 10, 75) + 10)));
console.log("waiting " + intervalsToWait);
}
document.querySelector("#progress-percentage").textContent = progress.toFixed(0);
console.log(intervalsToWait, intervalsToZoom, percent);
}, 100);
}
// Changing background and theme color (affects iOS)
document.getElementsByName("bg-color").forEach(element => {
element.addEventListener("change", () => {
document.querySelector("meta[name='theme-color'")
.setAttribute("content", element.value);
document.querySelector("main")
.style.setProperty("background-color", element.value);
});
});
// Starting the BSOD
document.querySelector("#create").addEventListener("click", () => {
start = Date.now();
const duration = document.querySelector("input[name='length']")
.valueAsNumber * 1000 || 30e3;
end = start + duration;
console.group("BSOD at " + start);
console.log("Blue screening for " + duration + "ms");
// Setting background and theme color again, just in case
document.getElementsByName("bg-color").forEach(element => {
if (element.checked) {
document.querySelector("meta[name='theme-color'")
.setAttribute("content", element.value);
document.querySelector("main")
.style.setProperty("background-color", element.value);
document.body.style.setProperty("background-color", element.value);
}
});
// Setting text
console.group("Setting text…");
document.querySelectorAll("fieldset > label > input[type='text']").forEach(input => {
const bsodElement = document.querySelector("#" + input.getAttribute("name"));
const inputValue = input.value || input.getAttribute("placeholder");
console.log(bsodElement, inputValue);
bsodElement.textContent = inputValue;
});
// Resetting variables/text
document.querySelector("#progress-percentage").textContent = 0;
progress = 0;
intervalsToWait = Math.min(10, Math.floor(duration / 200));
intervalsToZoom = 0;
console.groupEnd(1);
const bsodElement = document.querySelector("main");
try {
// For Safari. Fullscreen is supported on iPadOS / iOS >= 12, but not iPhone
const fullscreen = bsodElement.requestFullscreen || bsodElement.webkitRequestFullscreen;
fullscreen.call(bsodElement, {navigationUI: "hide"});
fullscreened = true;
} catch (error) {
fullscreened = false;
console.error(error);
}
bsodElement.style.setProperty("display", "flex");
updateProgress();
});
// Cancelling BSOD
function cancelBSOD() {
clearInterval(interval);
document.querySelector("main").style.setProperty("display", "none");
document.body.style.removeProperty("background-color");
console.log("BSOD cancelled.");
console.groupEnd(1);
}
document.addEventListener("keydown", event => {
if (event.key === "Escape") {
cancelBSOD();
}
});
document.addEventListener("fullscreenchange", () => {
if (!document.fullscreenElement) {
cancelBSOD();
fullscreened = false;
}
});
document.addEventListener("webkitfullscreenchange", () => {
if (!document.webkitFullscreenElement) {
cancelBSOD();
fullscreened = false;
}
});
/* IOS Warning */
if (
/iPad/.test(navigator.platform)
|| (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1)
) {
const iosWarning = document.querySelector("#ios-warning");
iosWarning.style.setProperty("display", "block");
}