-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
131 lines (100 loc) · 3.74 KB
/
Copy pathmain.js
File metadata and controls
131 lines (100 loc) · 3.74 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
// Предупреждения консоли даже невозможно отловить. Пусть это и костыль, но им пользуется половина интернета
console.warn = () => {};
// Всплывающее сообщение
Alert.setDelayMultiplayer(1).create(
`<b>${i18n("main-alert-name")}</b><br><small>${i18n("main-alert-description")}</small><br>${i18n("main-alert-detail", `window.scrollTo({top: window.innerHeight, behavior: "smooth"});`)}`,
"success",
i18n("main-alert-title-hello"),
);
// Скролл вверх страницы при запуске
window.scrollTo({ top: 0, behavior: "smooth" });
// Новая, быстрая и плавная прокрутка
document.addEventListener(
"wheel",
(wheelEvent) => {
if (userParams.disableCustomScroll) return;
if (wheelEvent.deltaY === 0) return;
if (wheelEvent.shiftKey) return;
let isDirectionTop = wheelEvent.deltaY < 0;
let targetWithScroll = wheelEvent.path.find((node) => {
if (node.clientHeight === node.scrollHeight) return;
let isCanScroll = isDirectionTop
? node.scrollTop !== 0
: node.scrollTop !== node.scrollHeight - node.clientHeight;
if (!isCanScroll) return;
let overflowType = window.getComputedStyle(node)["overflow-y"];
return !["", "hidden", "visible"].includes(overflowType);
});
if (targetWithScroll !== document.documentElement) return;
if (targetWithScroll.scrollTop > window.innerHeight) return;
if (targetWithScroll.scrollTop === window.innerHeight && !isDirectionTop)
return;
wheelEvent.preventDefault();
window.scrollTo({
top: isDirectionTop ? 0 : window.innerHeight,
behavior: "smooth",
});
},
{ passive: false },
);
// Срабатывает кнопкой Пуск или нажатием пробела
async function launch() {
if (userParams.clearedConsole) console.clear();
window.events.emit("launchCode");
localDB.setItem("statistic.launch", (current) => current + 1);
try {
await eval(`(async () => {${codearea.textContent}})()`);
} catch (err) {
Alert.setDelayMultiplayer(1.5);
Alert.create(err.message, "error", i18n("main-alert-title-error"));
console.error(err);
window.events.emit("error", err);
localDB.setItem("statistic.launchEndWithError", (current) => current + 1);
}
window.events.emit("launchCodeEnd");
}
if (
!window.location.href.includes("ignore") &&
userParams.launchOnStart &&
crashDefender.check()
)
launch();
if (userParams.codeareaHeight)
document
.querySelector("body > main")
.style.setProperty("--codeSpace-code-height", userParams.codeareaHeight);
if (userParams.background)
document.body.style.background = userParams.background;
if (userParams.menuButtonsColor)
document.documentElement.style.setProperty(
"--mainThemeColor",
`hsl(${userParams.menuButtonsColor}, 35%, 55%)`,
);
if (userParams.codeSize)
document.documentElement.style.setProperty(
"--codeFontSize",
`${userParams.codeSize}em`,
);
if (localDB.getItem("statistic?.win") > 0) {
document.querySelector("#game").classList.add("post-initial");
}
(async () => {
if (!userParams.letItSnow) return;
let element = document.createElement("script");
element.src = `./classes/LetItSnow.js`;
element.id = "LetItSnow";
document.body.append(element);
await new Promise((res) => (element.onload = res));
new SnowBackground();
})();
window.events.emit("main");
I18nManager.replaceAll();
(function registerPWAWorker() {
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("pwa.worker.js", { scope: "." })
.catch((error) => {
console.error("Service Worker registration failed:", error);
});
}
})();