-
Notifications
You must be signed in to change notification settings - Fork 71
/
stenunblockedmain.js
167 lines (146 loc) · 3.96 KB
/
stenunblockedmain.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
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
const likeElement = document.getElementById("likes");
const stenUnblockedAPILikes = "https://stenunblockedserver-c3acd8e9110f.herokuapp.com/";
const stenUnblockedAPIViews = "https://stenunblockedserver-c3acd8e9110f.herokuapp.com/views/"
function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
let expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
let name = cname + "=";
let ca = document.cookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
if (getCookie("likes")==="") {
setCookie("likes", '[]', 365);
}
function getLikes(cb) {
let url = stenUnblockedAPILikes + 'like?game=' + encodeURIComponent(game);
const xml = new XMLHttpRequest();
xml.open("GET", url, true);
xml.send(null);
xml.onload=function() {
if (xml.status === 200) {
cb( JSON.parse(xml.responseText)['likes'] );
} else {
cb( "Error: " + xml.responseText );
}
};
}
function like() {
let js = JSON.parse(getCookie("likes"));
if (js.includes(game)) {
likeElement.innerText = 'Updating likes...';
getLikes(function(res) {
likes[game] = res;
likeElement.innerText = likes[game] + ' likes';
});
return;
}
let url = stenUnblockedAPILikes + 'like?game=' + encodeURIComponent(game);
const xml = new XMLHttpRequest();
xml.open("POST", url, true);
xml.send(null);
xml.onload = function(){
if (xml.status === 200) {
js.push(game);
setCookie("likes", JSON.stringify(js));
getLikes(function(res) {
likes[game]=res;
likeElement.innerText = likes[game] + ' likes';
});
return;
}
cb( "Error: " + xml.responseText);
};
}
if (getCookie("enabledCookie")=="1") {
try {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-MY0THGFRYS');
} catch {
console.log("[StenUnblocked] Failed to load google analytics!");
}
}
if (likeElement != null)
getLikes(function(likeCount) {
likeElement.innerText = likeCount + " likes";
});
(function(){
var gameURL = 'hmm';
try {
gameURL = '?game=' + encodeURIComponent(game);
} catch {
gameURL = '';
}
let xml = new XMLHttpRequest();
xml.open('POST', stenUnblockedAPIViews + 'view-game' + gameURL, true);
xml.send(null);
})();
function sleep(milliseconds) {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
var _hueMode = getCookie("hueMode") == "1";
async function hueModeLoop() {
while (_hueMode) {
let as = document.getElementsByTagName("a");
let speed = 1;
for (let r = 0; r < 360; r+=speed) {
for (let i = 0; i < as.length; i++) {
as[i].style.filter = 'hue-rotate(' + r + 'deg)';
as[i].style.color = 'red';
}
await sleep(1);
}
}
}
async function hueify(el) {
let speed = 1;
while (!_hueMode) {
for (let r = 0; r < 360; r+=speed) {
el.style.filter = 'hue-rotate(' + r + 'deg)';
el.style.color = 'red';
await sleep(1);
}
}
}
function clearHues() {
let as = document.getElementsByTagName("a");
for (let i = 0; i < as.length; i++) {
as[i].style.filter = '';
as[i].style.color = '';
}
}
function toggleHueMode() {
if (_hueMode) {
_hueMode = false;
setCookie("hueMode", "");
hueify(hueModeTxt);
clearHues();
} else {
_hueMode = true;
setCookie("hueMode", "1");
hueModeLoop();
}
}
var hueModeTxt = document.getElementById("hueModeTxt");
if (hueModeTxt) {
hueify(hueModeTxt);
hueModeTxt.addEventListener("onclick", function(e) {
toggleHueMode();
})
}
if (_hueMode)
hueModeLoop();