-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
611 lines (540 loc) · 21.9 KB
/
index.html
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flash Loader</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#37528c" />
<link rel="manifest" href="/manifest.json">
<meta name="description" content="A collection of Flash games you can play directly in your browser using the Ruffle Flash emulator"/>
<meta name="application-name" content="FlashLoader"/>
<meta name="creator" content="pooiod7"/>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background-color: #37528c;
color: #fff;
height: 100vh;
display: flex;
flex-direction: column;
overflow-x: hidden;
overflow-y: auto;
}
* {
scrollbar-color: #c7d3f0 #37528c;
}
*::-webkit-scrollbar-track {
background: #37528c;
}
*::-webkit-scrollbar-thumb {
background-color: #c7d3f0;
}
#loading,
#error {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #37528c;
color: #f4f4f4;
justify-content: center;
align-items: center;
z-index: 9999;
}
#loading {
opcaity: 0;
/* animation: pulse-opacity 2s infinite; */
}
#error {
background-color: #16223a;
color: #fff;
}
#error pre {
margin: 0;
color: #fff;
}
#gameListContainer {
padding: 20px;
width: 100%;
overflow-y: auto;
background-color: #37528c;
box-sizing: border-box;
display: flex;
flex-direction: column;
}
#searchBar {
padding: 10px;
margin-bottom: 10px;
border: 1px solid #4161a7;
background-color: #223254;
color: #fff;
border-radius: 5px;
width: 100%;
box-sizing: border-box;
}
#searchBar::placeholder {
color: #eaeaea;
opacity: 1;
}
.game-item {
padding: 10px 20px;
background-color: #4161a7;
border: 1px solid #2e4678;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.2s;
margin-bottom: 10px;
color: #fff;
}
.download-button {
position: relative;
background: #37528c;
border-radius: 4px;
float: right;
padding-left: 5px;
padding-right: 5px;
border: 1px solid #2e4678;
color: #fff;
}
.lowsupport {
opacity: 0.5;
}
.lowperformance {
opacity: 0.8;
}
.game-item:hover {
background-color: #334c82;
}
#gameContainer {
flex-grow: 1;
display: flex;
align-items: center;
justify-content: center;
background-color: #37528c;
width: 100%;
}
object {
width: 100%;
height: 100%;
}
@keyframes pulse-opacity {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 1;
}
}
</style>
</head>
<body>
<div id="loading">Loading...</div>
<div id="error">
<pre id="errorMessage"></pre>
<input type="file" id="fileInput" style="display: none;" accept=".swf">
</div>
<div id="gameListContainer">
<input type="text" id="searchBar" placeholder="Search games...">
<div id="gameList"></div>
</div>
<div id="gameContainer" style="display:none;"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script>
const loadingScreen = document.getElementById('loading');
const errorScreen = document.getElementById('error');
const errorMessage = document.getElementById('errorMessage');
const gameList = document.getElementById('gameList');
const gameContainer = document.getElementById('gameContainer');
const fileInput = document.getElementById('fileInput');
const searchBar = document.getElementById('searchBar');
var gamesJson = "/games.json";
var serverdown = true;
var games = [];
async function getGameByName(name) {
if (games == [] || !games || games.length < 1) {
games = [];
var tries = 0;
while (games.length < 1 && tries <= 20) {
var games = await (await fetch(gamesJson)).json();
tries += 1;
}
}
name = decodeURI(name);
const game = games.find(game => game.name === name);
return game || null;
}
var warnings = {
unsuported: ["This game is not yet fully supported by ruffle, try <a href='https://flash.pm'><p style='display:inline;color:white;'>flash.pm</p></a> for a better gaming experience.", "5000"],
badlinks: ["Some external links may cause game crashing and data loss.", 3000],
studders: ["You may experience ocasional studders while playing this game.", "5000"],
jumpscare: ["Warning: scary!", 3000]
}
var installedActuallFlash = false;
function isFlashSupported() {
var hasFlash = false;
if (navigator.plugins && navigator.plugins.length > 0) {
var flashPlugin = navigator.plugins['Shockwave Flash'];
if (flashPlugin) {
hasFlash = true;
}
}
return hasFlash && !window.RufflePlayer;
} installedActuallFlash = isFlashSupported();
if (!installedActuallFlash) {
if (!document.cookie.split('; ').find(row => row.startsWith('rufflesave=')) && !serverdown) {
const button = document.createElement('button');
button.textContent = 'Log in to save online';
button.style.position = 'fixed';
button.style.bottom = '10px';
button.style.left = '10px';
button.style.padding = '10px 15px';
button.style.backgroundColor = '#007bff';
button.style.color = '#fff';
button.style.border = 'none';
button.style.borderRadius = '5px';
button.style.cursor = 'pointer';
button.style.zIndex = '1';
button.id = "loginbutton";
button.addEventListener('click', () => {
window.location.href = 'login';
});
document.body.appendChild(button);
}
}
function displaymessage(msg, time) {
const message = document.createElement("div");
message.innerHTML = msg;
message.style.position = "fixed";
message.style.top = "0";
message.style.right = "0";
message.style.zIndex = "9999";
message.style.backgroundColor = "#333";
message.style.color = "#fff";
message.style.padding = "10px";
message.style.opacity = "0";
message.style.transition = "opacity 0.5s";
message.id = "message";
message.pointerEvents = "none";
document.body.appendChild(message);
setTimeout(() => {
message.style.opacity = "1";
}, 100);
setTimeout(() => {
message.style.opacity = "0";
}, time);
setTimeout(() => {
message.style.display = "none";
document.body.removeChild(message);
}, time+600);
}
function showLoading(show) {
loadingScreen.style.display = show ? 'flex' : 'none';
}
function showError(message) {
errorMessage.textContent = message;
errorScreen.style.display = 'flex';
}
var stopreload = false;
window.addEventListener('hashchange', function() {
if (!stopreload) {
showLoading(true);
window.location.reload();
}
});
function loadLocalSWF(file) {
const gameUrl = URL.createObjectURL(file);
gameContainer.innerHTML = `<object data="${gameUrl}" type="application/x-shockwave-flash"></object>`;
gameContainer.style.display = "block";
document.title = file.name;
loadruffle();
setTimeout(function () {
fixruffle();
}, 2000);
errorScreen.style.display = 'none';
}
fileInput.addEventListener('change', function () {
if (fileInput.files.length > 0) {
const file = fileInput.files[0];
if (file.type === 'application/x-shockwave-flash' || true) {
loadLocalSWF(file)
} else {
showError('Selected file is not a valid SWF.');
}
}
});
function fixruffle() {
try {
var shadowHost = document.querySelector('#gameContainer > ruffle-object:nth-child(1)');
var shadowRoot = shadowHost.shadowRoot;
var container = shadowRoot.querySelector('#container');
const style = document.createElement('style');
style.textContent = `
#save-manager, #volume-controls-modal {
width: 100vw;
height: 100vh;
}
#modal-area {
/*margin-top: calc(50% - 350px);*/
margin-top: 15vh;
width: 70vw;
height: 60vh;
max-height: 70vh;
min-width: 250px;
min-height: 100px;
max-width: 90vh
}
#volume-controls-modal > div:nth-child(1) {
margin-top: 40vh;
}
`;
shadowRoot.appendChild(style);
if (/Mobi|Android/i.test(navigator.userAgent)) {
if (shadowHost.requestFullscreen) {
shadowHost.requestFullscreen();
} else if (shadowHost.mozRequestFullScreen) { // Firefox
shadowHost.mozRequestFullScreen();
} else if (shadowHost.webkitRequestFullscreen) { // Chrome, Safari, and Opera
shadowHost.webkitRequestFullscreen();
} else if (shadowHost.msRequestFullscreen) { // IE/Edge
shadowHost.msRequestFullscreen();
}
}
if (container) {
container.style.width = '100vw';
container.style.height = '100vh';
}
} catch(err) {
console.warn("Ignored error:", err)
}
}
var ruffleused = false;
function loadruffle(item) {
document.getElementById('gameListContainer').style.display = 'none';
document.getElementById("loginbutton")?.remove();
setTimeout(function () {
fixruffle();
}, 1000);
setTimeout(function () {
fixruffle();
}, 500);
setTimeout(function () {
fixruffle();
if (!document.cookie.includes('rufflesave')) {
document.addEventListener('contextmenu', function(e) {
function addButton(text, onClick) {
const contextMenu = shadowRoot.querySelector('#context-menu');
if (contextMenu) {
const menuItem = document.createElement('li');
menuItem.className = 'menu-item';
menuItem.textContent = text;
menuItem.addEventListener('click', async function(e) {
e.preventDefault();
await onClick(e);
});
contextMenu.appendChild(menuItem);
}
}
function addSeparator() {
const contextMenu = shadowRoot.querySelector('#context-menu');
if (contextMenu) {
const separator = document.createElement('li');
separator.className = 'menu-separator';
separator.innerHTML = '<hr>';
contextMenu.appendChild(separator);
}
}
const contextMenu = shadowRoot.querySelector('#context-menu');
if (contextMenu && contextMenu.lastElementChild) {
contextMenu.removeChild(contextMenu.lastElementChild);
}
addButton('Back to games', async function() {
shadowRoot.querySelector('#context-menu-overlay').classList.add("hidden");
window.location.href = "/";
});
});
}
}, 3000);
(function() {
if (document.cookie.includes('rufflesave')) {
var autosavescript = document.createElement('script');
autosavescript.src = 'cloudsave.js';
if (!serverdown) document.head.appendChild(autosavescript);
}
})();
const ruffleScript = document.createElement('script');
ruffleScript.src = 'https://unpkg.com/@ruffle-rs/ruffle';
// ruffleScript.onload = () => {};
if (!installedActuallFlash) {
document.head.appendChild(ruffleScript);
ruffleused = true;
installedActuallFlash = isFlashSupported();
if (item) {
if (item.warning) {
displaymessage(warnings[item.warning][0], warnings[item.warning][1]);
}
}
}
}
var downloading = false;
async function loadGames() {
showLoading(true);
try {
const response = await fetch(gamesJson);
games = await response.json();
const customSwfItem = document.createElement('div');
customSwfItem.classList.add('game-item');
customSwfItem.textContent = 'Load your own game (.swf)';
customSwfItem.onclick = () => fileInput.click();
gameList.appendChild(customSwfItem);
games.forEach(item => {
var gameName = item.name;
var gameItem = document.createElement('div');
gameItem.classList.add('game-item');
gameItem.textContent = gameName;
var downloadButton = document.createElement('button');
downloadButton.textContent = 'Download';
downloadButton.classList.add('download-button');
downloadButton.onclick = (event) => {
event.preventDefault();
downloading = true;
window.location.href = "download.html?game=" + gameName;
setTimeout(function(){
downloading = false;
}, 500);
};
setTimeout(function(){
if (!isFlashSupported()) {
if (item.warning && item.warning == "unsuported") {
gameItem.classList.add('lowsupport');
} else if (item.warning && item.warning == "studders") {
gameItem.classList.add('lowperformance');
gameItem.appendChild(downloadButton);
} else {
gameItem.appendChild(downloadButton);
}
}
}, 100);
gameItem.onclick = (event) => {
if (event.ctrlKey) {
event.preventDefault();
window.location.href = "download.html?game=" + gameName;
} else {
if (!downloading) {
loadGame(gameName);
}
}
};
if (!item.hidden) {
gameList.appendChild(gameItem);
}
});
if (gameList.children.length === 0) {
showError('No games found.');
} else {
const tmpsearch = new URLSearchParams(window.location.search).get('q');
if (tmpsearch) {
searchBar.value = tmpsearch;
filterGames();
searchBar.style.display = "none";
}
}
} catch (error) {
showError(`Error loading games: ${error.message}`);
} finally {
showLoading(false);
}
}
function filterGames() {
const filterText = searchBar.value.toLowerCase();
const gameItems = document.querySelectorAll('.game-item');
gameItems.forEach(item => {
if (item.textContent.toLowerCase().includes(filterText)) {
item.style.display = '';
} else {
item.style.display = 'none';
}
});
}
async function loadGame(gameName) {
try {
showLoading(true);
document.title = decodeURIComponent(gameName) + ".swf";
var item = await getGameByName(gameName);
stopreload = true;
window.location.hash = gameName;
setTimeout(function () {
stopreload = false;
}, 500);
if (!item && gameName != "login") {
throw new Error("Failed to find swf");
}
var gameUrl = "";
if (gameName != "login") {
gameUrl = item.url;
}
gameContainer.innerHTML = `<object data="${gameUrl}" type="application/x-shockwave-flash"></object>`;
gameContainer.style.display = "block";
loadruffle(item);
window.location.hash = `#${gameName}`;
} catch (error) {
showError(`Error loading game: ${error.message}`);
} finally {
showLoading(false);
}
}
async function handleHash() {
const hash = window.location.hash.substring(1);
if (hash) {
games = await (await fetch(gamesJson)).json();
loadGame(hash);
} else {
loadGames();
}
}
searchBar.addEventListener('input', filterGames);
window.onload = function() {
handleHash();
};
</script>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('worker.js')
.then(reg => console.log('Service Worker Registered', reg))
.catch(err => console.log('Service Worker Failed to Register', err));
navigator.serviceWorker.addEventListener('message', (event) => {
if (event.data.type === 'FILE_RECEIVED') {
const fileInput = document.getElementById('fileInput');
const file = new File([new Blob()], event.data.fileName);
const dataTransfer = new DataTransfer();
dataTransfer.items.add(file);
fileInput.files = dataTransfer.files;
// Trigger the change event
fileInput.dispatchEvent(new Event('change'));
}
});
if ('launchQueue' in window) {
launchQueue.setConsumer((launchParams) => {
if (launchParams.files.length) {
launchParams.files[0].getFile().then(file => loadLocalSWF(file));
}
});
} else {
var navuser = navigator.userAgent;
if (navigator.brave && navigator.brave.isBrave()) { // why is this disabled by default?
alert("Please enable brave://flags/#file-system-access-api to allow for .swf files to be opened with FlashLoader");
} else {
console.error("File system access api is not available");
}
}
}
</script>
</body>
</html>