-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
70 lines (59 loc) · 2.07 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>💾</text></svg>">
<title>NDS Converter</title>
<style>
body, a {
background-color: #212529;
color: #dee2e6;
font-family: sans-serif;
}
hr {
width: 400px;
text-align: left;
margin-left: 0px;
margin-top: 20px;
}
</style>
</head>
<body>
<h2>NDS Converter</h2>
<p>Please, select one or more <code>.sav</code> or <code>.dsv</code> files.</p>
<input type="file" accept=".dsv,.sav" multiple onchange="convertFiles(this)">
<hr>
<p><a href="https://github.com/BiRabittoh/nds-converter">Source code</a></p>
<script>
async function convertFiles(element) {
element.disabled = true;
for (f of element.files) {
await convert(f);
}
element.disabled = false;
}
async function convert(file) {
const formData = new FormData();
formData.append('file', file);
const response = await fetch('/', {
method: 'POST',
body: formData,
});
if (!response.ok) {
alert(`Error ${response.status}: ${await response.text()}`);
return;
}
const newExtension = file.name.endsWith('.dsv') ? '.sav' : '.dsv';
const blob = await response.blob();
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = file.name.replace(/\.[^.]+$/, '') + newExtension;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
</script>
</body>
</html>