Add files via upload

This commit is contained in:
GreyHope 2022-04-30 09:49:23 +01:00 committed by GitHub
parent e42d2ca9a1
commit 96d811ef54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,81 +1,118 @@
<!DOCTYPE html>
<html> <html>
<head> <head>
<title>Emulatorjs | Select Game Rom</title> <title>EmulatorJS</title>
<link rel="icon" type="image/png" href="docs/Logo.png">
</head> <link rel = icon href = docs/Logo.png>
<body> <meta name = viewport content = "width = device-width, initial-scale = 1">
<style> <style>
body{ body, html {
background: #c4bdff; height: 100%;
}
body {
font-family: monospace;
font-weight: bold;
font-size: 20px;
margin: 0; margin: 0;
padding: 0; overflow: hidden;
background-color: #222
} }
.form{
body, #box {
display: flex;
align-items: center;
justify-content: center;
}
#box {
color: #aaa;
height: 20em;
width: 30em;
max-width: 80%;
max-height: 80%;
background-color: #333;
border-radius: 0.4em;
border: 2px solid #555;
position: relative;
flex-direction: column;
transition-duration: 0.2s;
overflow: hidden
}
#box:hover, #box[drag] {
border-color: #38f;
color: #ddd
}
#input {
cursor: pointer;
position: absolute; position: absolute;
top: 450px; left: 0;
left: 50%; top: 0;
margin-top: -150px;
margin-left: -250px;
width: 500px;
height: 200px;
border: 4px dashed #111;
}
.form p{
width: 100%; width: 100%;
height: 100%; height: 100%;
text-align: center; opacity: 0
line-height: 170px;
color: #111;
font-family: Arial;
} }
.form input{
position: absolute; #display {
margin: 0;
padding: 0;
width: 100%; width: 100%;
height: 100%; height: 100%
outline: none;
opacity: 0;
} }
.eimg{
width: 250px; select, button {
padding: 0.6em 0.4em;
margin: 0.5em;
width: 15em;
max-width: 100%;
font-family: monospace;
font-weight: bold;
font-size: 16px;
background-color: #444;
color: #aaa;
border-radius: 0.4em;
border: 1px solid #555;
cursor: pointer;
transition-duration: 0.2s
} }
#uploadf, #uploadf1{
display: block; select:hover, button:hover {
background-color: #666;
color: #ddd
} }
</style> </style>
</head>
<body>
<div id = box>
<input type = file id = input>
Drag ROM file or click here
</div>
<script> <script>
window.addEventListener('load', function() { input.onchange = async () => {
document.getElementById('file').onchange = async function(e) { const url = URL.createObjectURL(new Blob([input.files[0]]))
var ce = function(e) {return document.createElement(e);}; const parts = input.files[0].name.split(".")
var br = function(e) {e.appendChild(ce('br'))};
var gameUrl = URL.createObjectURL(new Blob([e.target.files[0]])) const core = await (async (ext) => {
var extension = e.target.files[0].name.split('.').pop() if (["fds", "nes", "unif", "unf"].includes(ext))
var gameName = e.target.files[0].name.replaceAll("'", "\\'") return "nes"
var gameName = gameName.substr(0, gameName.length - extension.length - 1)
e.target.remove(); if (["smc", "fig", "sfc", "gd3", "gd7", "dx2", "bsx", "swc"].includes(ext))
document.getElementById('uploadf').style.display = "none"; document.getElementById('uploadf1').style.display = "none"; return "snes"
if (['fds', 'nes', 'unif', 'unf'].includes(extension)) {
var core = 'nes'; if (["nds", "gba", "gb", "z64", "n64"].includes(ext))
} else if (['z64'].includes(extension)) { return ext
var core = 'n64';
} else if (['smc', 'fig', 'sfc', 'gd3', 'gd7', 'dx2', 'bsx', 'swc'].includes(extension)) { return await new Promise(resolve => {
var core = 'snes'; const cores = {
} else if (['nds'].includes(extension)) {
var core = 'nds';
} else if (['gba'].includes(extension)) {
var core = 'gba';
} else if (['gb'].includes(extension)) {
var core = 'gb';
} else {
var core = await function() {
return new Promise(function(resolve, reject) {
var cores = {"NES / Nintendo Entertainment System / Famicon": "nes",
"SNES / Super Nintendo Entertainment System": "snes",
"Nintendo 64": "n64", "Nintendo 64": "n64",
"Nintendo Game Boy": "gb", "Nintendo Game Boy": "gb",
"Nintendo Game Boy Advance": "gba", "Nintendo Game Boy Advance": "gba",
"Nintendo DS": "nds", "Nintendo DS": "nds",
"Nintendo Entertainment System": "nes",
"Super Nintendo Entertainment System": "snes",
"PlayStation": "psx", "PlayStation": "psx",
"Virtual Boy": "vb", "Virtual Boy": "vb",
"Sega Mega Drive": "segaMD", "Sega Mega Drive": "segaMD",
@ -87,71 +124,53 @@
"Sega Game Gear": "segaGG", "Sega Game Gear": "segaGG",
"Sega Saturn": "segaSaturn", "Sega Saturn": "segaSaturn",
"Atari 7800": "atari7800", "Atari 7800": "atari7800",
"Atari 2600": "atari2600"}; "Atari 2600": "atari2600"
var a = ce('div');
a.style = 'padding: 50px;';
var p = ce('h2');
p.innerHTML = 'Unable to auto-detect system. Please select the desired system.';
a.appendChild(p);
br(a);
for (var k in cores) {
var input = ce('input');
input.type = 'radio';
input.id = 'game-' + cores[k];
input.name = 'game';
input.value = cores[k];
a.appendChild(input);
var label = ce('label');
label.for = 'game-' + cores[k];
label.innerHTML = k;
a.appendChild(label);
br(a);
};
br(a);
var submit = ce('input');
submit.type = 'submit';
submit.value = 'Load Game';
submit.onclick = function(e) {
var q = false;
var radios = document.getElementsByName('game');
for (var i=0; i<radios.length; i++) {
if (radios[i].checked) {
var q = radios[i].value;
break;
};
};
if (! q) {
return;
};
a.remove();
resolve(q);
};
a.appendChild(submit);
document.body.appendChild(a);
});
}();
};
var a = document.createElement('div');
a.style = "width:65%;height:100%;max-width:100%";
var b = document.createElement('div');
b.id = 'game';
a.appendChild(b);
document.getElementById("cont").appendChild(a);
var script = document.createElement('script');
script.innerHTML = "EJS_player = '#game'; EJS_gameName = '" + gameName + "'; EJS_biosUrl = ''; EJS_gameUrl = '" + gameUrl + "'; EJS_core = '" + core + "'; EJS_pathtodata = 'data/';";
document.body.appendChild(script);
var script = document.createElement('script');
script.src = 'data/loader.js';
document.body.appendChild(script);
} }
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 = "data/"
script.src = "data/loader.js"
document.body.appendChild(script)
}
box.ondragover = () => box.setAttribute("drag", true)
box.ondragleave = () => box.removeAttribute("drag")
</script> </script>
<center id="cont">
<img id="uploadf1" class="eimg" src="docs/Logo.png">
</center>
<div id="uploadf" class="form">
<input type="file" id="file">
<b><p>Select Game Rom: Drag your files here or click in this area.</p></b>
</div>
</body> </body>
</html> </html>