-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenter.js
470 lines (442 loc) · 14.7 KB
/
enter.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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
const pageStack = [];
//old stuff but now just hides scrollbar
function openEnterScreen() {
//document.getElementsByTagName("body")[0].style.overflow = "hidden";
};
//transition effect
function transitionScreen(){
screenCover = document.getElementById('transitionScreen');
screenCover.style.opacity = .5;
screenCover.style.display = "block";
setTimeout(()=>{
screenCover.style.opacity = 0;
}, 300);
setTimeout(()=>{
screenCover.style.display = "none";
}, 800);
};
//for if you killed him
let guyStatus = 'alive';
let guyHealth = 100;
if (readCookie('guyHealth')){
guyStatus = 'dead';
guyHealth = parseInt(readCookie('guyHealth'), 10);
};
//fades out splash screen and hides it
function closeEnterScreen(){
document.getElementsByTagName("body")[0].style.overflow = "auto";
screenCover = document.getElementById("screenCover")
screenCover.style.transform = "translate(0px, -1000px)";
screenCover.style.opacity = 0;
setTimeout(()=>{
screenCover.style.display = "none";
}, 500);
//plays music
mainMusic.loop = true;
if (guyStatus === 'dead'){
document.getElementsByClassName('playbackButton')[0].setAttribute('onclick', "resuscitate()");
document.getElementsByClassName('playbackButton')[0].style.backgroundImage = "url('./res/404.jpg')";
console.log('he is dead. click him to resucitate');
} else if (readCookie('muteMusic') === 'true') {
console.log('mute pref = muted');
document.getElementsByClassName('playbackButton')[0].style.backgroundImage = "url('./res/notVibing.gif')";
} else {
mainMusic.play();
};
};
//bring him back
function resuscitate(){
guyHealth++;
writeCookie('guyHealth', guyHealth);
console.log(guyHealth + "/100");
if (guyHealth > 99){
deleteCookie('guyHealth');
document.getElementsByClassName('playbackButton')[0].setAttribute('onclick', "music()");
document.getElementsByClassName('playbackButton')[0].style.backgroundImage = "url('./res/vibing.gif')";
console.log("thanks man! i thought i was a goner for sure!")
if (readCookie('muteMusic') === 'true') {
console.log('mute pref = muted');
document.getElementsByClassName('playbackButton')[0].style.backgroundImage = "url('./res/notVibing.gif')";
} else {
mainMusic.play();
};
};
};
//runs on page load
window.onload = function(){
openEnterScreen();
loadPageContents(getUri());
};
//music
let mainMusic = new Audio('./res/CoaXioNTrackNo.1LowSampleRate.ogg');
function music() {
if (mainMusic.paused === false){
mainMusic.pause();
document.getElementsByClassName('playbackButton')[0].style.backgroundImage = "url('./res/notVibing.gif')";
writeCookie('muteMusic', 'true');
} else {
mainMusic.play();
document.getElementsByClassName('playbackButton')[0].style.backgroundImage = "url('./res/vibing.gif')";
deleteCookie('muteMusic');
}
};
//music stops when tab not focused
const handleVisibilityChange = function() {
if (document.visibilityState === 'visible') {
if (readCookie('guyHealth') < 100){
return;
}
if (readCookie('muteMusic') != 'true') {
mainMusic.play();
};
} else {
mainMusic.pause();
};
};
document.addEventListener("visibilitychange", handleVisibilityChange);
//sounds
let soundPlaying = false;
function playSound(sound) {
//prevents hover sound from playing on smaller screens
if (sound === './res/hover.mp3'){
if (screen.width < 1053){
return;
};
};
if (sound === './res/click.mp3' || sound === './res/hover.mp3'){
var audio = new Audio(sound);
audio.play();
return;
};
if (soundPlaying === false) {
var audio = new Audio(sound);
audio.onloadedmetadata = function () {
let soundLength = audio.duration;
soundPlaying = true;
audio.play();
if (readCookie('muteMusic') != 'true'){
mainMusic.volume = 0.1;
};
setTimeout(() => {
soundPlaying = false;
if (readCookie('muteMusic') != 'true'){
mainMusic.volume = 1;
};
}, soundLength * 1000);
};
};
};
//page switching
pageHtml = "";
function getUri(){
url = window.location.href;
uri = url.substring(url.search("=") +1 , url.length);
return uri;
};
firstLoad = true;
function loadPageContents(name) {
if (firstLoad === false){
//funny effects
transitionScreen();
playSound('./res/click.mp3');
pageStack.push(getUri());
};
firstLoad = false;
//changes url
const url = new URL(window.location);
url.searchParams.set('', [name]);
window.history.pushState({}, '', url);
//goatcounter inserted
function initGoatCounter() {
var t = setInterval(function() {
if (window.goatcounter && window.goatcounter.visit_count) {
clearInterval(t);
window.goatcounter.visit_count({
append: '#stats',
no_branding: true,
style: `
div { border-color: transparent; background-color: #141414; color: #888888; border-radius: 0px; }
#gcvc-views { font-family: monospace; }
#gcvc-for { color: #888888; }
`
});
}
}, 100);
};
function initGoatCounterFr() {
document.getElementById('stats').innerHTML ="<div style='position:relative; z-index:1; width:200px; height:25px; text-align:center; background-color:#141414; margin-bottom:-25px;'><p>Total Page Views:</p></div><div style='position:absolute; width:200px; height:50px; text-align:center; padding-top:20px;'><p>disable adblock to view</p></div>";
initGoatCounter();
var script2 = document.createElement('script');
script2.dataset.goatcounter = 'https://coaxion.goatcounter.com/count';
script2.async = true;
script2.src = './count.js';
document.body.appendChild(script2);
};
//back to page load
if (name === 'home' || name === 'deathmatch_classic_refragged' || name === 'lambda_fortress' || name === 'the_espionage_project' || name === 'coplay' || name === 'credits' || name === 'error'){
initGoatCounterFr();
//fetches html file
fetch("./" + [name] + ".html")
.then(response => response.text())
.then(text => pageHtml = text)
.then(enact => {
let stage = document.getElementById("infoCards");
stage.innerHTML = pageHtml;
pageSpecificChanges(name);
retreiveBlogList();
window.scrollTo(0, 0);
});
//for fetching blog pages
} else if(name.search('-') > -1){
initGoatCounterFr();
postName = name.substring(name.search("-") + 1, name.length);
game = name.substring(0, name.search("-"));
//normal page fetch but it puts it in a card
fetch("./blogs/" + game + "/" + postName + ".html")
.then(response => response.text())
.then(text => pageHtml = text)
.then(enact => {
let stage = document.getElementById("infoCards");
stage.innerHTML = '';
//title
let fullBlogList = {};
fetch("./blogs/bloglist.json")
.then(response => response.json())
.then(json => fullBlogList = json)
.then(bruh => {placeBlogInfo()});
function placeBlogInfo(){
let totalPostCount = fullBlogList[game].length;
let postNumber = 0;
for (let i = 0; i <= totalPostCount -1; i++){
let title = fullBlogList[game][i].contentUrl;
if (title === name){
postNumber = i;
break;
};
};
let postTitle = fullBlogList[game][postNumber].title;
let postDate = fullBlogList[game][postNumber].date;
let newCard = document.createElement("div");
newCard.classList.add("infoCard");
newCard.innerHTML = "<h1>" + postTitle + "</h1><p>" + postDate + "</p>";
stage.appendChild(newCard);
//content
newCard = document.createElement("div");
newCard.classList.add("infoCard");
newCard.innerHTML = pageHtml;
stage.appendChild(newCard);
pageSpecificChanges(game);
retreiveBlogList();
window.scrollTo(0, 0);
};
});
} else {
const url = new URL(window.location);
url.searchParams.set('', 'home');
window.history.pushState({}, '', url);
firstLoad = true;
document.getElementById('stats').innerHTML ="<div style='position:absolute; width:200px; height:25px; text-align:center; background-color:#141414;'><p>Page Views:</p></div>";
loadPageContents('home');
};
};
function pageSpecificChanges(page){
var topBarColor = document.getElementsByClassName("topBar")[0];
switch(page){
case "home":
//just to make home look more normal, i got rid of its search parameter
topBarColor.style.borderColor = "#a9a9a9";
const url = new URL(window.location);
url.searchParams.delete('');
window.history.pushState({}, '', url);
resetIcons();
break;
case "error":
resetIcons();
break;
case "deathmatch_classic_refragged":
topBarColor.style.borderColor = "#ec382c";
resetIcons();
icon = document.getElementById("dmcrIcon");
icon.style.filter = "saturate(1) brightness(1)";
initCarousel();
break;
case "lambda_fortress":
topBarColor.style.borderColor = "rgb(248, 176, 50)";
resetIcons();
icon = document.getElementById("lfIcon");
icon.style.filter = "saturate(1) brightness(1)";
initCarousel();
break;
case "legacy_lambda_fortress_extended":
resetIcons();
icon = document.getElementById("lfIcon");
icon.style.filter = "saturate(1) brightness(1)";
break;
case "the_espionage_project":
topBarColor.style.borderColor = "#3a6be9";
resetIcons();
icon = document.getElementById("tepIcon");
icon.style.filter = "saturate(1) brightness(1)";
initCarousel();
break;
case "coplay":
topBarColor.style.borderColor = "rgb(146 215 0)";
resetIcons();
icon = document.getElementById("coplayIcon");
icon.style.filter = "saturate(1) brightness(1)";
initCarousel();
break;
default:
resetIcons();
break;
};
};
//makes browser back button work
window.addEventListener('popstate', function(event) {
if (pageStack.length > 0) {
firstLoad = true;
const previousPage = pageStack.pop();
loadPageContents(previousPage);
playSound('./res/click.mp3');
transitionScreen();
}
});
function retreiveBlogList(){
//for building blog lists
let fullBlogList = {};
if (document.getElementsByClassName("blogPostList")[0] != undefined){
fetch("./blogs/bloglist.json")
.then(response => response.json())
.then(json => fullBlogList = json)
.then(bruh => {buildBlogList()});
};
//what to do if
function buildBlogList(){
let postListElement = document.getElementsByClassName("blogPostList")[0];
let blogType = postListElement.id;
let blogTypeName = '';
switch(blogType){
case "dmcrList":
blogTypeName = 'deathmatch_classic_refragged';
break;
case "llfeList":
blogTypeName = 'legacy_lambda_fortress_extended';
break;
case "lfList":
blogTypeName = 'lambda_fortress';
break;
case "tepList":
blogTypeName = 'the_espionage_project';
break;
};
let totalPostCount = fullBlogList[blogTypeName].length;
for (let i = 0; i <= totalPostCount -1; i++){
let post = document.createElement("div");
post.classList.add("postPreview");
let thumbnail = document.createElement("img");
thumbnail.src = fullBlogList[blogTypeName][i].thumbnailUrl;
post.appendChild(thumbnail);
let previewTextDiv = document.createElement("div");
previewTextDiv.classList.add("postPreviewText");
let title = document.createElement("h2");
title.innerHTML = fullBlogList[blogTypeName][i].title;
let postUrl = fullBlogList[blogTypeName][i].contentUrl;
post.setAttribute('onclick', "loadPageContents('" + postUrl + "')");
previewTextDiv.appendChild(title);
let date = document.createElement("p");
date.innerHTML = fullBlogList[blogTypeName][i].date;
previewTextDiv.appendChild(date);
let description = document.createElement("p");
description.innerHTML = fullBlogList[blogTypeName][i].description;
previewTextDiv.appendChild(description);
post.appendChild(previewTextDiv);
post.style.order = -i;
postListElement.appendChild(post);
};
};
};
//image carousel
let totalImages = 0;
let currentImage = 0;
function initCarousel(){
totalImages = document.getElementsByClassName("carouselImage").length;
currentImage = 0;
document.getElementsByClassName("carouselImage")[currentImage].id = "";
document.getElementsByClassName("imageNumber")[0].innerHTML = "<p>" + [currentImage + 1] + "/" + totalImages + "</p>";
};
function nextImage(){
playSound('./res/click2.mp3');
let currentImageElement = document.getElementsByClassName("carouselImage")[currentImage];
currentImageElement.id = "imageHidden";
currentImage++;
//loopback image using modulo
currentImage = currentImage % totalImages;
currentImageElement = document.getElementsByClassName("carouselImage")[currentImage];
currentImageElement.id = "";
document.getElementsByClassName("imageNumber")[0].innerHTML = "<p>" + [currentImage + 1] + "/" + totalImages + "</p>";
};
function previousImage(){
playSound('./res/click2.mp3');
let currentImageElement = document.getElementsByClassName("carouselImage")[currentImage];
currentImageElement.id = "imageHidden";
--currentImage;
//loopback image with if statement
if (currentImage < 0){
currentImage = totalImages - 1;
};
currentImageElement = document.getElementsByClassName("carouselImage")[currentImage];
currentImageElement.id = "";
document.getElementsByClassName("imageNumber")[0].innerHTML = "<p>" + [currentImage + 1] + "/" + totalImages + "</p>";
};
//resets icon styles
function resetIcons(){
dmcrIcon = document.getElementById("dmcrIcon");
lfIcon = document.getElementById("lfIcon");
tepIcon = document.getElementById("tepIcon");
coplayIcon = document.getElementById("coplayIcon");
dmcrIcon.style.filter = "saturate(0) brightness(1.6)";
lfIcon.style.filter = "saturate(0)";
tepIcon.style.filter = "saturate(0)";
coplayIcon.style.filter = "saturate(0)";
};
//mobile scroll physics
if (screen.width < 1053){
window.onscroll = function(e) {
// print "false" if direction is down and "true" if up
let scrollingDown = this.oldScroll < this.scrollY;
this.oldScroll = this.scrollY;
console.log(scrollingDown);
if (scrollingDown === true){
document.getElementsByClassName('topBar')[0].style.top = '-100px';
document.getElementsByClassName('constructionMessage')[0].style.top = '20px';
} else {
document.getElementsByClassName('topBar')[0].style.top = '0px';
document.getElementsByClassName('constructionMessage')[0].style.top = '200px';
};
};
};
//cookie functions borrowed from boxkid.net
function writeCookie(name, property) {
document.cookie = name + '=' + property + ';expires=Thu, 01 Jan 2030 00:00:00 GMT;path=/';
};
function readCookie(name) {
if (document.cookie !== '') {
let allCookies = document.cookie.split('; ');
let cookie = allCookies.find(row => row.startsWith(name + '='));
if (cookie) {
let cookieValue = cookie.split('=')[1];
return cookieValue;
} else {
return false;
};
};
};
function deleteCookie(name) {
document.cookie = name + '=' + ';expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/';
}
function clearCookies() {
let allCookies = document.cookie.split('; ');
for (var i = 0; i < allCookies.length; i++) {
deleteCookie(allCookies[i]);
};
};