all repos — nds-converter @ main

A lightweight save converter for NDS and DeSmuME.

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