all repos — nds-converter @ 2e720846fea25e571a0381533f1b2a72205bfee5

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            for (f of element.files) {
34                await convert(f);
35            }
36        }
37
38        async function convert(file) {
39            const formData = new FormData();
40            formData.append('file', file);
41
42            const response = await fetch('/', {
43                method: 'POST',
44                body: formData,
45            });
46
47            if (!response.ok) {
48                alert(`Error ${response.status}: ${await response.text()}`);
49                return;
50            }
51
52            const newExtension = file.name.endsWith('.dsv') ? '.sav' : '.dsv';
53
54            const blob = await response.blob();
55
56            const link = document.createElement('a');
57            link.href = window.URL.createObjectURL(blob);
58            link.download = file.name.replace(/\.[^.]+$/, '') + newExtension;
59
60            document.body.appendChild(link);
61            link.click();
62            document.body.removeChild(link);
63        }
64    </script>
65</body>
66
67</html>