-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
214 lines (193 loc) · 7.46 KB
/
index.html
File metadata and controls
214 lines (193 loc) · 7.46 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>CheerpJ test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="dark light">
<script src="https://cjrtnc.leaningtech.com/3_20241017_546/cj3loader.js"></script>
<!--<style>
.as-console-wrapper {
z-index: 500000 !important;
}
</style>-->
<style>
html, body {
margin: 0;
}
#container {
width: 100vw;
height: 100svh;
}
img.cheerpj-logo-direct-embed {
position: absolute;
top: 0;
right: 0;
height: 100px;
z-index: 99999999;
box-sizing: border-box;
margin: 0;
border-style: dashed;
border-width: 5px;
border-color: blue;
}
</style>
</head>
<body>
<img
src="https://cjrtnc.leaningtech.com/3_20241017_546/cheerpj.svg"
alt="Spinning circle image"
class="cheerpj-logo-direct-embed"/>
<div id="container">
<label for="version-select">FFDEC Version:</label>
<select name="versions" id="version-select">
<option value="default" selected>Default</option>
</select>
<br><br>
<label>
SWF File Upload:
<input type="file" accept=".swf" oninput="window.handleFiles(this)">
</label>
<br>
OR:
<button
onclick="{
const res = window.confirm('Are you sure? This file has a valid U.S. copyright.\n\n' +
'By continuing you acknowledge that the example file is protected under U.S. ' +
'copyright law and accept all responsibility for your use the file. ' +
'(i.e. your use of the file must be in accordance with U.S. copyright law)');
if(res) window.handleFiles(null, false);
}">
Use example SWF
</button>
<br>
OR:
<button onclick="window.runApp()">
Continue without a file (not recommended)
</button>
</div>
<script src="./sw-loader.js"></script>
<script type="module">
window.onerror = (msg, src, line, col, err) => {
console.warn(
`message: ${msg}`,
`source: ${src}`,
`lineno: ${line}`,
`colno: ${col}`,
`error: ${err}`,
);
};
const supportsClipboardAPI =
window.isSecureContext
&& await navigator
.permissions
.query({ name: "clipboard-read" })
.then(({ state }) =>
// Browser supports and can access or ask for access
state == "granted"
|| state == "prompt"
? true
: false)
.catch(() => false); // No browser support
const urlParams = new URLSearchParams(window.location.search);
async function initConsole() {
if(window.location.hash !== "#console") {
window.addEventListener("hashchange", initConsole, { once: true });
return;
}
await import("https://cdn.jsdelivr.net/npm/eruda@3/eruda.js");
await eruda.init();
}
await initConsole();
console.groupCollapsed("Initializing...");
await cheerpjInit({
javaProperties: [
"java.net.preferIPv4Stack=true",
],
/*preloadResources: {},*/
preloadProgress: (preloadDone, preloadTotal) => {
console.info(`Loaded ${((preloadDone / preloadTotal) * 100).toFixed(5)}% (${preloadDone}/${preloadTotal})`);
},
clipboardMode: supportsClipboardAPI === true ? "permission" : "system",
...(!urlParams.get("base")
? {}
: { overrideDocumentBase: urlParams.get("base") }
),
beepCallback: () => alert("Beep!"),
enableInputMethods: true,
/*natives: {},*/
});
console.groupEnd();
window.handleFiles = async (element, uploaded = true) => {
const file = uploaded
? element.files[0]
: await fetch("/tankz2.swf")
.then(res => res.blob())
.then(blob => new Blob(
[blob],
{ type: "application/x-shockwave-flash" },
));
const buff = await file.arrayBuffer();
const name = uploaded ? file.name : "tankz2.swf";
cheerpOSAddStringFile(`/str/${name}`, new Uint8Array(buff));
runApp(name);
};
async function runApp(fileName = null) {
const versionSelect = document.querySelector("select");
let basePath = "";
if(versionSelect.value !== "default") {
basePath = await fetch("/loadFs", {
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify(versionInfoMap.get(versionSelect.value))
})
.then((res) => res.text())
.catch(() => "");
}
const container = document.querySelector("#container");
container.replaceChildren(); // Delete contents
cheerpjCreateDisplay(-1, -1, container);
console.log("Created display...");
let config = Object.assign(Object.create(null), {
lastSaveDir: "/files",
lastOpenDir: "/str",
_showDebugMenu: true,
airLibLocation: "/app/flashlib/airglobal.swc",
playerLibLocation: "/app/flashlib/playerglobal32_0.swc",
"check.updates.enabled": false,
pluginPath: "/app/plugins/",
useDetailedLogging: true,
saveSessionOnExit: true,
"gui.window.maximized.horizontal": true,
"gui.window.maximized.vertical": true,
"gui.window.height": document.body.clientHeight,
"gui.window.width": document.body.clientWidth,
});
// Format config object as command line options string
config = Object.entries(config).reduce(
(accumulator, entry) =>
`${accumulator === null
? ""
: `${accumulator},`
}${entry[0]}=${entry[1]}`,
null,
);
console.group("Running...");
console.info("[Loader] App path:", `/app/${basePath}ffdec.jar`);
const exitCode = await cheerpjRunJar(
`/app/${basePath}ffdec.jar`,
"-config",
config,
...(fileName ? [`/str/${fileName}`] : []), // Support running without file
);
console.log(`Exited with code: ${exitCode}`);
console.groupEnd();
alert(`App exited with code ${exitCode}. You will need to reload the page to open it again.`)
}
window.runApp = runApp;
</script>
</body>
</html>