-
Notifications
You must be signed in to change notification settings - Fork 0
/
PokeRater.html
562 lines (481 loc) · 14.4 KB
/
PokeRater.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>PokeRater</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://kit.fontawesome.com/c4d1cd3624.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- <link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.css" rel="stylesheet" -->
<!-- type='text/css'> -->
<style>
.box {
font-size: 18px;
/* font-family: "Pokemon GB", Arial, sans-serif; */
border-radius: 2px;
padding: 16px;
width: 250px;
height: 48px;
line-height: 16px;
margin: auto;
background: white;
border: 1px solid white;
box-shadow: 0 1px 0 1px black,
inset 0 1px 0 1px black,
0 0 0 1px black,
inset 0 0 0 1px black;
text-align: left;
}
.box:hover {
background-color: gainsboro;
}
/* .box>i { */
#bouncing {
width: 0;
height: 0;
border: 5px solid transparent;
border-top-color: black;
margin-top: 23px;
float: right;
}
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
background-image: url("https://img.wallpapersafari.com/desktop/728/410/35/10/YAyj8S.png");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
flex-direction: column;
margin: 0px;
}
pokemon {
flex: 1;
height: 100%;
}
/* Style the header */
header {
background-color: rgba(0, 0, 0, 0.125);
padding: 0px 0px;
text-align: center;
font-size: 35px;
color: white;
/* background-image: url("https://wallup.net/wp-content/uploads/2017/11/17/301412-Pokemon-748x421.jpg"); */
}
h2 {
margin: 30px 30px;
}
#pk_name_title {
font-size: 48px;
padding: 0px 50px;
margin: 0px;
}
/* Container for flexboxes */
section {
display: -webkit-flex;
display: flex;
height: 100%;
}
/* Style the navigation menu */
nav {
height: 100%;
width: 0;
z-index: 1;
overflow-x: hidden;
/* overflow-y: hidden; */
transition: 0.2s;
padding-top: 60px;
background: rgba(0, 0, 0, 0.25);
}
/* Style the list inside the menu */
ol {
list-style-type: none;
overflow-y: hidden;
padding: 0;
}
li {
padding-left: 30px;
padding-top: 10px;
}
li,
li>p {
white-space: nowrap;
}
/* Style the content */
article {
/* -webkit-flex: 3;
-ms-flex: 3;
flex: 3; */
width: 100%;
/* background-color: #f1f1f1; */
padding: 10px;
}
/* .image, */
/* img { */
#sprites {
max-height: 300px;
height: 300px;
min-height: 300px;
width: auto;
background-color: rgba(0, 0, 0, 0.5);
/* min-height: 50%; */
}
.pk-click {
border: none;
background: none;
}
.pk-click:not(.grayout)>.fa-solid:hover {
color: grey;
}
#shChk {
display: none;
}
:checked+label>.fa-shuffle {
color: rgb(15, 189, 15);
}
:checked+label>.fa-shuffle:hover {
color: rgb(174, 249, 174);
}
/* unchecked */
.fa-shuffle:hover {
color: rgb(174, 249, 174);
}
.avg {
display: inline;
}
.rem {
display: inline;
}
.grayout {
opacity: 0.4;
/* Real browsers */
filter: alpha(opacity=60);
/* MSIE */
}
#submit {
height: 100%;
}
#title-font {
height: 100%;
}
/* #half-stars-example { */
/* use display:inline-flex to prevent whitespace issues. alternatively, you can put all the children of .rating-group on a single line */
.rating-group {
display: inline-flex;
background-color: rgba(0, 0, 0, 0.25);
padding-right: 10px;
}
/* make hover effect work properly in IE */
.rating__icon {
pointer-events: none;
}
/* hide radio inputs */
.rating__input {
position: absolute !important;
left: -9999px !important;
}
/* set icon padding and size */
.rating__label {
cursor: pointer;
/* if you change the left/right padding, update the margin-right property of .rating__label--half as well. */
padding: 0 0.1em;
font-size: 2rem;
}
/* add padding and positioning to half star labels */
.rating__label--half {
padding-right: 0;
margin-right: -0.6em;
z-index: 2;
}
/* set default star color */
.rating__icon--star {
color: orange;
}
/* set color of none icon when unchecked */
.rating__icon--none {
color: #eee;
}
/* if none icon is checked, make it red */
.rating__input--none:checked+.rating__label .rating__icon--none {
color: red;
}
/* if any input is checked, make its following siblings grey */
.rating__input:checked~.rating__label .rating__icon--star {
color: #ddd;
}
/* make all stars orange on rating group hover */
.rating-group:hover .rating__label .rating__icon--star,
.rating-group:hover .rating__label--half .rating__icon--star {
color: orange;
}
/* make hovered input's following siblings grey on hover */
.rating__input:hover~.rating__label .rating__icon--star,
.rating__input:hover~.rating__label--half .rating__icon--star {
color: #ddd;
}
/* make none icon grey on rating group hover */
.rating-group:hover .rating__input--none:not(:hover)+.rating__label .rating__icon--none {
color: #eee;
}
/* make none icon red on hover */
.rating__input--none:hover+.rating__label .rating__icon--none {
color: red;
}
/* } */
/* Responsive layout - makes the menu and the content (inside the section) sit on top of each other instead of next to each other */
@media (max-width: 800px) {
section {
-webkit-flex-direction: column;
flex-direction: column;
}
}
</style>
</head>
<body onload="setup()">
<!-- fixes firefox bug -->
<script>0</script>
<!-- -->
<header>
<h2 id="title"><img #id="title-font" src="/resources/PokeRater.png"></h2>
</header>
<pokemon>
<section>
<nav id="sidebar">
<ol>
<li #id="gen1">AVG: <p class="avg">xx</p>, REM: <p class="rem">yyy</p>
</li>
<li #id="gen2">AVG: <p class="avg">xx</p>, REM: <p class="rem">yyy</p>
</li>
<li #id="gen3">AVG: <p class="avg">xx</p>, REM: <p class="rem">yyy</p>
</li>
<li #id="gen4">AVG: <p class="avg">xx</p>, REM: <p class="rem">yyy</p>
</li>
<li #id="gen5">AVG: <p class="avg">xx</p>, REM: <p class="rem">yyy</p>
</li>
<li #id="gen6">AVG: <p class="avg">xx</p>, REM: <p class="rem">yyy</p>
</li>
<li #id="gen7">AVG: <p class="avg">xx</p>, REM: <p class="rem">yyy</p>
</li>
<li #id="gen8">AVG: <p class="avg">xx</p>, REM: <p class="rem">yyy</p>
</li>
</ol>
</nav>
<article id="main">
<button class="open_side pk-click" onclick="sideNav()">
<i id="side_nav_button" class="fa-solid fa-arrow-right-to-bracket fa-2x"></i>
</button>
<center>
<h1 id="pk_name_title">Ditto</h1>
<div class="image">
<img id="sprites" src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/132.png">
</div><br>
<button class="pk-click" onclick="setSource(-1)"> <i class="fa-solid fa-arrow-left fa-3x"
aria-hidden="true"></i></button>
<input class="shuffle" checked name="shuffle-check" id="shChk" value="checked" type="checkbox">
<label for="shChk"><i class="fa-solid fa-shuffle fa-2x"></i></label>
<button class="pk-click" id="undo" onclick="prevPokemon()"><i
class="fa-solid fa-angles-left fa-3x"></i></button>
<button class="pk-click" onclick="setSource(1)"><i class="fa-solid fa-arrow-right fa-3x"
aria-hidden="true"></i></button><br>
<!-- <br><br> -->
<!-- STARS -->
<div id="half-stars-example">
<div class="rating-group">
<input class="rating__input rating__input--none" checked name="rating2" id="rating2-0" value="0"
type="radio">
<label aria-label="0 stars" class="rating__label" for="rating2-0"> </label>
<label aria-label="0.5 stars" class="rating__label rating__label--half" for="rating2-05"><i
class="rating__icon rating__icon--star fa fa-star-half"></i></label>
<input class="rating__input" name="rating2" id="rating2-05" value="0.5" type="radio">
<label aria-label="1 star" class="rating__label" for="rating2-10"><i
class="rating__icon rating__icon--star fa fa-star"></i></label>
<input class="rating__input" name="rating2" id="rating2-10" value="1" type="radio">
<label aria-label="1.5 stars" class="rating__label rating__label--half" for="rating2-15"><i
class="rating__icon rating__icon--star fa fa-star-half"></i></label>
<input class="rating__input" name="rating2" id="rating2-15" value="1.5" type="radio">
<label aria-label="2 stars" class="rating__label" for="rating2-20"><i
class="rating__icon rating__icon--star fa fa-star"></i></label>
<input class="rating__input" name="rating2" id="rating2-20" value="2" type="radio">
<label aria-label="2.5 stars" class="rating__label rating__label--half" for="rating2-25"><i
class="rating__icon rating__icon--star fa fa-star-half"></i></label>
<input class="rating__input" name="rating2" id="rating2-25" value="2.5" type="radio" checked>
<label aria-label="3 stars" class="rating__label" for="rating2-30"><i
class="rating__icon rating__icon--star fa fa-star"></i></label>
<input class="rating__input" name="rating2" id="rating2-30" value="3" type="radio">
<label aria-label="3.5 stars" class="rating__label rating__label--half" for="rating2-35"><i
class="rating__icon rating__icon--star fa fa-star-half"></i></label>
<input class="rating__input" name="rating2" id="rating2-35" value="3.5" type="radio">
<label aria-label="4 stars" class="rating__label" for="rating2-40"><i
class="rating__icon rating__icon--star fa fa-star"></i></label>
<input class="rating__input" name="rating2" id="rating2-40" value="4" type="radio">
<label aria-label="4.5 stars" class="rating__label rating__label--half" for="rating2-45"><i
class="rating__icon rating__icon--star fa fa-star-half"></i></label>
<input class="rating__input" name="rating2" id="rating2-45" value="4.5" type="radio">
<label aria-label="5 stars" class="rating__label" for="rating2-50"><i
class="rating__icon rating__icon--star fa fa-star"></i></label>
<input class="rating__input" name="rating2" id="rating2-50" value="5" type="radio">
</div>
</div>
<br>
<div class="box" onclick="submit()"><img id="submit" src="/resources/submit.png"><i id="bouncing"></i></div>
</div>
</center>
</article>
</section>
</pokemon>
</body>
<script>
currID = null;
prevID = null;
currIMG = 0;
imageLinks = []
function setup() {
document.getElementById("shChk").checked = false;
document.getElementById("rating2-0").checked = true;
updateGrayOut();
getFirst();
document.onkeydown = function (event) {
switch (event.keyCode) {
case 37: //left
setSource(-1);
break;
case 39: //right
setSource(1)
break;
}
};
}
//actual mod since js only uses remainder
Number.prototype.mod = function (n) {
"use strict";
return ((this % n) + n) % n;
};
//sets the index for the current sprite
function setSource(shift) {
currIMG = (currIMG + shift).mod(imageLinks.length);
setSprite();
}
//sets the given link to display
function setSprite() {
document.getElementById("sprites").src = imageLinks[currIMG];
}
//sets the information for the generation on the page
function setGen(gen, avg, rem) {
cleaned_average = (Math.round(avg * 100) / 100).toFixed(2);
document.getElementsByClassName("avg")[Number(gen) - 1].innerHTML = String(cleaned_average);
document.getElementsByClassName("rem")[Number(gen) - 1].innerHTML = String(rem);
}
//goes back to the previous pokemon (in case accidentally hit wrong value)
function prevPokemon() {
//check if there is a previous pokemon
if (document.getElementById("undo").classList.contains("grayout")) {
return
}
//get prevID
fetch("/" + prevID).then((post) => {
console.log(post);
return post.json()
}).then((data) => {
currID = prevID;
prevID = null;
parsePokemon(data);
updateGrayOut();
})
}
// submits the form value
function submit() {
shuffle = document.getElementById("shChk").checked;
rating = getRating();
if (rating <= 0 || rating > 5) {
alert("Please enter a rating!")
return;
}
data = {
"name": currID,
"shuffle": shuffle,
"rating": rating
}
fetch("/", {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
})
getPokemon();
console.log("ending submit")
}
//gets the rating value
function getRating() {
radio = document.getElementsByName("rating2")
for (i = 0; i < radio.length; i++) {
if (radio[i].checked) {
return radio[i].value;
}
}
}
function getPokemon() {
shuffle = document.getElementById("shChk").checked;
console.log("get random");
if (shuffle) {
url = "/rand"
} else {
url = "/seq?" + currID
}
fetch(url).then((post) => {
console.log(post)
return post.json()
}).then((data) => {
prevID = currID;
parsePokemon(data);
updateGrayOut();
})
}
function getFirst(name) {
shuffle = document.getElementById("shChk").checked;
console.log("get sequential");
fetch("/first").then((post) => {
console.log(post)
return post.json()
}).then((data) => {
prevID = currID;
parsePokemon(data);
updateGrayOut();
})
}
function parsePokemon(pokemon) {
//DEBUG: remove below
// console.log(currID)
console.log(pokemon)
document.getElementById("rating2-0").checked = true;
currID = pokemon.name;
imageLinks = pokemon.urls;
setSource(0);
document.getElementById("pk_name_title").innerHTML = pokemon.name.toUpperCase();
pokemon.gens.forEach(element => {
setGen(element[0], element[1], element[2])
});
}
function updateGrayOut() {
if (prevID == null) {
document.getElementById("undo").classList.add("grayout");
} else {
document.getElementById("undo").classList.remove("grayout");
}
}
function sideNav() {
sideNavButton = document.getElementById("side_nav_button");
if (sideNavButton.classList.contains("fa-flip-horizontal")) {
sideNavButton.classList.remove("fa-flip-horizontal");
document.getElementById("sidebar").style.width = "0";
} else {
sideNavButton.classList.add("fa-flip-horizontal");
document.getElementById("sidebar").style.width = "300px";
}
}
</script>
</html>