jacobinathanialpeterson commited on
Commit
8f93c53
·
1 Parent(s): c6dd1ec

Create script.js

Browse files
Files changed (1) hide show
  1. script.js +112 -0
script.js ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ input.onchange = async () => {
2
+ const url = new Blob([input.files[0]]);
3
+ const parts = input.files[0].name.split('.');
4
+
5
+ const core = await (async ext => {
6
+ const core = await (async (ext) => {
7
+ if (["fds", "nes", "unif", "unf"].includes(ext))
8
+ return "nes"
9
+
10
+ if (["smc", "fig", "sfc", "gd3", "gd7", "dx2", "bsx", "swc"].includes(ext))
11
+ return "snes"
12
+
13
+ if (["z64", "n64"].includes(ext))
14
+ return "n64"
15
+
16
+ if (["pce"].includes(ext))
17
+ return "pce"
18
+
19
+ if (["ngp", "ngc"].includes(ext))
20
+ return "ngp"
21
+
22
+ if (["ws", "wsc"].includes(ext))
23
+ return "ws"
24
+
25
+ if (["col", "cv"].includes(ext))
26
+ return "coleco"
27
+
28
+ if (["d64"].includes(ext))
29
+ return "vice_x64"
30
+
31
+ if (["nds", "gba", "gb", "z64", "n64"].includes(ext))
32
+ return ext
33
+ })
34
+ return await new Promise(resolve => {
35
+ const cores = {
36
+ '3DO': '3do',
37
+ 'Arcade': 'arcade',
38
+ 'Atari 2600': 'atari2600',
39
+ 'Atari 5200': 'atari5200',
40
+ 'Atari 7800': 'atari7800',
41
+ 'Atari Jaguar': 'jaguar',
42
+ 'Atari Lynx': 'lynx',
43
+ 'Bandai WonderSwan (Color)': 'ws',
44
+ 'ColecoVision': 'coleco',
45
+ "Commodore 64": "vice_x64",
46
+ 'MAME': 'mame2003',
47
+ 'NEC PC-FX': 'pcfx',
48
+ 'NEC TurboGrafx-16/SuperGrafx/PC Engine': 'pce',
49
+ 'Nintendo Entertainment System': 'nes',
50
+ 'Nintendo 64': 'n64',
51
+ 'Nintendo DS': 'nds',
52
+ 'Nintendo Game Boy Advance': 'gba',
53
+ 'Nintendo Game Boy': 'gb',
54
+ 'PlayStation': 'psx',
55
+ 'Super Nintendo Entertainment System': 'snes',
56
+ 'SNK NeoGeo Pocket (Color)': 'ngp',
57
+ 'Sega 32X': 'sega32x',
58
+ 'Sega CD': 'segaCD',
59
+ 'Sega Game Gear': 'segaGG',
60
+ 'Sega Master System': 'segaMS',
61
+ 'Sega Mega Drive': 'segaMD',
62
+ 'Sega Saturn': 'segaSaturn',
63
+ 'Virtual Boy': 'vb',
64
+ };
65
+
66
+ const button = document.createElement('button');
67
+ const select = document.createElement('select');
68
+
69
+ for (const type in cores) {
70
+ const option = document.createElement('option');
71
+
72
+ option.value = cores[type];
73
+ option.textContent = type;
74
+ select.appendChild(option);
75
+ }
76
+
77
+ button.onclick = () => resolve(select[select.selectedIndex].value);
78
+ button.textContent = 'Load Game';
79
+ box.innerHTML = '';
80
+
81
+ box.appendChild(select);
82
+ box.appendChild(button);
83
+ });
84
+ })(parts.pop());
85
+
86
+ const div = document.createElement('div');
87
+ const sub = document.createElement('div');
88
+ const script = document.createElement('script');
89
+
90
+ sub.id = 'game';
91
+ div.id = 'display';
92
+
93
+ box.remove();
94
+ div.appendChild(sub);
95
+ document.body.appendChild(div);
96
+
97
+ window.EJS_player = '#game';
98
+ window.EJS_gameName = parts.shift();
99
+ window.EJS_biosUrl = '';
100
+ window.EJS_gameUrl = url;
101
+ window.EJS_core = core;
102
+ window.EJS_pathtodata = 'https://cdn.jsdelivr.net/gh/EmulatorJS/EmulatorJS@latest/data/';
103
+ window.EJS_startOnLoaded = true;
104
+
105
+
106
+
107
+ script.src = 'https://cdn.jsdelivr.net/gh/EmulatorJS/EmulatorJS@latest/data/loader.js';
108
+ document.body.appendChild(script);
109
+ };
110
+
111
+ box.ondragover = () => box.setAttribute('drag', true);
112
+ box.ondragleave = () => box.removeAttribute('drag');