This repository was archived by the owner on May 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.html
More file actions
74 lines (66 loc) · 2.53 KB
/
index.html
File metadata and controls
74 lines (66 loc) · 2.53 KB
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
71
72
73
74
<!DOCTYPE html>
<html>
<head>
<title>JavaDowngrader example</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script src="https://cjrtnc.leaningtech.com/3.0/cj3loader.js"></script>
</head>
<body>
<form style="display: none" id="downgrader-form">
<label for="file">File:</label>
<input type="file" id="file" name="file" accept=".jar">
<label for="version-select">Target version:</label>
<select id="version-select">
</select>
<input type="button" value="Downgrade" onclick="downgrade()">
</form>
<p id="loading">
Loading...
</p>
<script>
(async function () {
await cheerpjInit();
const cj = await cheerpjRunLibrary("/app/JavaDowngrader-Web-1.1.2-SNAPSHOT.jar");
window.javadowngrader = await cj.net.raphimc.javadowngrader.web.JavaDowngraderWeb
console.log("Creating form")
const versions = await window.javadowngrader.supportedVersions();
const select = document.getElementById("version-select");
for (let i = 0; i < versions.length; i++) {
const version = versions[i];
const option = document.createElement("option");
option.value = version;
option.text = version;
select.appendChild(option);
}
document.getElementById("downgrader-form").style.display = "block";
document.getElementById("loading").style.display = "none";
console.log("Form created")
})()
async function downgrade() {
const file = document.getElementById("file").files[0];
const version = document.getElementById("version-select").value;
const reader = new FileReader();
reader.onload = async function (e) {
const file = e.target.result;
const base64Data = bytesToBase64(new Uint8Array(file));
const downgraded = await window.javadowngrader.convert(base64Data, 20, version);
const blob = new Blob([base64ToBytes(downgraded)], {type: "application/java-archive"});
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = file.name;
a.click();
};
reader.readAsDataURL(file);
}
function base64ToBytes(base64) {
const binString = atob(base64);
return Uint8Array.from(binString, (m) => m.codePointAt(0));
}
function bytesToBase64(bytes) {
const binString = String.fromCodePoint(...bytes);
return btoa(binString);
}
</script>
</body>
</html>