Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Ludicrous
Path: blob/main/pages/_app.tsx
1223 views
1
import '../styles/globals.css';
2
import styles from '../styles/Global.module.css';
3
import Config from '../config';
4
import type { AppProps } from 'next/app';
5
import Particles from "react-tsparticles";
6
import { loadFull } from "tsparticles";
7
import { IoReload, IoClose, IoExpand, IoArrowBack, IoArrowForward, IoOpenOutline } from 'react-icons/io5';
8
import Script from 'next/script';
9
import Layout from '../components/layout'
10
import { useRouter } from 'next/router';
11
12
const particlesInit: any = async (main: any) => {await loadFull(main)};
13
14
const particlesLoaded: any = (e: any) => {e.canvas.element.style.zIndex = '1'};
15
16
const g: any = global;
17
18
g.console.error = new Proxy(g.console.error, {
19
apply(t: any, g: any, a: any): any {
20
if (a[0].toString().startsWith('Error: Loading initial props cancelled')) return false;
21
22
return Reflect.apply(t, g, a);
23
}
24
})
25
26
function Ludicrous({ Component, pageProps }: AppProps) {
27
g.openFrame = async function(url: any, sw: Boolean = false, origin: URL = new URL(location.href)) {
28
var el: any = document.getElementById(styles['game-frame']);
29
30
if (!el.contentDocument) return false;
31
32
if (origin && g.localStorage) {
33
g.localStorage.setItem('__lud$origin', origin.origin);
34
}
35
36
el.contentDocument.open();
37
38
el.contentDocument.write(`
39
<html data-theme="dark">
40
<head>
41
<script>
42
document.documentElement.dataset.theme = localStorage.getItem('__lud$theme')||'dark';
43
</script>
44
<title>Loading...</title>
45
<style>
46
@import url('/font/index.css');
47
48
*[data-theme="light"] {
49
--page-bg: linear-gradient(-45deg, #747474, #4d5061, rgba(0 93 172));
50
--main-bg: #2467a5;
51
--text-color: white;
52
}
53
54
*[data-theme="fiwfhgnwghr"] {
55
--page-bg: linear-gradient(-45deg,#d0d0d0,#87888e,#3770a0);
56
--main-bg: #4f86b9;
57
--text-color: white;
58
}
59
60
*[data-theme="dark"] {
61
--page-bg: linear-gradient(-45deg,#000000,#000000,#114067);
62
--main-bg: #091b2c;
63
--text-color: white;
64
}
65
66
*[data-theme="fracital"] {
67
--page-bg: linear-gradient(-45deg,#000,#222,#ff77fc);
68
--main-bg: #282828;
69
--text-color: #ff77fc;
70
}
71
72
*[data-theme="illusive"] {
73
--page-bg: linear-gradient(-45deg,#000,#232323,#808080);
74
--main-bg: #181818;
75
--text-color: white;
76
}
77
78
body, html {
79
margin: 0;
80
background: var(--page-bg);
81
background-size: 300% !important;
82
width: 100vw;
83
height: 100vh;
84
display: flex;
85
align-items: center;
86
justify-content: center;
87
font-family: 'Roboto', sans-serif;
88
color: var(--text-color);
89
}
90
</style>
91
</head>
92
<body>
93
<h1>Please Wait</h1>
94
<script>
95
window.status = function(e) {
96
document.querySelector('h1').innerText = e;
97
}
98
99
history.replaceState(null, null, '/nolonger.html');
100
</script>
101
</body>
102
</html>
103
`);
104
105
document.getElementById('proxy-frame')!.style.display = 'block';
106
107
if (el.getAttribute('src')!==('/proxy.html')) document.getElementById(styles['game-frame'])!.setAttribute('src', '/proxy.html');
108
109
if (sw==false) el.contentDocument.querySelector('h1').innerText = 'Redirecting';
110
111
if (sw) el.contentDocument.querySelector('h1').innerText = 'Registering ServiceWorkers';
112
113
if (!navigator.serviceWorker.controller && (g.ludicrous&&g.ludicrous.sw) && sw) {
114
await g.ludicrous.sw();
115
}
116
117
if (sw&&(el.contentWindow)) el.contentDocument.querySelector('h1').innerText = 'ServiceWorkers Registered';
118
119
setTimeout(function() {
120
if (sw&&(el.contentWindow)) el.contentDocument.querySelector('h1').innerText = 'Redirecting';
121
122
if (!navigator.onLine) return el.contentDocument.querySelector('h1').innerText = 'Offline, Proxy no work :(';
123
124
setTimeout(e=>(document.getElementById(styles['game-frame'])||document.body).setAttribute('src', url), 300);
125
}, 250);
126
}
127
128
g.ludicrous = {
129
mode: process.env.NODE_ENV,
130
framework: 'next',
131
blank: (e: any) => {
132
var win: any = window.open();
133
134
win.document.write(`<head><title>Classes</title><link rel="icon" href="${location.origin}/icon/classroom.png"></head><body><iframe src="${location.href}" style="width:100vw;height:100vh;border:0;outline:0;position:absolute;top:0;left:0;z-index:9999999;"></iframe></body>`);
135
136
win.document.close();
137
138
return win;
139
},
140
reload: (e: any) => {
141
if (g.router) {
142
let init = g.router.asPath;
143
144
return g.router.replace("/blank").then(
145
() => g.router.replace(init),
146
);
147
}
148
149
throw new Error('No Global Router Object Found');
150
},
151
sw: async () => {
152
if ('serviceWorker' in (g.navigator||{})) {
153
for (var registration of await g.navigator.serviceWorker.getRegistrations()) {
154
if (registration.scope.includes('/~/')) await registration.unregister();
155
}
156
157
await navigator.serviceWorker.register('/psw.js', {
158
scope: Config.config.Ultraviolet.prefix,
159
});
160
161
await navigator.serviceWorker.register('/psw.js', {
162
scope: Config.config.Dynamic.prefix,
163
});
164
165
await new Promise((resolve) => setTimeout(resolve, 1000));
166
167
return true;
168
} else return false;
169
}
170
}
171
172
if (!g.particles) g.particles = <Particles
173
id="tsparticles"
174
init={particlesInit}
175
loaded={particlesLoaded}
176
options={{
177
fpsLimit: 120,
178
interactivity: {
179
events: {
180
resize: true,
181
},
182
},
183
particles: {
184
color: {
185
value: "#ffffff",
186
},
187
move: {
188
direction: "right",
189
enable: true,
190
outModes: {
191
default: "out",
192
},
193
random: false,
194
speed: 1,
195
straight: false,
196
},
197
number: {
198
density: {
199
enable: true,
200
area: 800,
201
},
202
value: 48,
203
},
204
opacity: {
205
value: 0.6814501258678471,
206
random: true,
207
anim: {
208
enable: true,
209
speed: 0.24362316369040352,
210
opacity_min: 0.03248308849205381,
211
sync: false
212
}
213
},
214
shape: {
215
type: "circle",
216
},
217
size: {
218
anim: {
219
enable: true,
220
speed: 2.872463273808071,
221
size_min: 2.436231636904035,
222
sync: false
223
},
224
value: { min: 2, max: 3 },
225
},
226
},
227
detectRetina: true,
228
}}
229
/>
230
231
if (g.localStorage) {
232
if (g.localStorage.getItem('__lud$proxy')) {
233
Config.proxy = g.localStorage.getItem('__lud$proxy');
234
}
235
}
236
237
var bareOffline = false;
238
var ea: any = {};
239
240
try {
241
Object.defineProperty(ea, 'isOffline', {
242
get() {
243
return bareOffline;
244
},
245
set(val) {
246
console.log(val);
247
bareOffline = val;
248
249
var el: any = document.querySelector('#online-offline-show');
250
251
if (val&&el) el.style.display = 'block'
252
if (!val&&el) el.style.display = 'none'
253
254
return true;
255
}
256
})
257
} catch {}
258
259
g.router = useRouter();
260
261
pageProps.config = Config;
262
if (global.window) {
263
window.ononline = function() {
264
ea.isOffline = false;
265
}
266
267
window.onoffline = function() {
268
ea.isOffline = true;
269
}
270
271
try {
272
Object.defineProperty(window, '__lud$icon', {
273
set(val) {
274
var el: any = document.head.querySelector('link[rel="icon"]');
275
276
if (el&&el.getAttribute('href')!==val) el.href = val;
277
},
278
get() {
279
var el: any = document.head.querySelector('link[rel="icon"]');
280
return el.href;
281
}
282
});
283
} catch {};
284
285
try {
286
Object.defineProperty(window, '__lud$theme', {
287
configurable: true,
288
set(val) {
289
var el: any = document.querySelector('*[data-theme]');
290
291
if (el&&el.dataset.theme!==val) el.dataset.theme = val;
292
},
293
get() {
294
var el: any = document.querySelector('*[data-theme]');
295
return el.dataset.theme;
296
}
297
});
298
} catch {};
299
300
var win: any = window;
301
302
setInterval(function() {
303
if (localStorage.getItem('__lud$icon'))
304
win.__lud$icon = localStorage.getItem('__lud$icon')||'/favicon.ico';
305
}, 1);
306
307
setInterval(function() {
308
if (localStorage.getItem('__lud$title'))
309
window.document.title = localStorage.getItem('__lud$title')||'';
310
}, 1);
311
312
if (localStorage.getItem('__lud$title')) {
313
window.document.title = localStorage.getItem('__lud$title')||'';
314
315
var des: any = Object.getOwnPropertyDescriptor(window.Document.prototype, 'title')||{};
316
317
try {
318
Object.defineProperty(window.document, 'title', {
319
get() {
320
return des.get.call(this);
321
},
322
set(val) {
323
if (!localStorage.getItem('__lud$title')) return des.set.call(this, (document.querySelector('title')||{}).innerText);
324
if (des.get.call(this)==localStorage.getItem('__lud$title')) return val;
325
326
des.set.call(this, localStorage.getItem('__lud$title'));
327
328
return val;
329
}
330
});
331
} catch {};
332
} else window.document.title = 'Ludicrous';
333
334
const frame: any = document.getElementById(styles['game-frame']);
335
336
if (frame) frame.loads = 0;
337
338
const frameLoad: any = function(e: any) {
339
if (frame) frame.loads++;
340
341
clearInterval(frame.interval);
342
343
var title: any = document.querySelector('.frame-title');
344
var icon: any = document.querySelector('.frame-icon');
345
346
if (!frame.contentDocument) return setTimeout(frameLoad, 1000);
347
348
title.innerText = frame.contentDocument.title || frame.contentWindow.location.href;
349
350
frame.interval = setInterval(function() {
351
if (!frame.contentDocument) return clearInterval(frame.interval);
352
353
var expected = frame.contentDocument.title || frame.contentWindow.location.href;
354
355
if (title.innerText === expected) return;
356
357
title.innerText = expected;
358
}, 500);
359
}
360
361
if (frame) frame.onload = frameLoad;
362
}
363
364
const reloadFrame: any = function(e: any) {
365
var frame: any = document.getElementById(styles['game-frame']);
366
367
if (frame) frame.contentWindow.location.reload();
368
}
369
370
const closeFrame: any = function(e: any) {
371
var e: any = document.querySelector('#proxy-frame');
372
if (e) e.style.display = 'none';
373
374
var origin = new URL(localStorage.getItem('__lud$origin') || location.href);
375
376
if (origin.origin === location.origin) {
377
return g.router.replace(origin.pathname);
378
}
379
380
return g.location!.href = origin;
381
382
//location.href = '/';
383
}
384
385
const fullScreen: any = function(e: any) {
386
var e: any = document.getElementById(styles['game-frame'])
387
if (e) e.requestFullscreen();
388
}
389
390
const backward: any = function(e: any) {
391
var frame: any = document.getElementById(styles['game-frame']);
392
393
if (frame.contentWindow.history.state) return false;
394
395
if (frame) frame.contentWindow.history.back();
396
}
397
398
const forward: any = function(e: any) {
399
var frame: any = document.getElementById(styles['game-frame']);
400
401
if (frame) frame.contentWindow.history.forward();
402
}
403
404
const newPage: any = function(e: any) {
405
var frame: any = document.getElementById(styles['game-frame']);
406
407
if (frame) window.open(frame.contentWindow.location.href);
408
}
409
410
if (g.window) {
411
g.window.__lud$theme = g.localStorage.getItem('__lud$theme')||'dark';
412
};
413
414
return (
415
<>
416
<div data-theme="dark">
417
<script async src="/data/index.js"></script>
418
<div style={{
419
background: 'red',
420
border: '2px solid white',
421
zIndex: '2',
422
borderRadius: '3px',
423
color: 'white',
424
padding: '10px 20px',
425
position: 'absolute',
426
top: '10px',
427
left: '10px',
428
display: 'none',
429
}} id="online-offline-show">Offline - Proxies and Games may not work.</div>
430
<div id="proxy-frame" className={styles['game-div']}>
431
<div id={styles['game-header']}>
432
<div className="frame-icon" id={styles['frame-icon']}></div>
433
<div className="frame-title" id={styles['frame-title']}>Loading...</div>
434
435
<div className="frame-close" onClick={closeFrame} id={styles['frame-close']}><IoClose /></div>
436
<div className="frame-reload" onClick={reloadFrame} id={styles['frame-reload']}><IoReload /></div>
437
<div className="frame-fullscr" onClick={fullScreen} id={styles['frame-full']}><IoExpand /></div>
438
<div className="frame-open" onClick={newPage} id={styles['frame-open']}><IoOpenOutline /></div>
439
440
<div className="frame-for" onClick={forward} id={styles['frame-forward']}><IoArrowForward /></div>
441
<div className="frame-back" onClick={backward} id={styles['frame-back']}><IoArrowBack /></div>
442
</div>
443
<iframe src="/proxy.html" id={styles['game-frame']}></iframe>
444
</div>
445
<Layout particles={g.particles}>
446
<Component {...pageProps} particles={''} ></Component>
447
</Layout>
448
<Script src="/main.js"></Script>
449
</div>
450
</>
451
)
452
}
453
454
export default Ludicrous;
455
456