-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
346 lines (306 loc) · 14.4 KB
/
script.js
File metadata and controls
346 lines (306 loc) · 14.4 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
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
var advancedMode = false;
var toolTipTimer = null;
var tooltipDiv = null;
var GameVersion = 0; // 0 = USA, 1 = Japan, 2 = PAL
var allGameModeSelectors = [];
// ---------------------------- Load Information from Local Storage --------------------------
function loadInfo() {
// set initial values if first load onto site
if (localStorage.getItem("GameMode") == null) { localStorage.setItem("GameMode", 0); }
if (localStorage.getItem("AdvancedMode") == null) { localStorage.setItem("AdvancedMode", 'false'); }
// Game Version
GameVersion = Math.max(0, Math.min(localStorage.getItem("GameMode"), 2));
if (isNaN(GameVersion) || (typeof GameVersion) != "number") {
localStorage.setItem("GameMode", 0);
GameVersion = 0;
}
// Advanced Mode
advancedMode = localStorage.getItem("AdvancedMode").toLowerCase() === 'true';
localStorage.setItem("AdvancedMode", advancedMode);
}
loadInfo();
// ---------------------------- General Changing Game Versions --------------------------
function changeGameVersion(object) {
GameVersion = object.value;
localStorage.setItem("GameMode", object.value);
// update all game mode selectors to the new value
for (let i = 0; i < allGameModeSelectors.length; i++) {
allGameModeSelectors[i].value = GameVersion;
}
}
// ---------------------------- Advanced Mode --------------------------
function toggleAdvanced() {
const button = document.getElementById("AdvancedModeButton");
let text = button.childNodes[1];
if (advancedMode === true) {
button.style.backgroundColor = "var(--red-button)";
text.textContent = "(currently off)";
} else {
button.style.backgroundColor = "var(--green-button)";
text.textContent = "(currently on)";
}
advancedMode = !advancedMode
localStorage.setItem("AdvancedMode", advancedMode);
document.getElementById("AdvancedModeCheckMark").checked = advancedMode;
}
// ---------------------------- That one tooltip logic --------------------------
function hoverToolTipStart(object) {
if (tooltipDiv != null) { tooltipDiv.remove(); }
tooltipDiv = document.createElement('div');
tooltipDiv.classList.add('tooltip');
tooltipDiv.style.left = (object.getBoundingClientRect().left - 25) + 'px';
tooltipDiv.style.top = object.offsetHeight + object.offsetTop + 'px';
document.body.appendChild(tooltipDiv);
//need fade class after element is added to page. Best method I could get (.then didn't work)
toolTipTimer = setTimeout(function () {
tooltipDiv.classList.add('fade');
}, 300);
}
function hoverToolTipEnd() {
clearTimeout(toolTipTimer);
if (tooltipDiv != null) {
tooltipDiv.classList.remove('fade');
tooltipDiv.remove();
}
}
// ----------------------------- Making Content between pages consistent -------------------------
function makeNavBar(pathToRoot) {
// Redirect all network calls (for security to block requests outside the github site)
makeServiceWorkers(pathToRoot);
// JSON with Navbar contents. Makes it easier to update
const AllElements = [
{
"text": "Home",
"link": pathToRoot + "/"
},
{
"text": "Filenames",
"link": pathToRoot + "/Filenames/"
},
{
"text": "ID Documentation \u25BC",
"link": null,
"dropdownElements": [
{
"text": "Projectile IDs",
"link": pathToRoot + "/ProjectileID/Legacy/"
}
]
},
{
"text": "Game File Parsers \u25BC",
"link": null,
"dropdownElements": [
{
"text": "VsMode Spawns (_vs_Axx.bin)",
"link": pathToRoot + "/VSModeSpawns/"
},
{
"text": "Collision Files (hit_pack_xx.pac)",
"link": pathToRoot + "/CollisionFiles/"
}
]
},
{
"text": "External Resources \u25BC",
"link": null,
"dropdownElements": [
{
"text": "All Assault Voice lines",
"link": "https://starfox.org/games/star-fox-assault/audio/voice-acting/"
},
{
"text": "Speedrun page",
"link": "https://www.speedrun.com/sfassault"
},
{
"text": "High Score Runs",
"link": "https://cyberscore.me.uk/games/282"
},
{
"text": "Gecko/AR Codes for Assault",
"link": "https://gamehacking.org/game/54239"
},
{
"text": "The Cutting Room Floor",
"link": "https://tcrf.net/Star_Fox:_Assault"
},
{
"text": "Models Resource",
"link": "https://models.spriters-resource.com/gamecube/starfoxassault/"
},
{
"text": "Sounds Resource",
"link": "https://sounds.spriters-resource.com/gamecube/starfoxassault/"
}
]
}
]
// <div id="NavBar">
const navBar = document.createElement("div");
navBar.id = "NavBar";
for (let i = 0; i < AllElements.length; i++) {
if (AllElements[i]["link"] != null) { // for non-dropdown links
// <a href="./">Text</a>
let curLink = document.createElement("a");
curLink.href = AllElements[i]["link"];
curLink.text = AllElements[i]["text"];
navBar.appendChild(curLink);
} else {
/*<div class="NavBar_dropdown">
<p> Section Header </p>
<div>
<a href="#">Link to Page</a>
...
</div>
</div>*/
let curDiv = document.createElement("div");
curDiv.classList.add("NavBar_dropdown");
let curHeader = document.createElement("p");
curHeader.textContent = AllElements[i]["text"];
curDiv.appendChild(curHeader);
let divContainer = document.createElement("div");
for (j = 0; j < AllElements[i]["dropdownElements"].length; j++) {
let curLink = document.createElement("a");
curLink.href = AllElements[i]["dropdownElements"][j]["link"];
curLink.text = AllElements[i]["dropdownElements"][j]["text"];
divContainer.appendChild(curLink);
}
curDiv.appendChild(divContainer);
navBar.appendChild(curDiv);
}
}
// add navbar to page
let scriptTag = document.currentScript;
scriptTag.parentNode.replaceChild(navBar, scriptTag);
}
function makeGameModeSelector(funcToCall) {
// <select name="GameVersion" id="GameVersionSelector" onChange="changeGameVersion(this); funcToCall();">
const topLevel = document.createElement("select");
topLevel.name = "GameVersion";
topLevel.className = "GameVersionSelector";
if (funcToCall != null) {
topLevel.onchange = function () { changeGameVersion(this); funcToCall(); };
} else {
topLevel.onchange = function () { changeGameVersion(this); };
}
// -<option value=all_values[i]> all_text[i] </option>
let all_values = [0, 1, 2];
let all_text = ["NTSC-U (USA)", "NTSC-J (Japan)", "PAL (Europe)"];
for (let i = 0; i < all_values.length; i++) {
let curOption = document.createElement("option");
curOption.value = all_values[i];
curOption.textContent = all_text[i];
topLevel.appendChild(curOption);
}
topLevel.value = GameVersion; // set the default value to the current game version
allGameModeSelectors.push(topLevel); // add to list of all game mode selectors for updating all later
// add game mode selector to page
let scriptTag = document.currentScript;
scriptTag.parentNode.replaceChild(topLevel, scriptTag);
}
function makeHeader(title, funcToCall = null, makeGameModeSelector = true, makeAdvancedModeButton = true) {
// <div class = "flexContainer">
const topLevel = document.createElement("div");
topLevel.classList.add("flexContainer");
// -<h1 id = "Title"> title </h1>
const header = document.createElement("h1");
header.id = "Title";
header.textContent = title;
topLevel.appendChild(header);
// -<div id="TopRightOfScreen">
const topRightDiv = document.createElement("div");
topRightDiv.id = "TopRightOfScreen";
topLevel.appendChild(topRightDiv);
if (makeGameModeSelector) {
// --<script>makeGameModeSelector(funcToCall);</script>
const gameModeSelector = document.createElement("script");
gameModeSelector.textContent = "makeGameModeSelector("+funcToCall+");";
topRightDiv.appendChild(gameModeSelector);
}
if (makeAdvancedModeButton) {
// --<button id = "AdvancedModeButton" onmouseover = "hoverToolTipStart(this);" onmouseleave = "hoverToolTipEnd();" onclick = "toggleAdvanced();" style = "background-color: var(--red-button);"></button>
const advancedModeButton = document.createElement("button");
advancedModeButton.id = "AdvancedModeButton";
advancedModeButton.onmouseover = function () { hoverToolTipStart(this); };
advancedModeButton.onmouseleave = function () { hoverToolTipEnd(); };
advancedModeButton.onclick = function () { toggleAdvanced(); };
if (advancedMode === true) {
advancedModeButton.style.backgroundColor = "var(--green-button)";
document.getElementById("AdvancedModeCheckMark").checked = advancedMode;
} else {
advancedModeButton.style.backgroundColor = "var(--red-button)";
}
topRightDiv.appendChild(advancedModeButton);
// ---<span>Advanced Mode</span>
const advancedModeText_1 = document.createElement("span");
advancedModeText_1.textContent = "Advanced Mode";
advancedModeButton.appendChild(advancedModeText_1);
// ---<span>(currently on/off)</span>
const advancedModeText_2 = document.createElement("span");
advancedModeText_2.textContent = "(currently " + (advancedMode ? "on" : "off") + ")";
advancedModeButton.appendChild(advancedModeText_2);
}
// add header to page
let scriptTag = document.currentScript;
scriptTag.parentNode.replaceChild(topLevel, scriptTag);
}
// --------------- Security related things ------------------
// all network calls go through a service worker to block those from outside the github site
async function makeServiceWorkers(pathToRoot) {
if ('serviceWorker' in navigator) {
const reg = await navigator.serviceWorker.register(pathToRoot + '/sw.js');
// If there's a new SW waiting, activate it immediately
if (reg.waiting) {
reg.waiting.postMessage({ type: 'SKIP_WAITING' });
}
// Wait until SW is active and controlling the page
await navigator.serviceWorker.ready;
// If page isn't already controlled, reload so SW takes over
if (!navigator.serviceWorker.controller) {
window.location.reload();
}
navigator.serviceWorker.register = function() { return Promise.reject(new Error('serviceWorker disabled')); };
}
}
// Block anything and everything network related that I don't use (thanks Claude)
function removeNetworkFeatures() {
navigator.sendBeacon = () => false;
window.WebSocket = function() { throw new Error('WebSocket disabled'); };
window.EventSource = function() { throw new Error('EventSource disabled'); };
window.RTCPeerConnection = function() { throw new Error('WebRTC disabled'); };
window.SharedWorker = function() { throw new Error('SharedWorker disabled'); };
window.RTCPeerConnection = function() { throw new Error('RTCPeerConnection disabled'); };
window.RTCDataChannel = function() { throw new Error('RTCDataChannel disabled'); };
window.Worker = function() { throw new Error('Worker disabled'); };
window.SharedWorker = function() { throw new Error('SharedWorker disabled'); };
window.BroadcastChannel = function() { throw new Error('BroadcastChannel disabled'); };
window.XMLHttpRequest.prototype.open = function(method, url, ...rest) { throw new Error('XMLHttpRequest disabled'); };
// fetch blocks all requests outside of the current url origin
const originalFetch = window.fetch;
window.fetch = function(url, options) {
if (url[0] == '/' || /^(blob:|data:|\/\/|https?:\/\/)/i.test(url.toString())) {
return Promise.reject(new Error(`Promise blocked: ${url}`));
}
return originalFetch(url, options);
};
}
// claude written filename sanitizer
const sanitizeFilename = (name) => name
.replaceAll(/[<>:"/\\|?*\x00-\x1F]/g, '') // Remove illegal chars
.replaceAll(/[\s.]+$/g, '') // Strip trailing spaces/dots
.trim() // Strip leading/trailing whitespace
|| 'download'; // Fallback if name is empty
// got ASCII art from Claude. Made this cause I am not looking at security of my tools that much
function printWarningToConsole() {
const warning = `
██╗ ██╗ █████╗ ██████╗ ███╗ ██╗██╗███╗ ██╗ ██████╗ ██╗
██║ ██║██╔══██╗██╔══██╗████╗ ██║██║████╗ ██║██╔════╝ ██║
██║ █╗ ██║███████║██████╔╝██╔██╗ ██║██║██╔██╗ ██║██║ ███╗██║
██║███╗██║██╔══██║██╔══██╗██║╚██╗██║██║██║╚██╗██║██║ ██║╚═╝
╚███╔███╔╝██║ ██║██║ ██║██║ ╚████║██║██║ ╚████║╚██████╔╝██╗
╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝`
console.log(warning, "\nBE AWARE OF WHAT YOU COPY AND PASTE IF YOU GOT IT FROM SOMEONE ELSE. SECURITY PROBLEMS CAN OCCUR!!!")
}
printWarningToConsole();
removeNetworkFeatures();