-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgame.js
More file actions
916 lines (807 loc) · 40.4 KB
/
game.js
File metadata and controls
916 lines (807 loc) · 40.4 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
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
var gameData = {};
var gameCategories = {
"none": "Uncategorised",
"action": "Action",
"adventure": "Adventure",
"animals": "Animals",
"arcade": "Arcade",
"board": "Board Game",
"driving": "Driving",
"idle": "Idle",
"multiplayer": "Multiplayer",
"mystery": "Mystery",
"platformer": "Platformer",
"puzzle": "Puzzle",
"rp": "Role-Playing",
"simulation": "Simulation",
"sports": "Sports",
"strategy": "Strategy",
"survival": "Survival"
};
var xrunProxy = "https://crossrun.onrender.com/";
var showingFullscreenControls = true;
var isFullscreen = false;
function getURLParameter(name) {
return decodeURIComponent((new RegExp("[?|&]" + name + "=" + "([^&;]+?)(&|#|;|$)").exec(location.search) || [null, ""])[1].replace(/\+/g, "%20")) || null;
}
function formatDate(date) {
var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var day = date.getDate();
var monthIndex = date.getMonth();
var year = date.getFullYear();
return day + " " + monthNames[monthIndex] + " " + year + " at " + date.toLocaleTimeString("en-GB", {hour: "2-digit", minute: "2-digit"});
}
function toDataUrl(url, callback) {
if (url == null) {
callback(null);
} else if (url.startsWith("data:")) {
callback(url);
} else {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open("GET", url);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.responseType = "blob";
xhr.send();
}
}
function refreshCreatorPpic() {
firebase.storage().ref("users/" + gameData.uid + "/_settings/ppic.png").getDownloadURL().then(function(data) {
$(".creatorAccountPicture").attr("src", data);
});
}
function like() {
firebase.database().ref("games/" + getURLParameter("play") + "/metrics").once("value", function(snapshot) {
var likesData = snapshot.val();
if (likesData.likesProof === undefined) {
likesData.likesProof = [];
}
if (likesData.likesProof.indexOf(currentUid) > -1) {
firebase.database().ref("games/" + getURLParameter("play") + "/metrics/likes").set(likesData.likes - 1);
firebase.database().ref("games/" + getURLParameter("play") + "/metrics/likesProof").set(likesData.likesProof.filter(function(element) {
return element != currentUid;
}));
} else {
firebase.database().ref("games/" + getURLParameter("play") + "/metrics/likes").set(likesData.likes + 1);
firebase.database().ref("games/" + getURLParameter("play") + "/metrics/likesProof").set(likesData.likesProof.concat([currentUid]));
}
});
};
function postComment() {
if (currentUid != null) {
var commentData = $("#commentBox").val();
$("#commentBox").val("");
if (commentData.trim() != "") {
firebase.database().ref("users/" + currentUid + "/_settings/name").once("value", function(snapshot) {
var name = snapshot.val();
firebase.database().ref("games/" + getURLParameter("play") + "/comments").push().set({
dateAdded: formatDate(new Date()),
uid: currentUid,
by: name,
byStaff: isStaff(currentUid),
content: profanity.clean(commentData)
});
if (gameData.uid != currentUid) {
firebase.database().ref("users/" + gameData.uid + "/notifications/unread").push().set({
type: "comment",
date: new Date().getTime(),
uid: currentUid,
username: name,
target: getURLParameter("play"),
targetName: gameData.title,
content: profanity.clean(commentData)
});
}
});
}
}
}
function showMoreDescription() {
$(".gameDescription").css("max-height", "unset");
$(".gameSeeMore").hide();
}
function fullscreen(goFullscreen = true) {
if (goFullscreen) {
isFullscreen = true;
$("object, #gameIframe").css({
position: "fixed",
top: 0,
left: 0,
width: "100vw",
height: "100vh",
zIndex: 1,
backgroundColor: "black"
});
$("embed").css("height", "100vh");
$("body").css("overflow", "hidden");
$("#gameFullscreenOptions").show();
$("#gameIframe").focus();
// Fullscreen for different platforms
try {
document.body.requestFullscreen();
} catch (e) {}
try {
document.body.webkitRequestFullScreen();
} catch (e) {}
try {
document.body.mozRequestFullScreen();
} catch (e) {}
try {
document.body.msRequestFullScreen();
} catch (e) {}
$(".fullscreenWatermark").show();
} else {
isFullscreen = false;
streamingOptions(false);
streamingDisplay(false);
$("object, #gameIframe").css({
position: "unset",
top: "unset",
left: "unset",
width: "calc(100% - 10px)",
height: "35vw",
zIndex: "unset",
backgroundColor: "unset"
});
$("embed").css("height", "60vh");
$("body").css("overflow", "unset");
$("#gameFullscreenOptions").hide();
$("#gameIframe").focus();
// Fullscreen for different platforms
try {
document.exitFullscreen();
} catch (e) {}
try {
document.webkitCancelFullScreen();
} catch (e) {}
try {
document.mozCancelFullScreen();
} catch (e) {}
try {
document.msExitFullScreen();
} catch (e) {}
$(".fullscreenWatermark").hide();
}
}
function toggleFullscreenControls() {
if (showingFullscreenControls) {
$("#gameFullscreenOptionsButtons").hide();
$("#gameFullscreenOptionsHandle > i").text("chevron_left");
} else {
$("#gameFullscreenOptionsButtons").show();
$("#gameFullscreenOptionsHandle > i").text("chevron_right");
}
showingFullscreenControls = !showingFullscreenControls;
}
function hideCrossRunBalloon(doSet = true) {
$(".balloon.xrun").fadeOut();
if (doSet) {
localStorage.setItem("hideXrunBalloon", "true");
}
}
function switchToCrossRun(xrun = true) {
hideCrossRunBalloon();
if (xrun) {
window.location.href = window.location.href + "&xrun=true";
} else {
window.location.href = window.location.href.split("?")[0] + "?play=" + getURLParameter("play");
}
}
function verifyGame() {
if (isStaff(currentUid)) {
firebase.database().ref("games/" + getURLParameter("play") + "/verified").set(!gameData.verified);
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function deleteGameAction() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
firebase.database().ref("games/" + getURLParameter("play")).set(null);
window.location.href = isStaff(currentUid) ? "admin" : "account";
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function deleteGame() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
dialog("Delete Game", "Is it okay to delete this game? This action can't be undone.", [
{text: "Cancel", onclick: "closeDialog();", type: "bad"},
{text: "Delete", onclick: "deleteGameAction();", type: "reallyBad"}
]);
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function editGameTitleAction() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
firebase.database().ref("games/" + getURLParameter("play") + "/title").set(capitalizeText(profanity.clean($(".editGameTitleInput").val())));
window.location.reload();
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function editGameTitle() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
dialog("Edit Game Title", `
<div class="center">
<p>Your new title awaits...</p>
<input value="` + gameData.title.replace(/</g, "<").replace(/>/g, ">") + `" class="editGameTitleInput fullWidth"></input>
</div>
`, [
{text: "Cancel", onclick: "closeDialog();", type: "bad"},
{text: "Edit", onclick: "editGameTitleAction();", type: "normal"}
]);
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function editGameCategoryAction() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
firebase.database().ref("games/" + getURLParameter("play") + "/category").set(profanity.clean($(".editGameCategoryInput").val()));
window.location.reload();
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function editGameCategory() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
dialog("Edit Game Category", `
<div class="center">
<p>Your new category awaits...</p>
<select class="editGameCategoryInput">
<option value="none">Don't Categorise</option>
<option value="action">Action</option>
<option value="adventure">Adventure</option>
<option value="animals">Animals</option>
<option value="arcade">Arcade</option>
<option value="board">Board Game</option>
<option value="driving">Driving</option>
<option value="idle">Idle</option>
<option value="multiplayer">Multiplayer</option>
<option value="mystery">Mystery</option>
<option value="platformer">Platformer</option>
<option value="puzzle">Puzzle</option>
<option value="rp">Role-Playing</option>
<option value="simulation">Simulation</option>
<option value="sports">Sports</option>
<option value="strategy">Strategy</option>
<option value="survival">Survival</option>
</select>
</div>
`, [
{text: "Cancel", onclick: "closeDialog();", type: "bad"},
{text: "Edit", onclick: "editGameCategoryAction();", type: "normal"}
]);
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function editGameURLAction() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
firebase.database().ref("games/" + getURLParameter("play") + "/src").set($(".editGameURLInput").val());
firebase.database().ref("games/" + getURLParameter("play") + "/verified").set(false);
window.location.reload();
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function editGameURL() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
dialog("Edit Game URL", `
<div class="center">
<p>Change the URL below:</p>
<input value="` + gameData.src.replace(/</g, "<").replace(/>/g, ">") + `" class="editGameURLInput fullWidth"></input>
</div>
`, [
{text: "Cancel", onclick: "closeDialog();", type: "bad"},
{text: "Edit", onclick: "editGameURLAction();", type: "normal"}
]);
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function editGameThumbnailAction() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
var thumbnailInput = $(".editGameThumbnailInput").val();
dialog("Please Wait...", "Changing your thumbnail, it may take a few seconds of your life.", []);
toDataUrl(
gameData.src.startsWith("https://scratch.mit.edu/projects/")?
"https://cors-anywhere.herokuapp.com/" + "https://cdn2.scratch.mit.edu/get_image/project/" + gameData.src.split("/")[4] + "_288x216.png"
: (
thumbnailInput != "" ?
"https://cors-anywhere.herokuapp.com/" + thumbnailInput
: null
)
,
function(base64Img) {
firebase.database().ref("games/" + getURLParameter("play") + "/thumbnail").set(base64Img).then(function() {
window.location.reload();
});
}
);
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function editGameThumbnail() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
dialog("Edit Game Thumbnail", `
<div class="center">
<p>Paste an image URL here! Don't forget the http:// or https:// at the start.</p>
<input class="editGameThumbnailInput fullWidth"></input>
</div>
`, [
{text: "Cancel", onclick: "closeDialog();", type: "bad"},
{text: "Edit", onclick: "editGameThumbnailAction();", type: "normal"}
]);
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function editGameDescriptionAction() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
firebase.database().ref("games/" + getURLParameter("play") + "/description").set(profanity.clean($(".editGameDescriptionInput").val()));
window.location.reload();
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function editGameAttributionAction() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
firebase.database().ref("games/" + getURLParameter("play") + "/attributionText").set($("#attributionText").val());
firebase.database().ref("games/" + getURLParameter("play") + "/attributionLink").set($("#attributionLink").val());
window.location.reload();
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function editGameDescription() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
dialog("Edit Game Description", `
<div class="center">
<p>Your new description awaits...</p>
<textarea class="editGameDescriptionInput fullWidth">` + gameData.description.replace(/</g, "<").replace(/>/g, ">") + `</textarea>
</div>
`, [
{text: "Cancel", onclick: "closeDialog();", type: "bad"},
{text: "Edit", onclick: "editGameDescriptionAction();", type: "normal"}
]);
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function editGameAttribution() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
dialog("Edit Game Attribution", `
<div class="center">
<p>Your new attribution awaits...</p>
<input placeholder="Attribution Text" class="attributionGameUploadField" id="attributionText"></input>
<input placeholder="Attribution Link" class="attributionGameUploadField" id="attributionLink"></input>
</div>
`, [
{text: "Cancel", onclick: "closeDialog();", type: "bad"},
{text: "Edit", onclick: "editGameAttributionAction();", type: "normal"}
]);
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
function showEditGameInfo() {
if (isStaff(currentUid) || gameData.uid == currentUid) {
dialog("Edit Game Info", `
<div>
<h2 class="noMargin">Edit title</h2>
<p class="noMargin">Edit the title of the game, also changing the game's searchable name.</p>
<div class="right">
<button onclick="editGameTitle();">Edit</button>
</div>
</div>
<div>
<h2 class="noMargin">Edit description</h2>
<p class="noMargin">Update the description of the game, possibly to fix layouts or links.</p>
<div class="right">
<button onclick="editGameDescription();">Edit</button>
</div>
</div>
<div>
<h2 class="noMargin">Edit game URL</h2>
<p class="noMargin">Edit the URL of the game to fix errors if the source stops working.</p>
<div class="right">
<button onclick="editGameURL();">Edit</button>
</div>
</div>
<div>
<h2 class="noMargin">Edit thumbnail</h2>
<p class="noMargin">Edit the thumbnail link of the game. Make it look good!</p>
<div class="right">
<button onclick="editGameThumbnail();">Edit</button>
</div>
</div>
<div>
<h2 class="noMargin">Edit category</h2>
<p class="noMargin">Edit the category of the game. Make it easier to find!</p>
<div class="right">
<button onclick="editGameCategory();">Edit</button>
</div>
</div>
<div>
<h2 class="noMargin">Edit attribution</h2>
<p class="noMargin">Edit the attribution text and link to give credit to the creator.</p>
<div class="right">
<button onclick="editGameAttribution();">Edit</button>
</div>
</div>
<div>
<h2 class="noMargin">Delete game</h2>
<p class="noMargin">Remove the game from GameProxy. Realise the potential mistake that lays upon you for doing so.</p>
<div class="right">
<button class="reallyBad" onclick="deleteGame();">Delete</button>
</div>
</div>
`, [{text: "Cancel", onclick: "closeDialog();", type: "bad"}]);
} else {
alert("Nice try, hacker! You'll never break our security.");
}
}
$(function() {
$(".gameVerified").hide();
$(".gameSeeMore").hide();
$(".gameDescription").css({
"max-height": "100px",
"overflow": "hidden"
});
firebase.auth().onAuthStateChanged(function(user) {
if (currentUid == null) {
$(".postComment").text("Sign in to comment");
$(".postComment").css({
backgroundColor: "#7e7e7e",
color: "black",
cursor: "default"
});
} else {
setInterval(function() {
if (isGameProxyPro(currentUid)) {
$(".adBox").remove();
}
}, 10);
}
});
firebase.database().ref("games/" + getURLParameter("play")).once("value", function(snapshot) {
gameData = snapshot.val();
if (gameData == null) {
window.location.href = "404.html";
}
$(".gameName").text(gameData.title);
$(".creatorAccountName").text(gameData.by);
$(".creatorProfileLink").attr("href", "profile?user=" + gameData.uid);
$(".creatorProfileButton").attr("onclick", "window.location.href = 'profile?user=" + gameData.uid + "';");
$(".gameDate").text("Uploaded " + gameData.dateAdded);
if (typeof(gameData.category) == "string") {
$(".gameCategory").text(gameCategories[gameData.category]);
} else {
$(".gameCategory").text(gameCategories["none"]);
}
if (gameData.attributionText == undefined) {
$(".gameAttribution").text("Not provided");
} else if (gameData.attributionText == "") {
$(".gameAttribution").text("Not provided");
} else {
$(".gameAttribution").text(gameData.attributionText);
$(".gameAttribution").attr("href", gameData.attributionLink);
}
var converter = new showdown.Converter();
if (gameData.description.trim() != "") {
$(".gameDescription").html(converter.makeHtml(gameData.description.replace(/</g, "<").replace(/>/g, ">")));
} else {
$(".gameDescription").html("<p class='center'><em>Nothing to see here...</em></p>");
}
if ($(".gameDescription").prop("scrollHeight") > $(".gameDescription").height()) {
$(".gameSeeMore").show();
}
if (gameData.byStaff) {
$(".creatorAccountName").css("color", "#27ef70");
} else if (isGameProxyPro(gameData.uid)) {
$(".creatorAccountName").css("color", "#b3c20f");
}
refreshCreatorPpic();
if (gameData.src != undefined && gameData.src.endsWith(".swf")) {
if (getURLParameter("xrun") == "true") {
$("#gameFrame").html(`
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%">
<param name="movie" value="` + xrunProxy + gameData.src.replace(/http:\/\//g, "https://").replace(/"/g, "") + `" />
<param name="base" value />
<param name="quality" value="high" />
<param name="scale" value="default" />
<param name="wmode" value="direct" />
<embed src="` + gameData.src.replace(/http:\/\//g, "https://").replace(/"/g, "") + `" quality="high" type="application/x-shockwave-flash" width="100%" height="100%" scale="default" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<div class="right">
<button onclick="switchToCrossRun(false);" class="secondary"><i class="material-icons button">offline_bolt</i> Disable CrossRun</button>
<span class="balloonTarget">
<div class="balloon xrun">
<h2>Introducing CrossRun</h2>
<p>We've made CrossRun, a new service that lets you effortlessly play any GameProxy game anywhere without blockages.</p>
<div class="balloonButtons">
<button onclick="switchToCrossRun(true);" class="highlight">Try it!</button>
<button onclick="hideCrossRunBalloon();" class="secondary">Later</button>
</div>
</div>
</span>
<button aria-label="Go fullscreen" title="Go fullscreen" onclick="fullscreen(true);" class="secondary"><i class="material-icons button">fullscreen</i> <span class="desktop">Fullscreen</span></button>
</div>
`);
} else {
$("#gameFrame").html(`
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%">
<param name="movie" value="` + gameData.src.replace(/http:\/\//g, "https://").replace(/"/g, "") + `" />
<param name="base" value />
<param name="quality" value="high" />
<param name="scale" value="default" />
<param name="wmode" value="direct" />
<embed src="` + gameData.src.replace(/http:\/\//g, "https://").replace(/"/g, "") + `" quality="high" type="application/x-shockwave-flash" width="100%" height="100%" scale="default" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<div class="right">
<button onclick="switchToCrossRun(true);" class="secondary"><i class="material-icons button">flash_on</i> Activate CrossRun</button>
<span class="balloonTarget">
<div class="balloon xrun">
<h2>Introducing CrossRun</h2>
<p>We've made CrossRun, a new service that lets you effortlessly play any GameProxy game anywhere without blockages.</p>
<div class="balloonButtons">
<button onclick="switchToCrossRun(true);" class="highlight">Try it!</button>
<button onclick="hideCrossRunBalloon();" class="secondary">Later</button>
</div>
</div>
</span>
<button aria-label="Go fullscreen" title="Go fullscreen" onclick="fullscreen(true);" class="secondary"><i class="material-icons button">fullscreen</i> <span class="desktop">Fullscreen</span></button>
</div>
`);
}
} else if (gameData.src != undefined && gameData.src.startsWith("https://scratch.mit.edu/projects/")) {
if (getURLParameter("xrun") == "true") {
$("#gameFrame").html(`
<iframe src="` + xrunProxy + `https://scratch.mit.edu/projects/embed/` + gameData.src.split("/")[4] + `&turbo=false&full-screen=true&aspect-x=4&aspect-y=3&resolution-x=&resolution-y=" id="gameIframe"></iframe>
<div class="right">
<button onclick="switchToCrossRun(false);" class="secondary"><i class="material-icons button">offline_bolt</i> Disable CrossRun</button>
<button aria-label="Go fullscreen" title="Go fullscreen" onclick="fullscreen(true);" class="secondary floatRight"><i class="material-icons button">fullscreen</i> <span class="desktop">Fullscreen</span></button>
</div>
`);
} else {
$("#gameFrame").html(`
<iframe src="https://scratch.mit.edu/projects/embed/` + gameData.src.split("/")[4] + `" id="gameIframe"></iframe>
<div class="right">
<button onclick="switchToCrossRun(true);" class="secondary"><i class="material-icons button">flash_on</i> Activate CrossRun</button>
<span class="balloonTarget">
<div class="balloon xrun">
<h2>Introducing CrossRun</h2>
<p>We've made CrossRun, a new service that lets you effortlessly play any GameProxy game anywhere without blockages.</p>
<div class="balloonButtons">
<button onclick="switchToCrossRun(true);" class="highlight">Try it!</button>
<button onclick="hideCrossRunBalloon();" class="secondary">Later</button>
</div>
</div>
</span>
<button aria-label="Go fullscreen" title="Go fullscreen" onclick="fullscreen(true);" class="secondary floatRight"><i class="material-icons button">fullscreen</i> <span class="desktop">Fullscreen</span></button>
</div>
`);
}
} else {
if (getURLParameter("xrun") == "true") {
$("#gameFrame").html(`
<iframe src="` + xrunProxy + gameData.src.replace(/"/g, "") + `" id="gameIframe"></iframe>
<div class="right">
<button onclick="switchToCrossRun(false);" class="secondary"><i class="material-icons button">offline_bolt</i> Disable CrossRun</button>
<button aria-label="Go fullscreen" title="Go fullscreen" onclick="fullscreen(true);" class="secondary"><i class="material-icons button">fullscreen</i> <span class="desktop">Fullscreen</span></button>
</div>
`);
} else {
$("#gameFrame").html(`
<iframe src="` + gameData.src.replace(/"/g, "") + `" id="gameIframe"></iframe>
<div class="right">
<button onclick="switchToCrossRun(true);" class="secondary">
<i class="material-icons button">flash_on</i>
Activate CrossRun
</button>
<span class="balloonTarget">
<div class="balloon xrun">
<h2>Introducing CrossRun</h2>
<p>We've made CrossRun, a new service that lets you effortlessly play any GameProxy game anywhere without blockages.</p>
<div class="balloonButtons">
<button onclick="switchToCrossRun(true);" class="highlight">Try it!</button>
<button onclick="hideCrossRunBalloon();" class="secondary">Later</button>
</div>
</div>
</span>
<button aria-label="Go fullscreen" title="Go fullscreen" onclick="fullscreen(true);" class="secondary"><i class="material-icons button">fullscreen</i> <span class="desktop">Fullscreen</span></button>
</div>
`);
}
}
if (gameData.verified) {
$(".gameVerified").show();
$(".verifyButton").removeClass("secondary").addClass("highlight");
$(".verifyButton").html("<i class='material-icons button'>verified_user</i> Verified");
}
if (gameData.uid == currentUid) {
$(".editGameInfo").show();
}
setInterval(function() {
$("#gameLoader").hide();
$("#gameFrame").show();
}, 2000);
var consensusPart = Math.floor(Math.random() * 2);
if (consensusPart == 0) {
if (gameData.metrics.likes > 0) {
// Check if likesProof has been altered (use real user accounts)!
for (var i = 0; i < gameData.metrics.likesProof.length; i++) {
(function(currentInspection, likesProofIteration) {
firebase.database().ref("users/" + currentInspection.replace(/[.#$\[\]/]/g, "") + "/_settings/name").once("value", function(snapshot) {
if (!snapshot.exists()) {
firebase.database().ref("games/" + getURLParameter("play") + "/metrics/likesProof/" + likesProofIteration).remove();
}
});
})(gameData.metrics.likesProof[i], i);
}
}
} else {
firebase.database().ref("games/" + getURLParameter("play") + "/metrics/likesProof").once("value", function(snapshot) {
var likesProofList = snapshot.val();
var likesProofFinal = [];
// Reorder the likes proof list
for (var key in likesProofList) {
if ($.inArray(likesProofList[key], likesProofFinal) == -1) {
likesProofFinal.push(likesProofList[key]);
}
}
firebase.database().ref("games/" + getURLParameter("play") + "/metrics/likesProof").set(likesProofFinal);
});
}
});
firebase.database().ref("games/" + getURLParameter("play") + "/verified").on("value", function(snapshot) {
if (!!snapshot.val()) {
$(".gameVerified").show();
$(".verifyButton").removeClass("secondary").addClass("highlight");
$(".verifyButton").html("<i class='material-icons button'>verified_user</i> Verified");
} else {
$(".gameVerified").hide();
$(".verifyButton").removeClass("highlight").addClass("secondary");
$(".verifyButton").html("<i class='material-icons button'>verified_user</i> Verify");
}
gameData.verified = !!snapshot.val();
});
firebase.database().ref("games/" + getURLParameter("play") + "/metrics").on("value", function(snapshot) {
var likesData = snapshot.val();
if (likesData.likesProof === undefined) {
likesData.likesProof = [];
}
$(".gameLikes").text(likesData.likes);
if (likesData.likesProof.indexOf(currentUid) > -1) {
$("#likeGameButton").removeClass("secondary").addClass("highlight");
} else {
$("#likeGameButton").removeClass("highlight").addClass("secondary");
}
// Like verification to see if no-one's hacking!
firebase.database().ref("games/" + getURLParameter("play") + "/metrics/likes").set(likesData.likesProof.length);
});
firebase.database().ref("games/" + getURLParameter("play") + "/comments").on("value", function(snapshot) {
$("#commentsList").html("");
snapshot.forEach(function(childSnapshot) {
try {
if (childSnapshot.val().byStaff) {
$("#commentsList").html(`
<div class="comment">
<a href="profile?user=` + childSnapshot.val().uid + `" class="hidden"><strong style="color: #27ef70;" class="floatLeft">` + profanity.clean(childSnapshot.val().by.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">")) + `</strong></a> <span class="commentDate">` + profanity.clean(childSnapshot.val().dateAdded.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&")) + `</span>
<p class="commentContent"></p>
</div>
` + $("#commentsList").html());
} else if (isGameProxyPro(childSnapshot.val().uid)) {
$("#commentsList").html(`
<div class="comment">
<a href="profile?user=` + childSnapshot.val().uid + `" class="hidden"><strong style="color: #b3c20f;" class="floatLeft">` + profanity.clean(childSnapshot.val().by.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">")) + `</strong></a> <span class="commentDate">` + profanity.clean(childSnapshot.val().dateAdded.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&")) + `</span>
<p class="commentContent"></p>
</div>
` + $("#commentsList").html());
} else {
$("#commentsList").html(`
<div class="comment">
<a href="profile?user=` + childSnapshot.val().uid + `" class="hidden"><strong class="floatLeft">` + profanity.clean(childSnapshot.val().by.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">")) + `</strong></a> <span class="commentDate">` + profanity.clean(childSnapshot.val().dateAdded.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&")) + `</span>
<p class="commentContent"></p>
</div>
` + $("#commentsList").html());
}
$(".commentContent").first().text(profanity.clean(childSnapshot.val().content).length < 200 ? profanity.clean(childSnapshot.val().content) : profanity.clean(childSnapshot.val().content).substring(0, 200) + "...");
} catch (e) {}
});
});
// if (getURLParameter("play") == "-LRvXQAh67wwS_OCOiE1") {
// $.ajax({
// url: "https://ipapi.co/json/",
// success: function(data) {
// if (data.ip == "194.74.169.202") {
// // dialog("Smash Flash Knockout Tournament", `
// // <div class="center">
// // <img src="media/SFK.png" height="100" />
// // <h1>Are YOU from Norwich School?</h1>
// // <p>
// // We're hoping to organise a <strong>Smash Flash Knockout</strong> tournament at Norwich School.<br>
// // While it is totally not official, we're just seeing if you're interested, which we're sure you are.
// // </p>
// // <div>
// // So if you're a Norwich School pupil and wish to show us your interest, visit:<br>
// // <a href="/sfk/interest/" target="_blank">gameproxy.host/sfk/interest</a>
// // </div><br>
// // <div>
// // <small>
// // GameProxy is not sponsored, endorsed or otherwise affiliated with McLeodGaming Inc., Norwich School,
// // Cadbury or any of the charities that GameProxy is donating to. Competition Rules apply.
// // </small>
// // </div>
// // </div>
// // `, [
// // {text: "Later", onclick: "closeDialog();", type: "bad"},
// // {text: "Register Interest!", onclick: "window.open("/sfk/interest/"); closeDialog();", type: "primary"}
// // ]);
// dialog("Smash Flash Knockout Tournament", `
// <div class="center">
// <h1 class="noMargin">SMASH FLASH KNOCKOUT</h1>
// <h4 class="noMargin">FRIDAY 17TH MAY | FIT | 1:10 PM | FREE IF PAID FOR ALREADY</h4>
// <img src="media/SFK.png" height="75" />
// <p>
// Due to unforseeable problems with the Norwich School network on Friday 10th May, the Smash Flash Knockout
// competition has been moved to Friday 17th May. If you have paid to enter or spectate, you will be able to
// go again for free on the 17th. Please note that due to the large number of competitors who came on the
// 10th, new competitors will not be able to enter. Prizes will be given out on the 17th, along with the
// participation prizes!
// <p><br>
// <div>
// <small>
// GameProxy is not sponsored, endorsed or otherwise affiliated with McLeodGaming Inc., Norwich School,
// Cadbury or any of the charities that GameProxy is donating to. Competition Rules apply.
// </small>
// </div>
// </div>
// `, [
// {text: "Later", onclick: "closeDialog();", type: "bad"},
// {text: "Learn More", onclick: "window.open("/sfk"); closeDialog();", type: "primary"}
// ]);
// }
// }
// });
// }
if (localStorage.getItem("hideXrunBalloon") == "true") {
setInterval(function() {
hideCrossRunBalloon();
});
}
setTimeout(function() {
hideCrossRunBalloon(false);
}, 10000);
});
$("#commentBox").keypress(function(e) {
if ((event.keyCode ? event.keyCode : event.which) == 13) {
e.preventDefault();
postComment();
}
});
function joinGameSessionAction() {
$("#gameIframe").src($(".joinGameSession").val());
}
function joinGameSession() {
dialog(
"Join a Group Game",
`
<div class="center">
<p>Just enter the URL from the game below.</p>
<input class="joinGameSession fullWidth"><button onclick="joinGameSessionAction(); closeDialog();">Join</button>
</div>
`
);
}
window.onbeforeunload = function () {
return "Do you really want to leave this game? Your progress may be lost!";
}