-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
61 lines (53 loc) · 1.53 KB
/
main.js
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
import "./normalize.css";
import "./styles.css";
import { initialise } from "@open-ic/openchat-embed";
import { Elm } from "./src/Main.elm";
window.onload = async () => {
const touch =
"ontouchstart" in window ||
navigator.maxTouchPoints > 0 ||
navigator.msMaxTouchPoints > 0;
let level = Number(localStorage.getItem("openchat_minesweeper_level") ?? 1);
let instructions =
localStorage.getItem("openchat_minesweeper_instructions") !== "false";
let fastestStr = localStorage.getItem("openchat_minesweeper_fastest");
let fastestTimes = {
easy: undefined,
normal: undefined,
hard: undefined,
hardcore: undefined,
};
if (fastestStr) {
fastestTimes = JSON.parse(fastestStr);
}
let username = "User";
if (window.self !== window.top) {
const client = await initialise();
username = client.username;
}
const flags = {
username: username,
level,
instructions,
fastestTimes,
touch,
};
console.log("Flagz: ", flags);
const app = Elm.Main.init({
node: document.getElementById("app"),
flags,
});
app.ports.updateLevel.subscribe((level) => {
localStorage.setItem("openchat_minesweeper_level", level.toString());
});
app.ports.instructions.subscribe((show) => {
localStorage.setItem("openchat_minesweeper_instructions", show.toString());
});
app.ports.updateFastest.subscribe((fastest) => {
localStorage.setItem(
"openchat_minesweeper_fastest",
JSON.stringify(fastest)
);
});
window.onresize = () => app.ports.resize.send(true);
};