forked from CubeyTheCube/wordle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addons.js
99 lines (88 loc) · 3.44 KB
/
addons.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
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
const appObserver = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.addedNodes && mutation.addedNodes[0].tagName === "GAME-APP") {
appObserver.disconnect();
loadPlayAgainButton();
return;
}
}
});
appObserver.observe(document.body, {
childList: true,
subtree: true,
});
function loadPlayAgainButton() {
const modal = document
.querySelector("game-app")
.shadowRoot.querySelector("game-modal");
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (
mutation.attributeName === "open" &&
mutation.target.getAttribute("open") === ""
) {
const countdown = mutation.target
.querySelector("game-stats")
.shadowRoot.querySelector(".countdown");
while (countdown.firstChild)
countdown.removeChild(countdown.firstChild);
const button = document.createElement("button");
button.textContent = "PLAY AGAIN";
Object.assign(button.style, {
"background-color": "rgb(106, 170, 100)",
color: "white",
"font-family": "inherit",
"font-weight": "bold",
"border-radius": "4px",
cursor: "pointer",
border: "none",
"user-select": "none",
display: "flex",
"justify-content": "center",
"align-items": "center",
"text-transform": "uppercase",
"-webkit-tap-highlight-color": "rgba(0,0,0,0.3)",
width: "80%",
"font-size": "20px",
height: "52px",
"margin-left": "20px",
});
countdown.appendChild(button);
button.addEventListener("click", () => {
observer.disconnect();
document.body.removeChild(document.querySelector("game-app"));
document.body.appendChild(new window.wordle.bundle.GameApp());
const themeManager = document
.querySelector("game-app")
.shadowRoot.querySelector("game-theme-manager");
if (localStorage.getItem("darkTheme") === "true")
themeManager.setDarkTheme(true);
if (localStorage.getItem("colorBlindTheme") === "true")
themeManager.setColorBlindTheme(true);
const newModal = document
.querySelector("game-app")
.shadowRoot.querySelector("game-modal");
observer.observe(newModal, { attributes: true });
});
/*
// This may cause problems with reloading the page, but yeah it's here
document.addEventListener("keyup", function(event) {
if (event.code === 'Enter') {
observer.disconnect();
document.body.removeChild(document.querySelector('game-app'));
document.body.appendChild(new window.wordle.bundle.GameApp());
const themeManager = document.querySelector('game-app').shadowRoot.querySelector('game-theme-manager');
if (localStorage.getItem('darkTheme') === 'true')
themeManager.setDarkTheme(true);
if (localStorage.getItem('colorBlindTheme') === 'true')
themeManager.setColorBlindTheme(true);
const newModal = document.querySelector('game-app').shadowRoot.querySelector('game-modal');
observer.observe(newModal, { attributes: true });
}
});
*/
}
}
});
observer.observe(modal, { attributes: true });
}