-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·428 lines (378 loc) · 14.3 KB
/
index.html
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
<head>
<meta name="description" content="PET THE FROG! FRONGAS HAVIG A APPARTY">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>FRONG PARTY</title>
<style>
html * {
font-family: "Comic Sans MS", "Comic Sans", Arial, Roboto, auto;
animation: none;
cursor: url('hande.png'), auto;
}
body {
background-image: url('grass.jpg');
background-repeat: no-repeat;
background-size: cover;
overflow: hidden;
}
h1, label, li {
font-weight: 800;
color: white;
}
label ~ input { margin-left: 5px;}
#score {
text-align: center;
}
#scores-container {
text-align: center;
position: absolute; bottom: 10px; width: 100vw;
}
#start {
color: white;
font-size: 3rem;
position: absolute;
}
#frong {
display: block;
position: absolute;
top: 40%;
left: 50%;
margin-left: calc(-152px/2);
width: 152px;
height: 111px;
background-size: contain;
background-repeat: no-repeat;
background-image: url(frong.jpg);
background-color: white;
box-shadow: none;
}
#leaderboard{
text-align: center;
list-style: decimal;
}
.me_irl {
background-color: rgba(100, 255, 255, 0.5);
}
.hidden{display:none !important;}
.unselectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@keyframes wiggle {
0% { transform: rotate(0deg); }
20% { transform: rotate(5deg); }
80% { transform: rotate(-5deg); }
100% { transform: rotate(0deg); }
}
.wiggle {
animation-name: wiggle;
animation-duration: .1s;
animation-delay: 0;
animation-iteration-count: infinite;
}
.wiggle-once {
animation-name: wiggle;
animation-duration: .1s;
animation-delay: 0;
animation-iteration-count: 1;
}
.anim-speed-10 { animation-duration: .1s !important; }
.anim-speed-9 { animation-duration: .15s !important; }
.anim-speed-8 { animation-duration: .2s !important; }
.anim-speed-7 { animation-duration: .25s !important; }
.anim-speed-6 { animation-duration: .3s !important; }
.anim-speed-5 { animation-duration: .35s !important; }
.anim-speed-4 { animation-duration: .4s !important; }
.anim-speed-3 { animation-duration: .45s !important; }
.anim-speed-2 { animation-duration: .5s !important; }
.anim-speed-1 { animation-duration: .55s !important; }
</style>
<script type='text/javascript'>
/* __ .__ __ .__.__ .__ __ .__ __
_______/ |_ ___.__.| | ____ __ ___/ |_|__| | |__|/ |_ ___.__. ______ ___________|__|______/ |_ ______
/ ___/\ __< | || | _/ __ \ | | \ __\ | | | \ __< | | / ___// ___\_ __ \ \____ \ __\/ ___/
\___ \ | | \___ || |_\ ___/ | | /| | | | |_| || | \___ | \___ \\ \___| | \/ | |_> > | \___ \
/____ > |__| / ____||____/\___ > |____/ |__| |__|____/__||__| / ____| /____ >\___ >__| |__| __/|__| /____ >
\/ \/ \/ \/ \/ \/ |__| \/
*/
function WiggleOnce(elem) {
elem.classList.add('wiggle-once');
setTimeout(function(){
elem.classList.remove('wiggle-once');
}, 100);
}
// frong is READY ... undoot hims invisibility cloak
function ToggleVisibility(selector) {
var selected = document.querySelectorAll(selector);
if (selected) {
selected.forEach( function(e){
if (e.classList.contains('hidden'))
e.classList.remove('hidden');
else e.classList.add('hidden');
});
}
}
function Hide(selector) {
selected = document.querySelectorAll(selector);
if (selected) {
selected.forEach( function(el) {
el.classList.add('hidden');
});
}
}
function Show(selector) {
selected = document.querySelectorAll(selector);
if (selected) {
selected.forEach( function(el) {
el.classList.remove('hidden');
});
}
}
</script>
<script type='text/javascript'>
/* __ .__.__ .__ __ .__ __
__ ___/ |_|__| | |__|/ |_ ___.__. ______ ___________|__|______/ |_ ______
| | \ __\ | | | \ __< | | / ___// ___\_ __ \ \____ \ __\/ ___/
| | /| | | | |_| || | \___ | \___ \\ \___| | \/ | |_> > | \___ \
|____/ |__| |__|____/__||__| / ____| /____ >\___ >__| |__| __/|__| /____ >
\/ \/ \/ |__| \/ */
GameStorage = {
fallbackToCookieStorage: false,
init: function() {
try {
localStorage.setItem('test', 1);
} catch(err) {
console.error('frong memory kinda bade doe :///// COOKIE TIEM');
this.fallbackToCookieStorage = true;
}
},
set: function(key, val) {
if (!this.fallbackToCookieStorage) return localStorage.setItem(key, val);
else return this._cookieSet(key, val);
},
get: function(key) {
if (!this.fallbackToCookieStorage) return localStorage.getItem(key);
else return this._cookieGet(key);
},
_cookieSet: function(key, val) {
document.cookie = key+'='+val+';expires=Fri, 15 May 9999 23:59:59 GMT';
},
_cookieGet: function(key){
var captureCookieValue = new RegExp('(?:(?:^|.*;\\s*)'+key+'\\s*\\=\\s*([^;]*).*$)|^.*$');
return document.cookie.replace(captureCookieValue, "$1");
},
};
IsDev = window.location.href.indexOf('.localhost') > -1;
// SLOW THE HEMK DOWN FRONGO
const Throttle = (func, limit) => {
let lastFunc
let lastRan
return function() {
const context = this
const args = arguments
if (!lastRan) {
func.apply(context, args)
lastRan = Date.now()
} else {
clearTimeout(lastFunc)
lastFunc = setTimeout(function() {
if ((Date.now() - lastRan) >= limit) {
func.apply(context, args)
lastRan = Date.now()
}
}, limit - (Date.now() - lastRan))
}
}
}
</script>
<script type='text/javascript'>
/*_ _ _ _ _____ _____
| | | | | | | | /\ | __ \_ _|
| | ___ __ _ __| | ___ _ __| |__ ___ __ _ _ __ __| | / \ | |__) || |
| | / _ \/ _` |/ _` |/ _ \ '__| '_ \ / _ \ / _` | '__/ _` | / /\ \ | ___/ | |
| |___| __/ (_| | (_| | __/ | | |_) | (_) | (_| | | | (_| | / ____ \| | _| |_
|______\___|\__,_|\__,_|\___|_| |_.__/ \___/ \__,_|_| \__,_| /_/ \_\_| |_____|*/
Leaderboard = {
endpoint: 'http://'+window.location.hostname+'/v1/leaderboard',
// (hi, Im frong!) < (hi, frong, I'm leaderboard!)
hello: function(urName, initComplete) {
// name doesnt actually matter after init, its just an alias for the uuid the API will gen for you
this._leaderboardReq( 'POST', {'name': urName},
function(xhr){
try {
initComplete(true);
} catch (e) {
initComplete(false);
}
},
function(xhr){
console.error("Leaderboard ain't too social today :(");
initComplete(false);
}
);
},
// (leaderboard, I just scored!) < (oke duely noted, fromgas)
score: function(points) {
this._leaderboardReq( "PATCH", {'score': points},
null, // if the request was successful there's nothing left to do!
function(xhr){
console.error('Themse other frong petters must have dems airpods in :(');
}
);
},
// (leaderboard, how u doin?) < (ok, smoothbrain)
refresh: function( tellMeAboutTheLeaderboard ) {
var leaderboard = null;
this._leaderboardReq( "GET", {},
function(xhr) {
// abstract-out the xhr request and provide a clean leaderboard datastructure to the handler
leaderboard = JSON.parse(xhr.responseText);
tellMeAboutTheLeaderboard( leaderboard );
},
function(xhr) {
console.error("Frong petters always say YEE HAW, but now I'm asking HAW YEE? :(");
tellMeAboutTheLeaderboard( null ); // not sure about this yet
}
);
},
_leaderboardReq: function(method, body, onsuccess, onerror) {
const xhr = new XMLHttpRequest();
xhr.open(method, this.endpoint, true);
xhr.onreadystatechange = function(){
if (xhr.readyState === XMLHttpRequest.DONE) {
var status = xhr.status;
if (status >= 200 && status < 400) {
if (typeof onsuccess === 'function') {onsuccess(xhr);}
}
else if (typeof onerror === 'function') {onerror(xhr);}
}
}
xhr.send(JSON.stringify(body));
return
},
_getContext: function(){ return this }
}
</script>
</head>
<body>
<audio id='hit1' autostart="false"><source src='hit1.wav'></audio>
<audio id='hit2' autostart="false"><source src='hit2.wav'></audio>
<audio id='hit3' autostart="false"><source src='hit3.wav'></audio>
<audio id='appear' autostart="false"><source src='appear.mp3'></audio>
<h1 id='score' class='toggleVisibilityOnLoad hidden unselectable'>PET THE FRONG <br> YOUR SCORE: <span id='score-num'>0</span></h1>
<a id='frong' class='toggleVisibilityOnLoad hidden anim-speed-10'></a>
<div id=scores-container class='toggleVisibilityOnLoad hidden'>
<h1 id='highscore'>UR BESTEST: <span id='highscore-num'>0</span></h1>
<hr>
<ul id='leaderboard' class='hidden'>
<li>Kermit: 0</li>
<li>Kermit: 0</li>
<li>Kermit: 0</li>
<li>Kermit: 0</li>
<li>Kermit: 0</li>
<li>Kermit: 0</li>
<li>Kermit: 0</li>
</ul>
<h1 id='leaderboard-offline'>I ain't vibin wiff other frongs rn :c</h1>
</div>
<!--- _____ __ __
\_ |__ _____/ ____\___________ ____ _______/ |______ ________/ |_
| __ \_/ __ \ __\/ _ \_ __ \_/ __ \ / ___/\ __\__ \\_ __ \ __\
| \_\ \ ___/| | ( <_> ) | \/\ ___/ \___ \ | | / __ \| | \/| |
|___ /\___ >__| \____/|__| \___ > /____ > |__| (____ /__| |__|
\/ \/ \/ \/ \/ -->
<label for='urName' class='toggleVisibilityOnLoad'>gibe ur name pls...</label>
<input type='text' id='urName' class='toggleVisibilityOnLoad' placeholder='kremit' maxlength=16>
<h1 id='start' class='toggleVisibilityOnLoad wiggle'>START</h1>
</body>
<footer>
<script type='text/javascript'>
function main() {
GameStorage.init();
var urNameElem = document.getElementById('urName');
urNameElem.focus();
var startbtn = document.getElementById('start');
startbtn.addEventListener('click', function(e){
var urName = urNameElem.value;
Leaderboard.hello(urName, function(onlineEnabled){start(onlineEnabled)});
});
}
function start(online) {
// DOM elements (frongas of the web, ONE MIGHT SAY. ACTUALLY I DO SAY!)
var frong = document.getElementById('frong');
var songe = document.getElementById('songe');
var appear = document.getElementById('appear');
var hits = document.querySelectorAll('audio[id^="hit"]'); // get all elems with id's beginning with "hit"
// petting points
var scoreContainerElem = document.getElementById('score');
var scoreElem = document.getElementById('score-num');
var highscoreContainerElem = document.getElementById('highscore');
var highscoreElem = document.getElementById('highscore-num');
var score = 0;
var highscore = GameStorage.get('highscore') || 0;
highscoreElem.innerHTML = highscore;
function _setScore(score){
if (score > highscore) {
highscore = score;
WiggleOnce(highscoreContainerElem);
}
scoreElem.innerHTML = score;
highscoreElem.innerHTML = highscore;
GameStorage.set('highscore', highscore);
}
function increaseScore() {
var points = (Math.floor( Math.random() * 80 ) + 20);
score += points;
WiggleOnce(scoreContainerElem);
if (online) Leaderboard.score(points);
_setScore(score)
}
/* if i pet a fronge in the woods and no one is
around to see it, did I really pete fromge? */
var increaseScoreTentatively = Throttle(increaseScore, 15);
frong.addEventListener( 'mousedown', function(e) {
var randNum = Math.floor(Math.random() * 3);
hits[randNum].play();
WiggleOnce(frong);
increaseScoreTentatively();
});
// leaderboard
var leaderboardUL = document.getElementById('leaderboard');
var leaderboardObj = { 'name':"cremit", 'score':0, 'isMe':false };
var updateLeaderboard = function(){
Leaderboard.refresh(function(leaderboard){
if (leaderboard && leaderboard['rankings']) {
Show('#leaderboard');
Hide('#leaderboard-offline');
var rankings = leaderboard['rankings'];
var i = 0;
var listItems = leaderboardUL.querySelectorAll('li');
for(i=0; i < listItems.length; i++){
listItems[i].innerHTML = (rankings[i])['name']+": "+(rankings[i])['score'];
listItems[i].classList.remove('me_irl');
}
if (leaderboard['you'] >= 0 && listItems[ leaderboard['you'] ]) {
listItems[ leaderboard['you'] ].classList.add('me_irl');
}
}
else {
// swap leaderboard to offline version, *dont* go offline though
Show('#leaderboard-offline');
Hide('#leaderboard');
}
});
}
if (online) {
updateLeaderboard();
// keep 'er synced
setInterval(updateLeaderboard, 3000);
}
ToggleVisibility('.toggleVisibilityOnLoad');
appear.play();
}
main();
</script>
</footer>