Skip to content

Commit 0ad6cf3

Browse files
committed
refactor
1 parent 0e9cf81 commit 0ad6cf3

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

undata.htm

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,29 @@
1515
file = "";
1616
}
1717
const mimeType = index < 0 ? "" : file.substring("data:".length, index);
18+
19+
function write(selector, text) {
20+
const e = document.querySelector(selector);
21+
if (typeof text === "object") {
22+
for (const [k, v] of Object.entries(text)) {
23+
e[k] = v;
24+
}
25+
} else {
26+
e.innerText = text;
27+
}
28+
}
1829
</script>
1930
</head>
2031
<body>
2132
<h1>Undata</h1>
2233
<p>Mime type: <span id="mimeType"></span></p>
23-
<script>(function (){
24-
const a = document.querySelector("#mimeType") ?? undefined;
25-
if (a !== undefined) {
26-
a.innerText = mimeType;
27-
}
28-
})();</script>
29-
<p>File length: <script>
30-
(function (){ const length = Math.max(0, file.length); document.write(length); })();
31-
</script> characters.</p>
34+
<p>File length: <span id="fileLength"></span> characters.</p>
3235
<p><a id="download" download="undata">DOWNLOAD</a></p>
33-
<script>(function (){
34-
const a = document.querySelector("#download") ?? undefined;
35-
if (a !== undefined) {
36-
a.href = file;
37-
}
38-
if (file === "") {
39-
a.innerText = "INVALID FILE";
40-
}
41-
})();</script>
4236
<h2>WARNING: The file you are about to download could come from anyone and could contain any data. Download at your own risk.</h2>
37+
<script>
38+
write("#mimeType", mimeType);
39+
write("#fileLength", file.length);
40+
write("#download", { href: file, innerText: file === "" ? "INVALID FILE" : "DOWNLOAD" });
41+
</script>
4342
</body>
4443
</html>

0 commit comments

Comments
 (0)