all repos — nds-converter @ c49ad1e5149c8ebc9941e186f50cbcef737a4732

A lightweight save converter for NDS and DeSmuME.

templates/index.html (view raw)

 1<!DOCTYPE html>
 2<html lang="en">
 3
 4<head>
 5    <meta charset="UTF-8">
 6    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 7    <meta http-equiv="X-UA-Compatible" content="ie=edge">
 8    <title>NDS Converter</title>
 9    <style>
10        body, a {
11            background-color: #212529;
12            color: #dee2e6;
13            font-family: sans-serif;
14        }
15        hr {
16            width: 400px;
17            text-align: left;
18            margin-left: 0px;
19            margin-top: 20px;
20        }
21    </style>
22</head>
23
24<body>
25    <h2>NDS Converter</h2>
26    <p>Please, select one or more <code>.sav</code> or <code>.dsv</code> files.</p>
27    <input type="file" accept=".dsv,.sav" multiple onchange="convertFiles(this)">
28    <hr>
29    <p><a href="https://github.com/BiRabittoh/nds-converter">Source code</a></p>
30
31    <script>
32        async function convertFiles(element) {
33            element.disabled = true;
34            for (f of element.files) {
35                await convert(f);
36            }
37            element.disabled = false;
38        }
39
40        async function convert(file) {
41            const formData = new FormData();
42            formData.append('file', file);
43
44            const response = await fetch('/', {
45                method: 'POST',
46                body: formData,
47            });
48
49            if (!response.ok) {
50                alert(`Error ${response.status}: ${await response.text()}`);
51                return;
52            }
53
54            const newExtension = file.name.endsWith('.dsv') ? '.sav' : '.dsv';
55
56            const blob = await response.blob();
57
58            const link = document.createElement('a');
59            link.href = window.URL.createObjectURL(blob);
60            link.download = file.name.replace(/\.[^.]+$/, '') + newExtension;
61
62            document.body.appendChild(link);
63            link.click();
64            document.body.removeChild(link);
65        }
66    </script>
67</body>
68
69</html>