File size: 3,367 Bytes
8f93c53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
input.onchange = async () => {
  const url = new Blob([input.files[0]]);
  const parts = input.files[0].name.split('.');

  const core = await (async ext => {
    const core = await (async (ext) => {
      if (["fds", "nes", "unif", "unf"].includes(ext))
        return "nes"

      if (["smc", "fig", "sfc", "gd3", "gd7", "dx2", "bsx", "swc"].includes(ext))
        return "snes"

      if (["z64", "n64"].includes(ext))
        return "n64"

      if (["pce"].includes(ext))
        return "pce"

      if (["ngp", "ngc"].includes(ext))
        return "ngp"

      if (["ws", "wsc"].includes(ext))
        return "ws"

      if (["col", "cv"].includes(ext))
        return "coleco"

      if (["d64"].includes(ext))
        return "vice_x64"

      if (["nds", "gba", "gb", "z64", "n64"].includes(ext))
        return ext
    })
      return await new Promise(resolve => {
        const cores = {
          '3DO': '3do',
          'Arcade': 'arcade',
          'Atari 2600': 'atari2600',
          'Atari 5200': 'atari5200',
          'Atari 7800': 'atari7800',
          'Atari Jaguar': 'jaguar',
          'Atari Lynx': 'lynx',
          'Bandai WonderSwan (Color)': 'ws',
          'ColecoVision': 'coleco',
          "Commodore 64": "vice_x64",
          'MAME': 'mame2003',
          'NEC PC-FX': 'pcfx',
          'NEC TurboGrafx-16/SuperGrafx/PC Engine': 'pce',
          'Nintendo Entertainment System': 'nes',
          'Nintendo 64': 'n64',
          'Nintendo DS': 'nds',
          'Nintendo Game Boy Advance': 'gba',
          'Nintendo Game Boy': 'gb',
          'PlayStation': 'psx',
          'Super Nintendo Entertainment System': 'snes',
          'SNK NeoGeo Pocket (Color)': 'ngp',
          'Sega 32X': 'sega32x',
          'Sega CD': 'segaCD',
          'Sega Game Gear': 'segaGG',
          'Sega Master System': 'segaMS',
          'Sega Mega Drive': 'segaMD',
          'Sega Saturn': 'segaSaturn',
          'Virtual Boy': 'vb',
        };

        const button = document.createElement('button');
        const select = document.createElement('select');

        for (const type in cores) {
          const option = document.createElement('option');

          option.value = cores[type];
          option.textContent = type;
          select.appendChild(option);
        }

        button.onclick = () => resolve(select[select.selectedIndex].value);
        button.textContent = 'Load Game';
        box.innerHTML = '';

        box.appendChild(select);
        box.appendChild(button);
      });
    })(parts.pop());

    const div = document.createElement('div');
    const sub = document.createElement('div');
    const script = document.createElement('script');

    sub.id = 'game';
    div.id = 'display';

    box.remove();
    div.appendChild(sub);
    document.body.appendChild(div);

    window.EJS_player = '#game';
    window.EJS_gameName = parts.shift();
    window.EJS_biosUrl = '';
    window.EJS_gameUrl = url;
    window.EJS_core = core;
    window.EJS_pathtodata = 'https://cdn.jsdelivr.net/gh/EmulatorJS/EmulatorJS@latest/data/';
    window.EJS_startOnLoaded = true;



    script.src = 'https://cdn.jsdelivr.net/gh/EmulatorJS/EmulatorJS@latest/data/loader.js';
    document.body.appendChild(script);
  };

  box.ondragover = () => box.setAttribute('drag', true);
  box.ondragleave = () => box.removeAttribute('drag');