-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
2204 lines (2038 loc) · 117 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
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
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en-US" class="dark">
<head>
<!-- GA4 Tag --><script async src="https://www.googletagmanager.com/gtag/js?id=G-LQY2YVNT21"></script><script>window.dataLayer=window.dataLayer || []; function gtag(){dataLayer.push(arguments);}gtag('js', new Date()); gtag('config', 'G-LQY2YVNT21');</script>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-TDF58VB');</script>
<!-- End Google Tag Manager -->
<meta charset="UTF-8">
<link rel="canonical" href="https://pvpivs.com/" />
<!-- Include pre-loads to reduce/optimize page load time-->
<link rel="preload" href="https://pvpivs.com/includes/style.css" as="style">
<link rel="preload" href="https://pvpivs.com/includes/darkLightThemes.js" as="script">
<link rel="preload" href="https://pvpivs.com/includes/collapsible.js" as="script">
<link rel="preload" href="https://pvpivs.com/includes/calculate.js" as="script">
<link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/awesomplete/1.1.5/awesomplete.min.css" as="style">
<link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/awesomplete/1.1.5/awesomplete.min.js" as="script">
<link rel="preload" href="https://pvpivs.com/includes/pokeListObj.js" as="script">
<title>PvP IVs - Rankings</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="PvP IVs lookup tool for Pokémon Go™ to help compare your Pokémon's PvP IVs to ideal PvP IVs. Finds PvP IVs for any wild-caught, weather boosted, traded, raided, hatched, and even purified Pokémon! Did you catch the very best?"/>
<link rel="icon"
type="image/png"
href="https://pvpivs.com/includes/favicon.png">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/awesomplete/1.1.5/awesomplete.min.css">
<link rel="stylesheet" href="https://pvpivs.com/includes/style.css">
<style>
/* control highlight of trading improvement rows based on % chace to improve post-trade
* also controls the output row highlighting for user entered IVs (#outTable)
* 1000/4096 ~= 0.2442 and 100/4096 ~= 0.02442
* use 0.02442 to approximate "Top 100" (green) when there are less than 4096 results
* use 0.2442 to approximate "Top 1000" (orange) when there are less than 4096 results */
#outTable tr.good > *, #familyTable tr.good > *, #tradeTable tr.highMaxRow > * {background-color: var(--goodResult); color: var(--navActiveText);}
#outTable tr.ok > *, #familyTable tr.ok > *, #tradeTable tr.okMaxRow > * {background-color: var(--okResult); color: var(--navActiveText);}
#outTable tr.rubbish > *, #familyTable tr.rubbish > *, #tradeTable tr.lowMaxRow > * {background-color: var(--badResult); color: var(--navActiveText);}
/* the > * operator applies the css to all children (cells) */
#outTable, #familyTable a {
color: var(--navActiveText);
}
input[type=number] {
width: 44px;
}
input[id=pokeList] {
width: 111px;
}
/* Plus/Minus Buttons */
/* https://stackoverflow.com/q/33766350 */
.circle {
border: 1px solid var(--navBackground);
box-shadow: inset 1px 1px 1px var(--tableDividers);
width: 18px;
height: 18px;
border-radius: 100%;
position: relative;
margin: 4px;
display: inline-block;
vertical-align: middle;
background: #aaaaaa4f;
}
.circle:hover{
background: radial-gradient(var(--textBoxBg), var(--tableHeaderBg));
}
.circle:active{
background: var(--navActive);
}
.circle:before,.circle:after{
content:'';position:absolute;top:0;left:0;right:0;bottom:0;
}
/* PLUS */
.circle.plus:before,.circle.plus:after {
background:green;
}
.circle.plus:before{
width: 2px;
margin: 3px auto;
}
.circle.plus:after{
margin: auto 3px;
height: 2px;
}
/* MINUS */
.circle.minus:before{
background: #cc0000;
margin: auto 3px;
height: 2px;
}
#totalRanks {
display: inline;
}
p[id=IVinputShow], small[id=IVinputHide] {
text-decoration: underline;
text-decoration-color: blue;
}
</style>
<!-- Begin Playwire Head -->
<script>window.ramp=window.ramp ||{}; window.ramp.que=window.ramp.que || []; </script> <script async src="//cdn.intergient.com/1025030/74482/ramp_config.js"></script> <script>window._pwGA4PageviewId=''.concat(Date.now()); window.dataLayer=window.dataLayer || []; window.gtag=window.gtag || function (){dataLayer.push(arguments);}; gtag('js', new Date()); gtag('config', 'G-JD7R9RWFZL',{'send_page_view': false}); gtag( 'event', 'ramp_js',{'send_to': 'G-JD7R9RWFZL', 'pageview_id': window._pwGA4PageviewId}); </script>
<!-- End Playwire Head -->
</head>
<body onload="checkURI()">
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-TDF58VB"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<header>
<ul class="header">
<li class="dropdown active left">
<a href="javascript:void(0)" class="dropbtn active">PvP IVs</a>
<div class="dropdown-content">
<a href="/" class="active">Rankings (Single)</a>
<a href="/indexTest.html">Rankings (Beta)</a>
<a href="/leagueRanks.html">Rankings (League)</a>
<a href="/searchStr.html">Search Strings</a>
<a href="/calculator.html">Calculator</a>
</div>
</li>
<li class="dropdown left">
<a href="javascript:void(0)" class="dropbtn">Typing</a>
<div class="dropdown-content">
<a href="/typeLookup.html">Chart</a>
<a href="/typeQuiz.html">Quiz</a>
</div>
</li>
<li class="flat right">
<div class="theme-toggle-div">
<img id="theme-toggle-icon" src="https://pvpivs.com/includes/sun.svg" aria-label="Change to light theme" alt="Sun icon" width="22" height="22">
</div>
</li>
<li class="dropdown right">
<a href="javascript:void(0)" class="dropburger"><div class="container"><div class="bar"></div><div class="bar"></div><div class="bar"></div></div></a>
<div class="dropdown-content dropdown-content-right">
<a href="/about.html">About PvP IVs</a>
<a href="/contribute.html">Contribute</a>
<a href="/contact.html">Contact Us</a>
<a href="/privacy.html">Privacy Policy</a>
<a href="/cookies.html">Cookie Policy</a>
</div>
</li>
</ul>
</header>
<br />
<section>
<label>Top <input type="number" value="10" id="limit" min="1" max="4096" oninput="setUserPreference('limit')"></label>
<label><select id="league" oninput="setUserPreference('league')">
<option value="500" label="Little Leagues">Little Leagues</option>
<option value="1500" selected label="Great League">Great League</option>
<option value="2500" label="Ultra League">Ultra League</option>
<option value="ML" label="Master League">Master League</option>
</select></label>
<input id="pokeList" onfocus="this.value=''" placeholder="Pokémon"/>
<span style="overflow-x:auto;" id="instructionsBox"><i><br />Please enter a valid Pokémon to continue...</i></span>
<br />
<table id="inputTable">
<tr><td><img src="https://www.pvpivs.com/includes/icon-shadow-purple.png" alt="Shadow" width="17" height="17"></td><td title="Your Attack IV">Atk</td><td title="Your Defense IV">Def</td><td title="Your Stamina IV">Sta</td><td id="plusCell"><button class="circle plus" onclick="doTheInsert()"></button></td></tr>
<tr>
<td><input class='shadowCB' id="shdw[0]" type="checkbox" oninput="shdwUpdater()"></td>
<td><select title="Your Attack IV" class="aIV" id="aIV[0]" onchange="main()">
<option value=""> </option>
<option value="15">15</option>
<option value="14">14</option>
<option value="13">13</option>
<option value="12">12</option>
<option value="11">11</option>
<option value="10">10</option>
<option value="9">9</option>
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
<option value="0">0</option>
</select></td>
<td><select title="Your Defense IV" class="dIV" id="dIV[0]" onchange="main()">
<option value="15">15</option>
<option value="14">14</option>
<option value="13">13</option>
<option value="12">12</option>
<option value="11">11</option>
<option value="10">10</option>
<option value="9">9</option>
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
<option value="0">0</option>
</select></td>
<td><select title="Your Stamina IV" class="sIV" id="sIV[0]" onchange="main()">
<option value="15">15</option>
<option value="14">14</option>
<option value="13">13</option>
<option value="12">12</option>
<option value="11">11</option>
<option value="10">10</option>
<option value="9">9</option>
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
<option value="0">0</option>
</select></td>
<td id="minusCell"><button class="circle minus" id="minus[0]" onclick="doTheRemoval()"></button></td>
</tr>
</table>
<p id="IVinputShow" onclick="showIVinput()"><i><small>Show IV input textbox</small></i></p>
<textarea id="ivInput" rows="4" cols="27" oninput="readIVs()" placeholder="/*Paste Your IVs here Atk IV Def IV Sta IV*/ 13	15	12 14	11	6" hidden></textarea><!--Atk IV Def IV Sta IV
13 15 12
14 11 6-->
<p onclick="hideIVinput()"><i><small id="IVinputHide" hidden>Hide IV input textbox</small></i></p>
<textarea id="CustomGroupExport" hidden></textarea>
<div style="overflow-x:auto;" id="megaNote"></div>
<div id="feedbackBox"><br /></div>
<div style="overflow-x:auto;" id="outputBox"></div>
<script async defer src="https://pvpivs.com/includes/darkLightThemes.js"></script>
<script async defer src="https://pvpivs.com/includes/collapsible.js"></script>
<script src="https://pvpivs.com/includes/calculate.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/awesomplete/1.1.5/awesomplete.min.js"></script>
<script src="https://pvpivs.com/includes/pokeListObj.js"></script>
<script>
var lastLeague;
var inputMon = "";
var perfTiming = false; /* used for timing execution */
var mnlMod = false; /*track if min Lvl was adjusted*/
var ivMod = false; /*track if IV floor was adjusted*/
let aIV=[document.getElementById('aIV[0]').value];
let dIV=[document.getElementById('dIV[0]').value];
let sIV=[document.getElementById('sIV[0]').value];
let shdw=[document.getElementById('shdw[0]').checked];
let rIV=[];
let lvl=[];
let mA = 0, mD = 0, mHP = 0; /*min stat filter vars*/
let filterMod = false; /*track if stat filters were adjusted*/
var input = document.getElementById("pokeList");
var monNames = Object.keys(pokeListObj);
/* Ensure we've successfully loaded pokeListObj, and converted to list for awesomplete */
if (monNames.length<1000) /* At time of writing, monNames.length was 1025 */
{
console.error("monNames.length ("+monNames.length+") shorter than expected (1000), check pokeListObj load");
document.getElementById('feedbackBox').innerHTML = "<p><i>ERROR: Failed to load, please try again.<br>If this issue persists, please <a href='https://discord.gg/UD4Temq'>contact us on Discord</i></p>";
console.log("pokeListObj: "+JSON.stringify(pokeListObj));
console.log("monNames: "+JSON.stringify(monNames));
} else {
new Awesomplete(input, {list: monNames});
/*https://github.com/LeaVerou/awesomplete/issues/16438#issuecomment-195921708*/
Awesomplete.$.bind(input, {
"awesomplete-selectcomplete": function(evt) {
/*console.log("User Selected "+evt.text.label+", passing to main and exiting Awesomplete");*/
if (evt.text.label.indexOf("_SPECULATIVE") > -1)
{
document.getElementById('megaNote').innerHTML = "<p><i>Please note these base stats are speculative and subject to change!</i></p>";
} else if (evt.text.label.indexOf("_PLACEHOLDER") > -1)
{
document.getElementById('megaNote').innerHTML = "<p><i>Please note these base stats are unknown and not yet in the Game Master!</i></p>";
} else {
document.getElementById('megaNote').innerHTML = ""; /* Clear the previous notes if any */
}
inputMon = evt.text.label;
main(evt.text.label);
}
});
/* end Awesomeplete https://leaverou.github.io/awesomplete/ */
}
function showIVinput() {
document.getElementById("IVinputShow").style.display = "none";
document.getElementById("ivInput").style.display = "inline-block";
document.getElementById("IVinputHide").style.display = "inline-block";
}
function hideIVinput() {
document.getElementById("IVinputShow").style.display = "inline-block";
document.getElementById("ivInput").style.display = "none";
document.getElementById("IVinputHide").style.display = "none";
document.getElementById("ivBox").checked = false;
}
function readIVs() {
var ivStr = document.getElementById("ivInput").value.split(/\r?\n/);
console.log("readIVs::IVs:ivStr:"+ivStr+", ivStr.length: "+ivStr.length);
/* Start by clearing all existing IV Input Rows */
for (var i=0; i<aIV.length; i++) {
/* magic to actually remove all the rows one by one */
var tr = document.getElementById('aIV['+i+']').parentNode;
tr.parentNode.parentNode.removeChild(tr.parentNode);
}
/* clear the value arrays */
aIV.splice(0, aIV.length);
dIV.splice(0, dIV.length);
sIV.splice(0, sIV.length);
shdw.splice(0, shdw.length);
for (var j=0; j<ivStr.length; j++)
{
if (!(/\d/.test(ivStr[j]))) { /* Ensure that we have IVs to process */
console.log("ivStr["+j+"]("+ivStr[j]+") has no numbers, skipping");
continue;
}
var userIVs = ivStr[j].match(/\d+/g);
if (userIVs.length<2) {continue;} /* skip blank/incomplete entries */
console.log("readIVs::IVs:insering userIVs: "+userIVs+" (length:"+userIVs.length+")");
doTheInsert(userIVs[0],userIVs[1],userIVs[2],userIVs[3]);
}
console.log("readIVs: IVs set to aIV:"+aIV+", dIV:"+dIV+", sIV:"+sIV+", shdw:"+shdw);
main();
}
function adjustFloors(pokeName) {
var T0;
if (perfTiming) {T0 = performance.now();}
/*check if we need to adjust IV Floor or Min Level*/
var minLvl = document.getElementById('minLvl');
var floor = document.getElementById('floor');
if (shadowLegend.includes(pokeName) && shdw.indexOf(true) > -1) {
console.log("adjustFloors: Detected Shadow Legendary:" +pokeName);
/*set min IVs to 10 and min Level to 20*/
if (minLvl.value/1 > 8) {
minLvl.value = 8;
mnlMod = true;
}
floor.value = 6;
ivMod = true;
if (perfTiming) {stopTiming(T0, "adjustFloors");}
return;
}
if (boxRewrd.includes(pokeName)) {
console.log("adjustFloors: Detected box reward mon:" +pokeName);
/*set min IVs to 1 and min Level to 15*/
if (minLvl.value/1 < 15) {
minLvl.value = 15;
mnlMod = true;
}
floor.value = 1;
ivMod = true;
if (perfTiming) {stopTiming(T0, "adjustFloors");}
return;
}
if (raidOnly.includes(pokeName)) {
console.log("adjustFloors: Detected Raid+Trade mon:" +pokeName);
/*set min IVs to 1 and min Level to 20*/
if (minLvl.value/1 < 20) {
minLvl.value = 20;
mnlMod = true;
}
floor.value = 1;
ivMod = true;
console.log("adjustFloors: Adjusted floors for Detected Raid+Trade mon:" +pokeName+", mnlMod="+mnlMod+", ivMod="+ivMod);
if (perfTiming) {stopTiming(T0, "adjustFloors");}
return;
}
if (boxMyth.includes(pokeName)) {
console.log("adjustFloors: Detected Mythical mon:" +pokeName);
/*set min IVs to 10 and min Level to 15*/
if (minLvl.value/1 < 15) {
minLvl.value = 15;
mnlMod = true;
}
floor.value = 10;
ivMod = true;
if (perfTiming) {stopTiming(T0, "adjustFloors");}
return;
}
if (raidMyth.includes(pokeName)) {
console.log("adjustFloors: Detected Raid no Trade mon:" +pokeName);
/*set min IVs to 10 and min Level to 20*/
if (minLvl.value/1 < 20) {
minLvl.value = 20;
mnlMod = true;
}
floor.value = 10;
ivMod = true;
if (perfTiming) {stopTiming(T0, "adjustFloors");}
return;
}
}
function stopTiming(startTime, functionName) {
var endTime = performance.now();
console.log(functionName+": Execution took "+(endTime-startTime).toFixed(1)+"ms");
document.getElementById('timing_outputs').innerHTML += functionName+": Execution took "+(endTime-startTime).toFixed(1)+"ms<br>";
}
function shdwUpdater() {
/* Ensure we have current shdw state all input rows */
for (var i=0; i<shdw.length; i++)
{
shdw[i] = document.getElementById("shdw["+i+"]").checked;
}
main();
}
function resetMonState() {
var T0;
if (perfTiming) {T0 = performance.now();}
var minLvl = document.getElementById('minLvl');
var floor = document.getElementById('floor');
/* Clear all existing IV Input Rows */
for (var i=0; i<aIV.length; i++) {
/* magic to actually remove all the rows one by one */
var tr = document.getElementById('aIV['+i+']').parentNode;
tr.parentNode.parentNode.removeChild(tr.parentNode);
}
/* clear the value arrays */
aIV.splice(0, aIV.length);
dIV.splice(0, dIV.length);
sIV.splice(0, sIV.length);
shdw.splice(0, shdw.length);
/* Re-Add default IV Input Row */
doTheInsert();
/* clear min stat filters, filterMod, and lastLeague */
mA = 0; mD = 0; mHP = 0; filterMod = false; lastLeague = undefined;
/*reset Min Level if we adjusted it previously*/
if (mnlMod==true) {
if ((minLvl.value == 8) || (minLvl.value == 15) || (minLvl.value == 20)) {
/* Check if User has Saved Setting for minLvl before we reset */
if (localStorage.minLvl == undefined) {
/* User has no preference for us to load, reset to default */
minLvl.value = 1;
console.log("resetMonState: Reset minLvl to default: "+minLvl.value);
} else {
minLvl.value = localStorage.minLvl;
console.log("resetMonState: Reset minLvl to User's Preference: "+localStorage.minLvl);
}
} else {console.log("resetMonState: No update needed, minLvl.value is not 8,15, or 20. User changed to: "+minLvl.value);}
mnlMod = false;
}
/*reset IV Floor if we adjusted it previously*/
if (ivMod==true) {
if ((floor.value == 1) || (floor.value == 6) || (floor.value == 10)) {
/* Check if User has Saved Setting for floor before we reset */
if (localStorage.floor == undefined) {
/* User has no preference for us to load, reset to default */
floor.value = 0;
console.log("resetMonState: Reset IV floor to default: "+floor.value);
} else {
floor.value = localStorage.floor;
console.log("resetMonState: Reset IV Floor to User's Preference: "+localStorage.floor);
}
} else {console.log("resetMonState: No update needed, floor.value is not 1,6, or 10. User changed to: "+floor.value);}
ivMod = false;
}
if (perfTiming) {stopTiming(T0, "resetMonState");}
}
function toggleFamilyEvos() {
var T0;
if (perfTiming) {T0 = performance.now();}
/* Toggle Family Evo League Selection */
if (document.getElementById("family").checked) {
document.getElementById("familyEvoLeagueLbl").style.display = "inline-block";
} else {
document.getElementById("familyEvoLeagueLbl").style.display = "none";
}
if (perfTiming) {stopTiming(T0, "toggleFamilyEvos");}
setUserPreference('family');
}
function outputUserRanks(aIV, dIV, sIV, shdw, mon, league, leagueName, ranks, dec, URL) {
var T0,Tc,Ti,Tr,T1;
if (perfTiming) {T0 = performance.now();}
/*console.log("oUR: Received aIV:"+aIV+", dIV:"+dIV+", sIV:"+sIV+", shdw:"+shdw+", league:"+league+", leagueName:"+leagueName+", ranks"+ranks+", dec:"+dec+", URL:"+URL);*/
var evoLeague = document.getElementById('familyEvoLeague').value;
var evoLeagueName = document.getElementById('familyEvoLeague').options[document.getElementById('familyEvoLeague').selectedIndex].innerHTML;
var minLvl = document.getElementById('minLvl').value;
var maxLvl = document.getElementById('maxLvl').value;
var floor = document.getElementById('floor').value;
var limit = document.getElementById('limit').value;
var keys = Object.keys(ranks);
var maxStatProd = keys[0].split(".")[0];
var evos = pokeListObj[mon].split(',').slice(4, pokeListObj[mon].split(',').length);
console.log("evos:"+JSON.stringify(evos));
var evoLen = evos.length;
var settings = (document.getElementById('mlCP').checked ? "1":"0") + (document.getElementById("cmp").checked ? "1":"0") + (document.getElementById("cge").checked ? "1":"0") + (document.getElementById("family").checked ? "1":"0") + (document.getElementById("dti").checked ? "1":"0") + (document.getElementById("dust").checked ? "1":"0") + (document.getElementById("bulk").checked ? "1":"0") + (document.getElementById("ivBox").checked ? "1":"0");
/* If family evos are checked and mirror selected, mirror selected league for family evos */
if (document.getElementById("family").checked && evoLeague === "mirror") {
evoLeague = league;
evoLeagueName = leagueName;
console.log("oUR: Detected mirror, mirroed to evoLeague:"+evoLeague+", evoLeagueName:"+evoLeagueName);
}
/*we have at least one rank to output, let's print! */
var evoHtml = "";
var evoFeedback = "";
var html = "<table id='outTable'><tr><th>#</th><th>Lvl</th><th>CP</th>";
if (document.getElementById('mlCP').checked) {
html += "<th>L"+minLvl+" CP</th>";
}
html += "<th>Atk IV</th><th>Def</th><th>Stam</th><th>Perfect</th>";
/*include XL candy costs if Max Level > 41*/
if (maxLvl > 41 && ranks.maxLvl>41) {
html+="<th>XL</th>";
}
/*include stardust costs if enabled*/
if (document.getElementById("dust").checked) {
html+="<th>Dust</th>";
}
/*print main table output and count actual outputted rows/ranks*/
var actualRank = 1; var rowsOutput = 0;
var minAtk = ranks.minAtk.value, maxAtk = ranks.maxAtk.value;
var minDef = ranks.minDef.value, maxDef = ranks.maxDef.value;
/* Initialize min stat filters if blank (first run only)*/
if ((mA+mD+mHP)/1 === 0 && filterMod === false) { console.log("Noticed mA,mD,or mHP are 0, initializing...");
mA = numOut(minAtk,dec);mD = numOut(minDef,dec);mHP = ranks.minHP.value;
} else {
/* Ensure that we don't have atk/def/HP filters above maximums */
mA = (mA/1 > maxAtk/1) ? numOut(maxAtk,dec)-1 : mA;
mD = (mD/1 > maxDef/1) ? numOut(maxDef,dec)-1 : mD;
mHP = (mHP/1 > ranks.maxHP.value/1) ? ranks.maxHP.value/1-1 : mHP;
/* Ensure that we don't have atk/def/HP filters above minimums unless filterMod is true */
if (filterMod) {console.log("Before mA:"+mA+", mD:"+mD+", mHP:"+mHP+", filterMod:"+filterMod);}
mA = (filterMod === true) ? mA : numOut(minAtk,dec);
mD = (filterMod === true) ? mD : numOut(minDef,dec);
mHP = (filterMod === true) ? mHP : ranks.minHP.value;
if (filterMod) {console.log("After mA:"+mA+", mD:"+mD+", mHP:"+mHP+", filterMod:"+filterMod);}
}
/*include cmp columns if checked*/
if (document.getElementById("cmp").checked) {
var cmpLim = document.getElementById('cmpLim').value;
if (ranks.numRanks/1 < cmpLim/1) {
/* If cmpLim is set too high, adjust down to numRanks */
cmpLim = ranks.numRanks/1;
}
html+="<th>R1 CMP</th><th>T"+cmpLim+" CMP</th>";
ranks = cmpCalcs(ranks, keys, dec, cmpLim, filterMod);
}
if (perfTiming) {Tc = performance.now();}
html+="<th>PvP Atk</th><th>Def</th><th>HP</th><th>Stat Prod</th>";
/*include bulk product if enabled*/
if (document.getElementById("bulk").checked) {
html+="<th>Bulk Prod</th>";
}
html+="</tr>";
/*used to ensure we don't Display Trade Improvement % for ineligible IVs*/
var gmRhtml = null;
document.getElementById('feedbackBox').innerHTML = "";
var uri;
lvl = []
;rIV = [];
var validIVs = "", invAtkIVs = "", invDefIVs = "", invHPIVs = "";
/* Generate user inputted IV rows for main output table */
for (i=0; i<aIV.length; i++) {
if (aIV[i] && dIV[i] && sIV[i]) {
if ((aIV[i]/1 >= floor/1) && (dIV[i]/1 >= floor/1) && (sIV[i]/1 >= floor/1)) {
/*console.log("i:"+i+" All 3 IVs > floor("+floor+"): "+aIV[i]+", "+dIV[i]+", "+sIV[i]+", aIV.length:"+aIV.length);*/
[gmRhtml, vAtk, vDef, vHP] = getMonRank(ranks, keys, shdw[i], maxStatProd, aIV[i], dIV[i], sIV[i], aIV.length, mon, false, false, maxLvl, dec);
/* Keep track of which user IVs are valid and invalid per stat filters */
if (filterMod) {
if (vAtk && vDef && vHP) {
validIVs += aIV[i]+"-"+dIV[i]+"-"+sIV[i]+" ";
} else {
if (!vAtk) {invAtkIVs += aIV[i]+"-"+dIV[i]+"-"+sIV[i]+" ";}
if (!vDef) {invDefIVs += aIV[i]+"-"+dIV[i]+"-"+sIV[i]+" ";}
if (!vHP) {invHPIVs += aIV[i]+"-"+dIV[i]+"-"+sIV[i]+" ";}
}
}
if (aIV[i] && dIV[i] && sIV[i] && (gmRhtml === "")) {
console.log("i:"+i+" Detected too high CP after getMonRank");
document.getElementById('feedbackBox').innerHTML += "<p><i>Row "+(i+1)+" with IVs ("+aIV[i]+"/"+dIV[i]+"/"+sIV[i]+") & min level ("+minLvl+") is too big for "+leagueName+"<br>Please check Advanced: Min Level and try again</i></p><br>";
} else {html += gmRhtml;}
/* See if we need to output evo familyTable*/
if (evoLen && document.getElementById("family").checked) {
/* valid set of IVs, need to find base stats for evos */
for (var e=0; e<evoLen; e++) {
/* Ensure we don't show impossible Tyrogue evos (highest stat determines evo) */
if (mon === "Tyrogue" && validTyroEvo(aIV[i], dIV[i], sIV[i], evos[e])) {continue;}
var evoVals = pokeListObj[evos[e]].split(",");
var evoRanks = calculate(parseInt(evoVals[1]), parseInt(evoVals[2]), parseInt(evoVals[3]), floor, minLvl, maxLvl, false, evoLeague, evos[e]);
var evoKeys = Object.keys(evoRanks);
var evoMaxStatProd = evoKeys[0].split(".")[0];
/*create link for evo table entry*/
uri = URL + "?mon="+evos[e];
if (limit/1 !== "10") uri += "&r="+limit;
uri += "&cp="+league; /* Must include league */
if (floor/1 > 0) uri += "&f="+floor;
if (minLvl/1 > 1) uri += "&min="+minLvl;
if (maxLvl/1 !== "51") uri += "&max="+maxLvl;
uri += "&set="+settings+"&fel="+evoLeague+"&IVs="+aIV[i] + "_" + dIV[i] + "_" + sIV[i];
if (shdw[i]) {
uri += "_" + shdw[i];
}
uri += "&mA=0&mD=0&mHP=0";
let [evoGMRhtml] = getMonRank(evoRanks, evoKeys, shdw[i], evoMaxStatProd, aIV[i], dIV[i], sIV[i], aIV.length, mon, evos[e], uri, false, dec);
if (evoGMRhtml) {
if (evoHtml) {
/*if this is a second evo, just add it*/
evoHtml += evoGMRhtml;
} else {
/*include stardust costs if enabled*/
var dustHeader = "";
if (document.getElementById("dust").checked) {
dustHeader="<th>Dust</th>";
}
/*include Bulk Product if enabled*/
var bulkProdHeader = "";
if (document.getElementById("bulk").checked) {
bulkProdHeader="<th>Bulk Prod</th>";
}
/*if this is the first evo, add header too*/
if ((evoLen > 1) || (aIV.length > 1)) {
evoHtml = "<p><i>"+evoLen+" "+mon+" "+evoLeagueName+" family evos:<br>(click table headers to sort)</i></p><table id='familyTable'><tr><th>Pokémon</th>";
if (aIV.length > 1) {
evoHtml += "<th>IVs</th>";
}
evoHtml += "<th>#</th><th>Lvl</th><th>CP</th><th>Perfect</th>"+dustHeader+"<th>Atk</th><th>Def</th><th>HP</th><th>Stat Prod</th>"+bulkProdHeader+"</tr>";
} else {
evoHtml = "<p><i>"+evoLen+" "+mon+" "+evoLeagueName+" family evo:</i></p><table id='familyTable'><tr><th>Pokémon</th><th>#</th><th>Lvl</th><th>CP</th><th>Perfect</th>"+dustHeader+"<th>Atk</th><th>Def</th><th>HP</th><th>Stat Prod</th>"+bulkProdHeader+"</tr>";
}
evoHtml += evoGMRhtml;
}
} else {
evoFeedback += "<p><i>"+evos[e]+" with your IVs ("+aIV[i]+"/"+dIV[i]+"/"+sIV[i]+") & min level ("+minLvl+") is too big for "+leagueName+"</i></p>";
}
}
}
} else {
console.log("i:"+i+" Detected IV below Floor:"+floor+" aIV[i]:"+aIV[i]+" dIV[i]:"+dIV[i]+" sIV[i]:"+sIV[i]);
document.getElementById('feedbackBox').innerHTML += "<p><i>Row "+(i+1)+" with IVs ("+aIV[i]+"/"+dIV[i]+"/"+sIV[i]+") is below the IV Floor ("+floor+")<br>Please check Advanced: IV Floor and try again</i></p><br>";
}
} else {
console.log("i:"+i+" Missing an IV, detected: aIV["+i+"]:"+aIV[i]+" dIV["+i+"]:"+dIV[i]+" sIV["+i+"]:"+sIV[i]);
document.getElementById('feedbackBox').innerHTML += "<p><i>Please enter an Attack IV for Row "+(i+1)+" with IVs (_"+aIV[i]+"_/"+dIV[i]+"/"+sIV[i]+") to check your "+mon+"'s "+leagueName+" PvP Rank</i></p>";
lvl.push(false); /* keep this balanced */
}
}
if (filterMod && aIV[0]) {
if (validIVs && (invAtkIVs || invDefIVs || invHPIVs)) {
document.getElementById('feedbackBox').innerHTML += "<p><i>IVs that meet your stat filter cutoffs: "+validIVs+"</p>";
if (invAtkIVs) {
document.getElementById('feedbackBox').innerHTML += "<p>IVs below minimum attack: "+invAtkIVs+"</i></p>";
}
if (invDefIVs) {
document.getElementById('feedbackBox').innerHTML += "<p>IVs below minimum defense: "+invDefIVs+"</i></p>";
}
if (invHPIVs) {
document.getElementById('feedbackBox').innerHTML += "<p>IVs below minimum HP: "+invHPIVs+"</i></p>";
}
} else if (validIVs) {
document.getElementById('feedbackBox').innerHTML += "<p><i>All IVs are above stat filters cutoffs</i></p>";
} else {
document.getElementById('feedbackBox').innerHTML += "<p><i>No IVs meet your stat filter cutoffs!</i></p>";
}
}
evoHtml += "</table>";
evoFeedback += "<br />";
/*console.log("outputUserRanks: Finished creating output for IVs, now printing main table...");*/
if (perfTiming) {Ti = performance.now();}
/* used to track if we should hide XL candy column */
var nonZeroXL = false;
var outIVs = "";
/* See if we need to check IV Efficiency */
var effIV = true;
if (document.getElementById("effIV").checked){
ranks = checkEfficientIVs(ranks, keys, dec);
}
for (i=0; ((actualRank/1<=ranks.numRanks/1) && (actualRank/1 <= limit/1)); i++) {
for (var j=0; j<ranks[keys[i]].length; j++) {
if ((mA/1 <= numOut(ranks[keys[i]][j].battle.A,dec)) && (mD/1 <= numOut(ranks[keys[i]][j].battle.D,dec)) && (mHP/1 <= ranks[keys[i]][j].battle.S)
&& (document.getElementById("effIV").checked===false || ranks[keys[i]][j].eff === true)) {
/* All three stats are above filter cutoffs, and (if enabled by user) IV is efficient, proceed with printing this row */
if (actualRank/1 <= limit/1) {
html+="<tr><td>"+actualRank+"</td>"; /*Rank*/
html+="<td>"+ranks[keys[i]][j].L+"</td>"; /*Level*/
html+="<td>"+ranks[keys[i]][j].CP+"</td>"; /*Final CP*/
if (document.getElementById('mlCP').checked) {html+="<td>"+Math.max(10, Math.floor((pokeListObj[mon].split(',')[1]/1 + ranks[keys[i]][j].IVs.A) * Math.sqrt(pokeListObj[mon].split(',')[2]/1 + ranks[keys[i]][j].IVs.D) * Math.sqrt(pokeListObj[mon].split(',')[3]/1 + ranks[keys[i]][j].IVs.S) * cpm[(minLvl-1)*2] * cpm[(minLvl-1)*2] / 10))+"</td>"; /*Raid/Hatch CP*/}
html+="<td>"+ranks[keys[i]][j].IVs.A+"</td>"; /*Atk IV*/
html+="<td>"+ranks[keys[i]][j].IVs.D+"</td>"; /*Def IV*/
html+="<td>"+ranks[keys[i]][j].IVs.S+"</td>"; /*Sta IV*/
outIVs+=ranks[keys[i]][j].IVs.A+"-"+ranks[keys[i]][j].IVs.D+"-"+ranks[keys[i]][j].IVs.S+",";
html+="<td>"+parseFloat((100*keys[i].split(".")[0])/maxStatProd).toFixed(3)+"%"+"</td>"; /*Perfection*/
if (maxLvl > 41 && ranks.maxLvl>41) {
var candy = XLcandy(ranks[keys[i]][j].L/1 - 40);
html+="<td>"+candy+"</td>";
if (!nonZeroXL && candy > 0) {nonZeroXL = true;} /*XL*/
}
if (document.getElementById("dust").checked) {html+= "<td>"+stardust(minLvl/1, ranks[keys[i]][j].L/1, false)+"</td>";} /*Stardust*/
if (document.getElementById("cmp").checked) {
html+="<td>"+ranks[keys[i]][j].IVs.R1+"</td>"; /*R1 CMP*/
html+="<td>"+ranks[keys[i]][j].IVs.cmp+"%"+"</td>"; /*CMP Wins*/
}
html+="<td>"+numOut(ranks[keys[i]][j].battle.A,dec)+"</td>"; /*GL Atk Total*/
html+="<td>"+numOut(ranks[keys[i]][j].battle.D,dec)+"</td>"; /*GL Def Total*/
html+="<td>"+ranks[keys[i]][j].battle.S+"</td>"; /*GL HP*/
html+="<td>"+keys[i].split(".")[0]+"</td>"; /*Stat Product*/
if (document.getElementById("bulk").checked) {
var bulkprod = numOut(numOut(ranks[keys[i]][j].battle.D,dec) * ranks[keys[i]][j].battle.S, 0);
html+="<td>"+bulkprod+"</td>"; /*Bulk Product*/
}
html+="</tr>";
rowsOutput = rowsOutput/1 + 1;
}
} else {
/* Skip printing row, but ensure we still print a total of <limit> rows */
limit = (limit/1 + 1)/1;
}
actualRank = actualRank + 1;
}
}
/*console.log("outputUserRanks: Finished loop with i:"+i+", actualRank:"+actualRank+" >= limit:"+limit);*/
html+="</table>"; /*finish building the whole table*/
var printLimit = Math.min(rowsOutput, limit, ranks.numRanks);
if (perfTiming) {Tr = performance.now();}
/*prepare max stat html output*/
var maxAtkurl = encodeURI(URL + "?mon="+mon+"&r="+limit+"&cp="+league+"&f="+floor+"&min="+minLvl+"&max="+maxLvl+"&set="+settings+"&fel="+evoLeague+"&IVs="+ranks.maxAtk.aIV + "_" + ranks.maxAtk.dIV + "_" + ranks.maxAtk.sIV);
var maxDefurl = encodeURI(URL + "?mon="+mon+"&r="+limit+"&cp="+league+"&f="+floor+"&min="+minLvl+"&max="+maxLvl+"&set="+settings+"&fel="+evoLeague+"&IVs="+ranks.maxDef.aIV + "_" + ranks.maxDef.dIV + "_" + ranks.maxDef.sIV);
var maxHPurl = encodeURI(URL + "?mon="+mon+"&r="+limit+"&cp="+league+"&f="+floor+"&min="+minLvl+"&max="+maxLvl+"&set="+settings+"&fel="+evoLeague+"&IVs="+ranks.maxHP.aIV + "_" + ranks.maxHP.dIV + "_" + ranks.maxHP.sIV);
var minAtkurl = encodeURI(URL + "?mon="+mon+"&r="+limit+"&cp="+league+"&f="+floor+"&min="+minLvl+"&max="+maxLvl+"&set="+settings+"&fel="+evoLeague+"&IVs="+ranks.minAtk.aIV + "_" + ranks.minAtk.dIV + "_" + ranks.minAtk.sIV);
var minDefurl = encodeURI(URL + "?mon="+mon+"&r="+limit+"&cp="+league+"&f="+floor+"&min="+minLvl+"&max="+maxLvl+"&set="+settings+"&fel="+evoLeague+"&IVs="+ranks.minDef.aIV + "_" + ranks.minDef.dIV + "_" + ranks.minDef.sIV);
var minHPurl = encodeURI(URL + "?mon="+mon+"&r="+limit+"&cp="+league+"&f="+floor+"&min="+minLvl+"&max="+maxLvl+"&set="+settings+"&fel="+evoLeague+"&IVs="+ranks.minHP.aIV + "_" + ranks.minHP.dIV + "_" + ranks.minHP.sIV);
var step = 1/Math.pow(10,dec);
var ranges = "<br />Atk ≥ <input type='number' step="+step+" id='atkVal' min="+numOut(minAtk,dec)+" max="+numOut(maxAtk,dec)+" value="+mA+" onchange='atkRange.value=this.value;mA=this.value;filterAdjusted();'> <a href="+minAtkurl+">"+numOut(minAtk,dec)+"</a><input type='range' id='atkRange' min="+numOut(minAtk,dec)+" max="+numOut(maxAtk,dec)+" value="+mA+" onchange='atkVal.value=this.value;mA=this.value;filterAdjusted();'><a href="+maxAtkurl+">"+numOut(maxAtk,dec)+"</a><br>";
ranges += "Def ≥ <input type='number' step="+step+" id='defVal' min="+numOut(minDef,dec)+" max="+numOut(maxDef,dec)+" value="+mD+" onchange='defRange.value=this.value;mD=this.value;filterAdjusted();'> <a href="+minDefurl+">"+numOut(minDef,dec)+"</a><input type='range' id='defRange' min="+numOut(minDef,dec)+" max="+numOut(maxDef,dec)+" value="+mD+" onchange='defVal.value=this.value;mD=this.value;filterAdjusted();'><a href="+maxDefurl+">"+numOut(maxDef,dec)+"</a><br>";
ranges += "HP ≥ <input type='number' step='1' min="+ranks.minHP.value+" max="+ranks.maxHP.value+" id='hpVal' value="+mHP+" onchange='hpRange.value=this.value;mHP=this.value;filterAdjusted();'> <a href="+minHPurl+">"+ranks.minHP.value+"</a><input type='range' id='hpRange' min="+ranks.minHP.value+" max="+ranks.maxHP.value+" value="+mHP+" onchange='hpVal.value=this.value;mHP=this.value;filterAdjusted();'><a href="+maxHPurl+">"+ranks.maxHP.value+"</a><br />";
/*compute trade percentages*/
var trades = "";
var searchLink = "";
var statProd = html.split('</td></tr><tr><td>')[0];
if ((gmRhtml !== "") && (statProd !== null) && (aIV[aIV.length-1] && dIV[aIV.length-1] && sIV[aIV.length-1])) {
statProd = statProd.split('</td><td>');
statProd = statProd[statProd.length-1];
if (document.getElementById("dti").checked) {
trades = tradePcnts(ranks, keys, statProd, floor, aIV.length, aIV[aIV.length-1], dIV[aIV.length-1], sIV[aIV.length-1], false);
}
/* Generate Search String links for each IV set, formatted like: https://pvpivs.com/searchStr.html?mon=Togedemaru&cp=1500&r=15_f_f&set=10100*/
if (!filterMod) {
for (i=0; i<rIV.length; i++) {
searchLink += "<p><a href='https://pvpivs.com/searchStr.html?mon="+mon+"&cp="+league+"&r="+rIV[i]+"&set=10100'>Generate "+mon+" Search String to Trash below Rank "+rIV[i]+"</a></p>";
}
}
} else {
if (document.getElementById("dti").checked) {
trades = tradePcnts(ranks, keys, statProd, floor, false, false, false, false, league);
}
}
/* Print out link to custom IV Search String if any ranks were filtered out*/
if (filterMod) {
var searchMon = mon;
var value = pokeListObj[mon].split(',');
/* Trim trailing comma off string */
outIVs = outIVs.replace(/,\s*$/, "");
/* Ensure that mon is a base form, if not find the base form! */
if (!(value[0].includes("b"))) {
/* Not a base form, check evolutions */
var monFamilyNames = value.slice(4,value.length);
for (i=0; i<monFamilyNames.length; i++) {
if ((pokeListObj[monFamilyNames[i]].split(",")[0]).includes("b")) {
/*console.log("Found the base mon! "+pokeListObj[monFamilyNames[i]].split(",")[0]+", setting searchMon="+monFamilyNames[i]);*/
searchMon = monFamilyNames[i];
}
}
}
searchLink += "<p><a href='https://www.pvpivs.com/searchStr.html?mon="+searchMon+"&cp="+league+"&o=000011&IVentry="+outIVs+"'>Generate "+searchMon+" Search String for only these filtered IVs</a></p>";
}
document.getElementById('outputBox').innerHTML = evoHtml + evoFeedback + html + ranges + searchLink + "<br>" + trades;
/* Append how many total ranks were generated at the end of "Top <Ranks> <League> <Mon>" top line on page" */
document.getElementById("instructionsBox").innerHTML += "<p id='totalRanks'> of "+ranks.numRanks+":</p><br />";
if (perfTiming) {T1 = performance.now();
console.log(mon+" outputUserRanks: "+(T1-T0).toFixed(1)+"ms (CMP "+(Tc-T0).toFixed(1)+"ms +IVs "+(Ti-Tc).toFixed(1)+"ms + Rows "+(Tr-Ti).toFixed(1)+"ms) for "+ranks.numRanks+" ranks.");
document.getElementById('timing_outputs').innerHTML += "outputUserRanks: "+(T1-T0).toFixed(1)+"ms (CMP "+(Tc-T0).toFixed(1)+"ms +IVs "+(Ti-Tc).toFixed(1)+"ms + Rows "+(Tr-Ti).toFixed(1)+"ms) for "+ranks.numRanks+" ranks.<br>";
}
return [printLimit];
}
function filterAdjusted() {
filterMod = true;
main();
}
function main(mon) {
var T0;
if (perfTiming) {T0 = performance.now();}
else {document.getElementById('timing_outputs').innerHTML = "";}
if (document.getElementById("ivBox").checked == true) {
showIVinput();
}
if (mon) { /* This is a new input */
console.log("main: New mon detected, resetting monState, mon:"+mon);
resetMonState();
adjustFloors(mon);
}
/* Awesomeplete sends "undefined" when it did not find a valid input */
if (mon === undefined) { /* Determine if we have a valid, previously selected mon we can use */
if ((pokeListObj[input.value]) || (pokeListObj[inputMon])) {
console.log("main: Found a valid input.value of:"+JSON.stringify(input.value));
/* Correct for autocomplete input being cleared accidentally */
if ((!(pokeListObj[input.value])) && (pokeListObj[inputMon])) {
input.value = inputMon;
}
mon = input.value;
/*console.log("SET MON TO:"+mon);*/
}
}
/* Exit if we don't have a valid mon yet */
if (typeof mon === 'undefined' || mon === null || typeof pokeListObj[mon] === 'undefined') {
console.log("main: No Pokémon received by main()");
if (perfTiming) {stopTiming(T0, "main");}
return;
} else { /* Have a valid mon, remove instructions */
document.getElementById('instructionsBox').innerHTML = "";
document.getElementById("IVinputShow").style.display = "none";
}
/*ensure we clear the prior output between runs*/
document.getElementById('outputBox').innerHTML = "";
if (document.contains(document.getElementById("totalRanks"))) {document.getElementById("totalRanks").remove();}
var monInfo = pokeListObj[mon].split(',');
/*Ensure we get the info we need to continue*/
if (monInfo === "")
{
console.error("main: Cannot find monInfo, returning");
document.getElementById('instructionsBox').innerHTML = "<p><i>ERROR: Cannot find monInfo, please try again.<br>If this issue persists, please <a href='https://discord.gg/UD4Temq'>contact us on Discord</i></p>";
if (perfTiming) {stopTiming(T0, "main");}
return false;
}
/* name user input fields for code readability */
var league = document.getElementById('league').value;
var dec = document.getElementById('dec').value;
var leagueName = document.getElementById('league').options[document.getElementById('league').selectedIndex].innerHTML;
if ((lastLeague) && (leagueName !== lastLeague)){ /* Reset if new League */mA = 0; mD = 0; mHP = 0;filterMod=false;}
lastLeague = leagueName; /* Store League for next run */
var ranks = calculate(parseInt(monInfo[1]), parseInt(monInfo[2]), parseInt(monInfo[3]), document.getElementById('floor').value, document.getElementById('minLvl').value, document.getElementById('maxLvl').value, document.getElementById("dti").checked, league, mon);
var URL = window.location.href.split("?")[0];
/*ensure we actually generated something to output*/
if (ranks.numRanks/1 < 1) {
/*nothing to output, print Error and exit*/
document.getElementById('instructionsBox').innerHTML = "<p><i>No eligible "+leagueName+" IVs found!<br>Please check the Min Level in Advanced and try again</i></p><br />";
document.getElementById('feedbackBox').innerHTML = "";
console.log("main: No ranks generated!");
if (perfTiming) {stopTiming(T0, "main");}
return false;
}
/* Ensure we have current IVs for all input rows */
for (var i=0; i<aIV.length; i++)
{
aIV[i] = document.getElementById("aIV["+i+"]").value;
dIV[i] = document.getElementById("dIV["+i+"]").value;
sIV[i] = document.getElementById("sIV["+i+"]").value;
}
const [printLimit] = outputUserRanks(aIV, dIV, sIV, shdw, mon, league, leagueName, ranks, dec, URL);
displayPvPokeEvoGroup(mon);
/*update the URL with search parameters*/
/*URL = "mon=Venusaur&r=10&cp=1500&f=0&min=1&max=40&set=000000&fel=1500&mA=119.7&mD=112.6&mHP=113";*/
var uri = URL + "?mon="+mon;
/* Only print remaining params if they aren't default values */
if (printLimit !== "10") uri += "&r="+printLimit;
uri += "&cp="+league; /* Must include league */
if (document.getElementById('floor').value > 0) {uri += "&f="+document.getElementById('floor').value;}
if (document.getElementById('minLvl').value > 1) {uri += "&min="+document.getElementById('minLvl').value;}
if (document.getElementById('maxLvl').value!== "51") {uri += "&max="+document.getElementById('maxLvl').value;}
var settings = (document.getElementById('mlCP').checked ? "1":"0") + (document.getElementById("cmp").checked ? "1":"0") + (document.getElementById("cge").checked ? "1":"0") + (document.getElementById("family").checked ? "1":"0") + (document.getElementById("dti").checked ? "1":"0") + (document.getElementById("dust").checked ? "1":"0") + (document.getElementById("bulk").checked ? "1":"0") + (document.getElementById("ivBox").checked ? "1":"0");
if (settings !== "00000000") {
/*console.log("906: About to make '&set'="+settings);*/
uri += "&set="+settings;}
if (document.getElementById('cmpLim').value !== "100") {uri += "&cmpLim="+document.getElementById('cmpLim').value;}
if (document.getElementById('familyEvoLeague').value !== "mirror") {uri += "&fel="+document.getElementById('familyEvoLeague').value;}
if (filterMod && mA !== numOut(ranks.minAtk.value, dec)) {uri += "&mA="+mA;console.log("mA:"+mA+" while numOut("+ranks.minAtk.value+", "+dec+"):"+numOut(ranks.minAtk.value, dec));}
if (filterMod && mD !== numOut(ranks.minDef.value, dec)) {uri += "&mD="+mD;}
if (filterMod && mHP !== ranks.minHP.value) {uri += "&mHP="+mHP;}
if (document.getElementById('effIV').checked) {uri += "&p=" + (document.getElementById("effIV").checked ? "1":"0");}
if (document.getElementById('dec').value > 1) {uri += "&dec="+document.getElementById('dec').value;}
if (aIV[0] && dIV[0] && sIV[0]) {
var IVs = "";
for (i=0; i<aIV.length; i++) {
if (i > 0) {IVs += "-";} else {IVs = "";}
IVs += aIV[i] + "_" + dIV[i] + "_" + sIV[i];
if (shdw[i]) {
IVs += "_" + shdw[i];
}
}
uri += "&IVs="+IVs;
}
uri = encodeURI(uri);
/*console.log("uri generated as:"+uri);*/
/* Update title and description to improve SEO for chosen mon */
var newTitle = mon+" PvP IVs - "+leagueName+" Rankings (Top "+document.getElementById('limit').value+")";
document.title = newTitle.replace(/_/g, ' '); /* replace all underscores ('_') with spaces */
window.history.pushState(null, newTitle, uri);
var newDescrp = mon+" PvP IVs lookup tool for Pokémon Go™ to help compare your "+mon+"'s PvP IVs to ideal PvP IVs. Finds PvP IVs for any wild-caught, weather boosted, traded, raided, hatched, and even purified "+mon+"! Did you catch the very best?";
document.querySelector('meta[name="description"]').setAttribute("content", newDescrp);
/* Update canonical link to include mon & league for improved SEO */
document.querySelector("link[rel='canonical']").setAttribute("href", "https://pvpivs.com/?mon="+mon+"&cp="+league);
/* Add event listener to capture user clicking on any table row */
document.getElementById('outTable').addEventListener('click', (function(){addToCompare(event);}), false);
/*make table sortable by clicking on any header https://stackoverflow.com/a/49041392 */
const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent;
const comparer = (idx, asc) => (a, b) => ((v1, v2) =>
v1 !== '' && v2 !== '' && !isNaN(v1.replace("%", "")) && !isNaN(v2.replace("%", "")) ? v1.replace("%", "") - v2.replace("%", "") : v1.toString().localeCompare(v2)
)(getCellValue(asc ? a : b, idx), getCellValue(asc ? b : a, idx));
/*sort the table by the column the user clicked on*/
document.querySelectorAll('th').forEach(th => th.addEventListener('click', (() => {
const table = th.closest('table');
Array.from(table.querySelectorAll('tr:nth-child(n+2)'))
.sort(comparer(Array.from(th.parentNode.children).indexOf(th), this.asc = !this.asc))
.forEach(tr => table.appendChild(tr) );
})));
if (perfTiming) {stopTiming(T0, "main");}
}
function displayPvPokeEvoGroup(inputName) {
var T0;
if (perfTiming) {T0 = performance.now();}
/*show textbox with PvPoke Custom Group Export data*/
if (document.getElementById("cge").checked === true)
{
var name = inputName;
/* Game Master uses Alola, but PvPoke uses Alolan, need to fix for valid data export */
console.log("displayPvPokeEvoGroup starting...");
if (name.includes("_Alola")) {
name = name + "n";
}
var cgeData = "";
var maxWidth = 0;
var validIVs;
for (var i=0; i<aIV.length; i++) {
validIVs = false;
var mon = name;
if (shdw[i]) {
mon = name + "_shadow";
}
if (aIV[i] === "") {
console.log("skipping incomplete row, i:"+i+", aIV:"+aIV[i]+", dIV:"+dIV[i]+", sIV:"+sIV[i]);