| 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'); | |