AdamOswald1 commited on
Commit
a422892
1 Parent(s): 6887937

Upload poke.js

Browse files
Files changed (1) hide show
  1. poke.js +1167 -0
poke.js ADDED
@@ -0,0 +1,1167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //Data exceptions (poke-api isn't fully updated)
2
+ const weezingabilities = {
3
+ "abilities": [
4
+ {
5
+ "ability": {
6
+ "name": "levitate",
7
+ "url": "https://pokeapi.co/api/v2/ability/69/"
8
+ },
9
+ "is_hidden": false,
10
+ "slot": 1
11
+ },
12
+ {
13
+ "ability": {
14
+ "name": "neutralizing-gas",
15
+ "url": "https://pokeapi.co/api/v2/ability/5/"
16
+ },
17
+ "is_hidden": false,
18
+ "slot": 2
19
+ },
20
+ {
21
+ "ability": {
22
+ "name": "stench",
23
+ "url": "https://pokeapi.co/api/v2/ability/125/"
24
+ },
25
+ "is_hidden": true,
26
+ "slot": 3
27
+ }
28
+ ]
29
+ }
30
+
31
+ const aegislashstats = {
32
+ "stats": [
33
+ {
34
+ "base_stat": 60,
35
+ "effort": 0,
36
+ "stat": {
37
+ "name": "hp",
38
+ "url": "https://pokeapi.co/api/v2/stat/1/"
39
+ }
40
+ },
41
+ {
42
+ "base_stat": 50,
43
+ "effort": 0,
44
+ "stat": {
45
+ "name": "attack",
46
+ "url": "https://pokeapi.co/api/v2/stat/2/"
47
+ }
48
+ },
49
+ {
50
+ "base_stat": 140,
51
+ "effort": 2,
52
+ "stat": {
53
+ "name": "defense",
54
+ "url": "https://pokeapi.co/api/v2/stat/3/"
55
+ }
56
+ },
57
+ {
58
+ "base_stat": 50,
59
+ "effort": 0,
60
+ "stat": {
61
+ "name": "special-attack",
62
+ "url": "https://pokeapi.co/api/v2/stat/4/"
63
+ }
64
+ },
65
+ {
66
+ "base_stat": 140,
67
+ "effort": 1,
68
+ "stat": {
69
+ "name": "special-defense",
70
+ "url": "https://pokeapi.co/api/v2/stat/5/"
71
+ }
72
+ },
73
+ {
74
+ "base_stat": 60,
75
+ "effort": 0,
76
+ "stat": {
77
+ "name": "speed",
78
+ "url": "https://pokeapi.co/api/v2/stat/6/"
79
+ }
80
+ }
81
+ ]
82
+ }
83
+
84
+ const types = new Array(
85
+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.5, 0, 1, 1, 0.5, 1, 1],// Normal
86
+ [1, 0.5, 0.5, 1, 2, 2, 1, 1, 1, 1, 1, 2, 0.5, 1, 0.5, 1, 2, 1, 1],// Fire
87
+ [1, 2, 0.5, 1, 0.5, 1, 1, 1, 2, 1, 1, 1, 2, 1, 0.5, 1, 1, 1, 1],// Water
88
+ [1, 1, 2, 0.5, 0.5, 1, 1, 1, 0, 2, 1, 1, 1, 1, 0.5, 1, 1, 1, 1],// Electric
89
+ [1, 0.5, 2, 1, 0.5, 1, 1, 0.5, 2, 0.5, 1, 0.5, 2, 1, 0.5, 1, 0.5, 1, 1],// Grass
90
+ [1, 0.5, 0.5, 1, 2, 0.5, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, 0.5, 1, 1],// Ice
91
+ [2, 1, 1, 1, 1, 2, 1, 0.5, 1, 0.5, 0.5, 0.5, 2, 0, 1, 2, 2, 0.5, 1],// Fighting
92
+ [1, 1, 1, 1, 2, 1, 1, 0.5, 0.5, 1, 1, 1, 0.5, 0.5, 1, 1, 0, 2, 1],// Poison
93
+ [1, 2, 1, 2, 0.5, 1, 1, 2, 1, 0, 1, 0.5, 2, 1, 1, 1, 2, 1, 1],// Ground
94
+ [1, 1, 1, 0.5, 2, 1, 2, 1, 1, 1, 1, 2, 0.5, 1, 1, 1, 0.5, 1, 1],// Flying
95
+ [1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 0.5, 1, 1, 1, 1, 0, 0.5, 1, 1],// Psychic
96
+ [1, 0.5, 1, 1, 2, 1, 0.5, 0.5, 1, 0.5, 2, 1, 1, 0.5, 1, 2, 0.5, 0.5, 1],// Bug
97
+ [1, 2, 1, 1, 1, 2, 0.5, 1, 0.5, 2, 1, 2, 1, 1, 1, 1, 0.5, 1, 1],// Rock
98
+ [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 0.5, 1, 1, 1],// Ghost
99
+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 0.5, 0, 1],// Dragon
100
+ [1, 1, 1, 1, 1, 1, 0.5, 1, 1, 1, 2, 1, 1, 2, 1, 0.5, 1, 0.5, 1],// Dark
101
+ [1, 0.5, 0.5, 0.5, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0.5, 2, 1],// Steel
102
+ [1, 0.5, 1, 1, 1, 1, 2, 0.5, 1, 1, 1, 1, 1, 1, 2, 2, 0.5, 1, 1],// Fairy
103
+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);// None
104
+
105
+ const typeName = ["normal", "fire", "water", "electric", "grass", "ice", "fighting", "poison", "ground", "flying", "psychic", "bug", "rock", "ghost", "dragon", "dark", "steel", "fairy"];
106
+ var result1 = new Array();
107
+ var result2 = new Array();
108
+
109
+ var chk = []
110
+ var ids2 = []
111
+
112
+ var saveInit = -1
113
+ var saveBtn = true
114
+ var saveIndex = 0
115
+ var saves = [] //List of fusions made
116
+
117
+ var typeComp = 0;
118
+
119
+ //Adding options to datalist
120
+ var box1 = document.getElementById('fname1');
121
+ var box2 = document.getElementById('fname2');
122
+ var box3 = document.getElementById('fname3');
123
+ var dl = document.createElement('datalist');
124
+ dl.id = 'dlPkmn';
125
+
126
+ for (var i = 0; i < ids.length; i += 1) {
127
+ var option = document.createElement('option');
128
+ //Special name case
129
+ option.value = nameCheck(ids[i][0])
130
+ dl.appendChild(option);
131
+ }
132
+ box1.appendChild(dl);
133
+ box2.appendChild(dl);
134
+ box3.appendChild(dl);
135
+
136
+ //Press 'Enter' event
137
+ document.addEventListener("keydown", function (event) {
138
+ key = event.key || event.keyCode
139
+ if (key == 'Enter' || key == 13) {
140
+ if (box1 === document.activeElement && box1.value.length != 0) {
141
+ box1.value = nameCheck(outputClosest(box1.value))
142
+ } else if (box2 === document.activeElement && box2.value.length != 0) {
143
+ box2.value = nameCheck(outputClosest(box2.value))
144
+ }
145
+ if (box1.value.length != 0 && box2.value.length != 0) {
146
+ verifInputs()
147
+ }
148
+ }
149
+ });
150
+
151
+ //Empty pokemon text area
152
+ function resetPoke() {
153
+ document.getElementById("fname1").value = null;
154
+ document.getElementById("fname2").value = null;
155
+ document.getElementById("fname3").value = null;
156
+ document.getElementById("p1").src = "Types/null.png";
157
+ document.getElementById("p2").style = "display:none";
158
+ document.getElementById("p3").style = "display:none";
159
+ document.getElementById("p4").src = "Types/null.png";
160
+ document.getElementById("p5").style = "display:none";
161
+ document.getElementById("p6").style = "display:none";
162
+ document.getElementById("p7").src = "Types/null.png";
163
+ document.getElementById("p8").style = "display:none";
164
+ document.getElementById("p9").style = "display:none";
165
+ document.getElementById("pic1").src = "question.png";
166
+ document.getElementById("pic2").src = "question.png";
167
+ document.getElementById("pic3").src = "question.png";
168
+
169
+ /*document.getElementById("IG1").innerHTML = "";
170
+ document.getElementById("IG2").innerHTML = "";
171
+ document.getElementById("IG3").innerHTML = "";*/
172
+
173
+ document.getElementById("FP1").innerHTML = "mon1/mon3/mon2";
174
+ document.getElementById("FP2").innerHTML = "mon1/mon2/mon3";
175
+ document.getElementById("FP3").innerHTML = "mon2/mon3/mon1";
176
+
177
+ document.getElementById("hp1").innerHTML = "HP: ";
178
+ document.getElementById("atk1").innerHTML = "ATK: ";
179
+ document.getElementById("def1").innerHTML = "DEF: ";
180
+ document.getElementById("spatk1").innerHTML = "SPE.ATK: ";
181
+ document.getElementById("spdef1").innerHTML = "SPE.DEF: ";
182
+ document.getElementById("spe1").innerHTML = "SPEED: ";
183
+ document.getElementById("bs1").innerHTML = "TOTAL: ";
184
+ document.getElementById("ab1").innerHTML = "ABILITY:";
185
+
186
+ document.getElementById("hp2").innerHTML = "HP: ";
187
+ document.getElementById("atk2").innerHTML = "ATK: ";
188
+ document.getElementById("def2").innerHTML = "DEF: ";
189
+ document.getElementById("spatk2").innerHTML = "SPE.ATK: ";
190
+ document.getElementById("spdef2").innerHTML = "SPE.DEF: ";
191
+ document.getElementById("spe2").innerHTML = "SPEED: ";
192
+ document.getElementById("bs2").innerHTML = "TOTAL: ";
193
+ document.getElementById("ab2").innerHTML = "ABILITY:";
194
+
195
+ document.getElementById("hp3").innerHTML = "HP: ";
196
+ document.getElementById("atk3").innerHTML = "ATK: ";
197
+ document.getElementById("def3").innerHTML = "DEF: ";
198
+ document.getElementById("spatk3").innerHTML = "SPE.ATK: ";
199
+ document.getElementById("spdef3").innerHTML = "SPE.DEF: ";
200
+ document.getElementById("spe3").innerHTML = "SPEED: ";
201
+ document.getElementById("bs3").innerHTML = "TOTAL: ";
202
+ document.getElementById("ab3").innerHTML = "ABILITY:";
203
+
204
+ document.getElementById("weak14").innerHTML = "x4: ";
205
+ document.getElementById("weak12").innerHTML = "x2: ";
206
+ document.getElementById("weak11").innerHTML = "x1: ";
207
+ document.getElementById("weak105").innerHTML = "x0.5: ";
208
+ document.getElementById("weak1025").innerHTML = "x0.25: ";
209
+ document.getElementById("weak100").innerHTML = "x0: ";
210
+
211
+ document.getElementById("weak24").innerHTML = "x4: ";
212
+ document.getElementById("weak22").innerHTML = "x2: ";
213
+ document.getElementById("weak21").innerHTML = "x1: ";
214
+ document.getElementById("weak205").innerHTML = "x0.5: ";
215
+ document.getElementById("weak2025").innerHTML = "x0.25: ";
216
+ document.getElementById("weak200").innerHTML = "x0: ";
217
+
218
+ var L0 = ["hp1", "atk1", "def1", "spatk1", "spdef1", "spe1", "bs1"];
219
+ var L1 = ["hp2", "atk2", "def2", "spatk2", "spdef2", "spe2", "bs2"];
220
+ var L2 = ["hp3", "atk3", "def3", "spatk3", "spdef3", "spe3", "bs3"];
221
+ for (var i = 0; i < L0.length; i++) {
222
+ document.getElementById(L0[i]).style.color = "";
223
+ document.getElementById(L1[i]).style.color = "";
224
+ document.getElementById(L2[i]).style.color = "";
225
+ }
226
+ }
227
+
228
+ //Random pokemon
229
+ function randomPoke() {
230
+ document.getElementById("random").disabled = true;
231
+ var idsRand = orderByEvo()
232
+ var rand1 = Math.floor(Math.random() * (idsRand.length))
233
+ var rand2 = Math.floor(Math.random() * (idsRand.length))
234
+ var rand3 = Math.floor(Math.random() * (idsRand.length))
235
+ document.getElementById("fname1").value = nameCheck(idsRand[rand1][0])
236
+ document.getElementById("fname2").value = nameCheck(idsRand[rand2][0])
237
+ document.getElementById("fname3").value = nameCheck(idsRand[rand3][0])
238
+ document.getElementById("button").click();
239
+ }
240
+
241
+ //Random pokemon for a specific input
242
+ function randomHalf(inputField) {
243
+ var idsRand = orderByEvo()
244
+ var rand = Math.floor(Math.random() * (idsRand.length))
245
+ if (inputField == 1) {
246
+ box1.value = nameCheck(idsRand[rand][0])
247
+ if (box2.value.length > 0) {
248
+ document.getElementById("r1").disabled = true;
249
+ document.getElementById("button").click();
250
+ }
251
+ } else {
252
+ box2.value = nameCheck(idsRand[rand][0])
253
+ if (box1.value.length > 0) {
254
+ document.getElementById("r2").disabled = true;
255
+ document.getElementById("button").click();
256
+ }
257
+ } else {
258
+ box3.value = nameCheck(idsRand[rand][0])
259
+ if (box1.value.length > 0) {
260
+ document.getElementById("r3").disabled = true;
261
+ document.getElementById("button").click();
262
+ }
263
+ }
264
+ }
265
+
266
+ //Fusion calculation function
267
+ function fusePoke() {
268
+
269
+ //Pokemon from both text area
270
+ var mon1 = (document.getElementById("fname1")).value.toLowerCase();
271
+ var mon2 = (document.getElementById("fname2")).value.toLowerCase();
272
+ var mon3 = (document.getElementById("fname3")).value.toLowerCase();
273
+ if ((mon1 == "" || mon1.length == 0 || mon1 == null) || (mon2 == "" || mon2.length == 0 || mon2 == null) || (mon3 == "" || mon3.length == 0 || mon3 == null)) {
274
+ document.getElementById("random").disabled = false
275
+ alert("Please fill the two text inputs!");
276
+ } else {
277
+ //Special mon selector: Giratina, Deoxys
278
+ if (nameException.includes(mon1)) {
279
+ mon1 = nameFix[nameException.indexOf(mon1)];
280
+ }
281
+ if (nameException.includes(mon2)) {
282
+ mon2 = nameFix[nameException.indexOf(mon2)];
283
+ }
284
+ if (nameException.includes(mon3)) {
285
+ mon3 = nameFix[nameException.indexOf(mon3)];
286
+ }
287
+
288
+ //First request
289
+ var txhr = new XMLHttpRequest();
290
+ var poke1 = 'https://pokeapi.co/api/v2/pokemon/' + mon1;
291
+ txhr.open('GET', poke1, true);
292
+ txhr.send();
293
+ txhr.onload = function () {
294
+ var jsonBody = txhr.responseText;
295
+ if (jsonBody) {
296
+ try {
297
+ a = JSON.parse(jsonBody);
298
+ } catch (e) {
299
+ alert("The first pokemon was misspelled!"); // error in the above string (in this case, yes)!
300
+ }
301
+ }
302
+ var jsonString = JSON.parse(jsonBody);
303
+
304
+ //ID selector for sprite showcase of the 1st mon/ Validator for 1st mon
305
+ var num1 = jsonString.id;
306
+ var id1 = num1;
307
+ var idCheck1 = false;
308
+ for (i = 0; i < ids.length; i++) {
309
+ if (ids[i][0] == mon1.charAt(0).toUpperCase() + mon1.slice(1)) {
310
+ idCheck1 = true;
311
+ num1 = ids[i][1];
312
+ }
313
+ }
314
+ if (idCheck1 == false && id1 >= 252) {
315
+ alert("The first pokemon isn't in the fangame!")
316
+ } else {
317
+ //Type selector for fusion type knowledge of the 1st mon
318
+ var type1 = jsonString.types;
319
+ var poke1 = 'https://pokeapi.co/api/v2/pokemon/' + type1[0].type.name;
320
+ var mon1types = [];
321
+ var compt = 0
322
+
323
+ //Exception mon selected for swapped types
324
+ for (i = 0; i < typeSwap.length; i++) {
325
+ if (typeSwap[i][2] == mon1.charAt(0).toUpperCase() + mon1.slice(1)) {
326
+ mon1types.push(typeSwap[i][0]);
327
+ mon1types.push(typeSwap[i][1]);
328
+ var compt = 1;
329
+ }
330
+ }
331
+
332
+ //Exception mon selected for one type
333
+ for (i = 0; i < typeUni.length; i++) {
334
+ if (typeUni[i][1] == mon1.charAt(0).toUpperCase() + mon1.slice(1)) {
335
+ mon1types.push(typeUni[i][0]);
336
+ var compt = 2;
337
+ }
338
+ }
339
+
340
+ //Type of 1st mon
341
+ if (compt == 0) {
342
+ mon1types.push(type1[0].type.name);
343
+ if (type1.length == 2 && compt != 2) {
344
+ if (type1[0].type.name == "normal" && type1[1].type.name == "flying") {
345
+ mon1types[0] = "flying";
346
+ } else {
347
+ mon1types.push(type1[1].type.name);
348
+ }
349
+ }
350
+ }
351
+
352
+ //Stats of 1st mon
353
+ var mon1stats = [];
354
+ if (mon1 != "aegislash-shield") {
355
+ var stats1 = jsonString.stats;
356
+ } else {
357
+ var stats1 = aegislashstats.stats;
358
+ }
359
+ for (i = 0; i < stats1.length; i++) {
360
+ mon1stats.push(stats1[i].base_stat)
361
+ }
362
+
363
+ //Ability of 1st mon
364
+ var mon1abilities = [];
365
+ if (mon1 != "weezing") {
366
+ var ab1 = jsonString.abilities;
367
+ } else {
368
+ var ab1 = weezingabilities.abilities;
369
+ }
370
+ for (i = 0; i < ab1.length; i++) {
371
+ mon1abilities.push([ab1[i].ability, ab1[i].is_hidden]);
372
+ }
373
+
374
+ //2nd request
375
+ var pxhr = new XMLHttpRequest();
376
+ var poke2 = 'https://pokeapi.co/api/v2/pokemon/' + mon2
377
+ pxhr.open('GET', poke2, true);
378
+ pxhr.send();
379
+ pxhr.onload = function () {
380
+
381
+ var jsonBody = pxhr.responseText;
382
+ if (jsonBody) {
383
+ try {
384
+ a = JSON.parse(jsonBody);
385
+ } catch (e) {
386
+ alert("The second pokemon was misspelled!"); // error in the above string (in this case, yes)!
387
+ }
388
+ }
389
+ var jsonString = JSON.parse(jsonBody);
390
+
391
+ //Name of fusion
392
+ if (!nameFix.includes(mon1) && !nameFix.includes(mon2) && !nameFix.includes(mon3)) {
393
+ var fmon1 = mon1.charAt(0).toUpperCase() + mon1.slice(1);
394
+ var fmon2 = mon2.charAt(0).toUpperCase() + mon2.slice(1);
395
+ var fmon3 = mon3.charAt(0).toUpperCase() + mon3.slice(1);
396
+ } else if (nameFix.includes(mon1) && !nameFix.includes(mon2) && !nameFix.includes(mon3)) {
397
+ var fmon1 = nameException[nameFix.indexOf(mon1)].charAt(0).toUpperCase() + nameException[nameFix.indexOf(mon1)].slice(1);
398
+ var fmon2 = mon2.charAt(0).toUpperCase() + mon2.slice(1);
399
+ var fmon3 = mon3.charAt(0).toUpperCase() + mon3.slice(1);
400
+ } else if (!nameFix.includes(mon1) && nameFix.includes(mon2) && nameFix.includes(mon3)) {
401
+ var fmon1 = mon1.charAt(0).toUpperCase() + mon1.slice(1);
402
+ var fmon2 = nameException[nameFix.indexOf(mon2)].charAt(0).toUpperCase() + nameException[nameFix.indexOf(mon2)].slice(1);
403
+ } else if (nameFix.includes(mon1) && nameFix.includes(mon2) && nameFix.includes(mon3)) {
404
+ var fmon1 = nameException[nameFix.indexOf(mon1)].charAt(0).toUpperCase() + nameException[nameFix.indexOf(mon1)].slice(1);
405
+ var fmon2 = nameException[nameFix.indexOf(mon2)].charAt(0).toUpperCase() + nameException[nameFix.indexOf(mon2)].slice(1);
406
+ }
407
+
408
+ //ID selector for sprite showcase of the 2st mon
409
+ var num2 = jsonString.id;
410
+ var id2 = num2;
411
+ var idCheck2 = false;
412
+ for (i = 0; i < ids.length; i++) {
413
+ if (ids[i][0] == mon2.charAt(0).toUpperCase() + mon2.slice(1)) {
414
+ idCheck2 = true;
415
+ num2 = ids[i][1];
416
+ }
417
+ }
418
+ if (idCheck2 == false && id2 >= 252) {
419
+ alert("The second pokemon isn't in the fangame!")
420
+ } else {
421
+
422
+ //Name of fusions
423
+ document.getElementById("FP1").innerHTML = fmon1 + "/" + fmon2;
424
+ document.getElementById("FP2").innerHTML = fmon2 + "/" + fmon1;
425
+
426
+ //Name of pictures
427
+ var pic1 = num1 + "." + num2 + ".png";
428
+ var pic2 = num2 + "." + num1 + ".png";
429
+
430
+ //Type selector for fusion type knowledge of the 2nd mon
431
+ var type2 = jsonString.types;
432
+ var mon2types = [];
433
+ var compt = 0
434
+
435
+ //Exception mon selected for swapped types
436
+ for (i = 0; i < typeSwap.length; i++) {
437
+ if (typeSwap[i][2] == mon2.charAt(0).toUpperCase() + mon2.slice(1)) {
438
+ mon2types.push(typeSwap[i][0]);
439
+ mon2types.push(typeSwap[i][1]);
440
+ var compt = 1;
441
+ }
442
+ }
443
+
444
+ //Exception mon selected for one type
445
+ for (i = 0; i < typeUni.length; i++) {
446
+ if (typeUni[i][1] == mon2.charAt(0).toUpperCase() + mon2.slice(1)) {
447
+ mon2types.push(typeUni[i][0]);
448
+ var compt = 2;
449
+ }
450
+ }
451
+
452
+ //Type of 2nd mon
453
+ if (compt == 0) {
454
+ mon2types.push(type2[0].type.name);
455
+ if (type2.length == 2 && compt != 2) {
456
+ if (type2[0].type.name == "normal" && type2[1].type.name == "flying") {
457
+ mon2types[0] = "flying";
458
+ } else {
459
+ mon2types.push(type2[1].type.name);
460
+ }
461
+ }
462
+ }
463
+
464
+ //Stats of 2nd mon
465
+ var mon2stats = [];
466
+ if (mon2 != "aegislash-shield") {
467
+ var stats2 = jsonString.stats;
468
+ } else {
469
+ var stats2 = aegislashstats.stats;
470
+ }
471
+ for (i = 0; i < stats2.length; i++) {
472
+ mon2stats.push(stats2[i].base_stat)
473
+ }
474
+
475
+ //Abilities of 2nd mon
476
+ if (mon2 != "weezing") {
477
+ var ab2 = jsonString.abilities;
478
+ } else {
479
+ var ab2 = weezingabilities.abilities;
480
+ }
481
+ var mon2abilities = [];
482
+ for (i = 0; i < ab2.length; i++) {
483
+ mon2abilities.push([ab2[i].ability, ab2[i].is_hidden]);
484
+ }
485
+
486
+ //Stats calculation
487
+ var hp1 = (mon2stats[0] / 3) + 2 * (mon1stats[0] / 3);
488
+ if (mon1 == "shedinja") {
489
+ hp1 = 1
490
+ }
491
+ var atk1 = 2 * (mon2stats[1] / 3) + (mon1stats[1] / 3);
492
+ var def1 = 2 * (mon2stats[2] / 3) + (mon1stats[2] / 3);
493
+ var spatk1 = (mon2stats[3] / 3) + 2 * (mon1stats[3] / 3);
494
+ var spdef1 = (mon2stats[4] / 3) + 2 * (mon1stats[4] / 3);
495
+ var spe1 = 2 * (mon2stats[5] / 3) + (mon1stats[5] / 3);
496
+ var bs1 = Math.floor(hp1) + Math.floor(atk1) + Math.floor(def1) + Math.floor(spatk1) + Math.floor(spdef1) + Math.floor(spe1);
497
+
498
+ var hp2 = (mon1stats[0] / 3) + 2 * (mon2stats[0] / 3);
499
+ if (mon2 == "shedinja") {
500
+ hp2 = 1
501
+ }
502
+ var atk2 = 2 * (mon1stats[1] / 3) + (mon2stats[1] / 3);
503
+ var def2 = 2 * (mon1stats[2] / 3) + (mon2stats[2] / 3);
504
+ var spatk2 = (mon1stats[3] / 3) + 2 * (mon2stats[3] / 3);
505
+ var spdef2 = (mon1stats[4] / 3) + 2 * (mon2stats[4] / 3);
506
+ var spe2 = 2 * (mon1stats[5] / 3) + (mon2stats[5] / 3);
507
+ var bs2 = Math.floor(hp2) + Math.floor(atk2) + Math.floor(def2) + Math.floor(spatk2) + Math.floor(spdef2) + Math.floor(spe2);
508
+
509
+ var L0 = ["hp1", "atk1", "def1", "spatk1", "spdef1", "spe1", "bs1"];
510
+ var L1 = ["hp2", "atk2", "def2", "spatk2", "spdef2", "spe2", "bs2"];
511
+ var L2 = [Math.floor(hp1), Math.floor(atk1), Math.floor(def1), Math.floor(spatk1), Math.floor(spdef1), Math.floor(spe1), Math.floor(bs1)];
512
+ var L3 = [Math.floor(hp2), Math.floor(atk2), Math.floor(def2), Math.floor(spatk2), Math.floor(spdef2), Math.floor(spe2), Math.floor(bs2)];
513
+ var L4 = []
514
+ var L5 = []
515
+ for (i = 0; i < L0.length; i++) {
516
+ L4.push(Math.max(L2[i], L3[i]) - Math.min(L2[i], L3[i]))
517
+ }
518
+
519
+ //Color of stats
520
+ for (i = 0; i < L1.length; i++) {
521
+ if (L2[i] < L3[i]) {
522
+ document.getElementById(L0[i]).style.color = "red";
523
+ document.getElementById(L1[i]).style.color = "green";
524
+ L5.push(" (+" + L4[i] + ")")
525
+ L4[i] = " (-" + L4[i] + ")";
526
+ } else if (L2[i] > L3[i]) {
527
+ document.getElementById(L1[i]).style.color = "red";
528
+ document.getElementById(L0[i]).style.color = "green";
529
+ L5.push(" (-" + L4[i] + ")")
530
+ L4[i] = " (+" + L4[i] + ")";
531
+ } else {
532
+ document.getElementById(L1[i]).style.color = "orange";
533
+ document.getElementById(L0[i]).style.color = "orange";
534
+ L4[i] = " (0)"
535
+ L5.push(" (0)");
536
+ }
537
+ document.getElementById(L0[i]).innerHTML = L0[i].slice(-1) + ": " + L2[i];
538
+ document.getElementById(L1[i]).innerHTML = L1[i].slice(-1) + ": " + L3[i];
539
+ }
540
+
541
+ //Writting stat in HTML
542
+ if (mon1 == "shedinja" || mon2 == "shedinja") {
543
+ document.getElementById("hp1").innerHTML = "HP: 1 (0)"
544
+ document.getElementById("hp1").style.color = "orange";
545
+
546
+ document.getElementById("hp2").innerHTML = "HP: 1 (0)";
547
+ document.getElementById("hp2").style.color = "orange";
548
+ } else {
549
+ document.getElementById("hp1").innerHTML = "HP: " + Math.floor(hp1) + L4[0];
550
+ document.getElementById("hp2").innerHTML = "HP: " + Math.floor(hp2) + L5[0];
551
+ }
552
+ document.getElementById("atk1").innerHTML = "ATK: " + Math.floor(atk1) + L4[1];
553
+ document.getElementById("def1").innerHTML = "DEF: " + Math.floor(def1) + L4[2];
554
+ document.getElementById("spatk1").innerHTML = "SPE.ATK: " + Math.floor(spatk1) + L4[3];
555
+ document.getElementById("spdef1").innerHTML = "SPE.DEF: " + Math.floor(spdef1) + L4[4];
556
+ document.getElementById("spe1").innerHTML = "SPEED: " + Math.floor(spe1) + L4[5];
557
+ document.getElementById("bs1").innerHTML = "TOTAL: " + Math.floor(bs1) + L4[6];
558
+
559
+ document.getElementById("atk2").innerHTML = "ATK: " + Math.floor(atk2) + L5[1];
560
+ document.getElementById("def2").innerHTML = "DEF: " + Math.floor(def2) + L5[2];
561
+ document.getElementById("spatk2").innerHTML = "SPE.ATK: " + Math.floor(spatk2) + L5[3];
562
+ document.getElementById("spdef2").innerHTML = "SPE.DEF: " + Math.floor(spdef2) + L5[4];
563
+ document.getElementById("spe2").innerHTML = "SPEED: " + Math.floor(spe2) + L5[5];
564
+ document.getElementById("bs2").innerHTML = "TOTAL: " + Math.floor(bs2) + L5[6];
565
+
566
+ //Abilities of fused mons
567
+ if (abilitySwap.includes(mon1)) {
568
+ [mon1abilities[0], mon1abilities[1]] = [mon1abilities[1], mon1abilities[0]];
569
+ }
570
+ if (abilitySwap.includes(mon2)) {
571
+ [mon2abilities[0], mon2abilities[1]] = [mon2abilities[1], mon2abilities[0]];
572
+ }
573
+ var abres1 = [...new Set(fusAb(mon1abilities, mon2abilities))];
574
+ var abres2 = [...new Set(fusAb(mon2abilities, mon1abilities))];
575
+
576
+ //Type of fused mons
577
+ var fmonres1 = fusType(mon1types, mon2types);
578
+ var fmonres2 = fusType(mon2types, mon1types);
579
+
580
+ //Types effectiveness
581
+ if (typeComp > 0) {
582
+ c = document.getElementsByClassName('monweak');
583
+ for (b = 0; b < c.length; b++) {
584
+ defaultValue = c[b].getAttribute('data-default');
585
+ if (defaultValue) {
586
+ c[b].innerText = defaultValue;
587
+ }
588
+ }
589
+ }
590
+
591
+ tyeffid1 = typeId(fmonres1);
592
+ tyeffid2 = typeId(fmonres1);
593
+
594
+ for (var i = 0; i < typeName.length; i++) {
595
+ result1[i] = (types[i][tyeffid1[0]] * types[i][tyeffid1[1]]);
596
+ }
597
+
598
+ for (var i = 0; i < typeName.length; i++) {
599
+ var image = new Image()
600
+ image.src = 'Types/' + typeName[i] + ".png";
601
+
602
+ if (result1[i] == 4) {
603
+ document.getElementById("weak14").appendChild(image);
604
+ }
605
+ if (result1[i] == 2) {
606
+ document.getElementById("weak12").appendChild(image);
607
+ }
608
+ if (result1[i] == 1) {
609
+ document.getElementById("weak11").appendChild(image);
610
+ }
611
+ if (result1[i] == 0.5) {
612
+ document.getElementById("weak105").appendChild(image);
613
+ }
614
+ if (result1[i] == 0.25) {
615
+ document.getElementById("weak1025").appendChild(image);
616
+ }
617
+ if (result1[i] == 0) {
618
+ document.getElementById("weak100").appendChild(image);
619
+ }
620
+ }
621
+
622
+ tyeffid1 = typeId(fmonres2);
623
+ tyeffid2 = typeId(fmonres2);
624
+
625
+ for (i = 0; i < typeName.length; i++) {
626
+ result2[i] = (types[i][tyeffid1[0]] * types[i][tyeffid1[1]]);
627
+ }
628
+
629
+ for (i = 0; i < typeName.length; i++) {
630
+ var image = new Image()
631
+ image.src = 'Types/' + typeName[i] + ".png";
632
+
633
+ if (result2[i] == 4) {
634
+ document.getElementById("weak24").appendChild(image);
635
+ }
636
+ if (result2[i] == 2) {
637
+ document.getElementById("weak22").appendChild(image);
638
+ }
639
+ if (result2[i] == 1) {
640
+ document.getElementById("weak21").appendChild(image);
641
+ }
642
+ if (result2[i] == 0.5) {
643
+ document.getElementById("weak205").appendChild(image);
644
+ }
645
+ if (result2[i] == 0.25) {
646
+ document.getElementById("weak2025").appendChild(image);
647
+ }
648
+ if (result2[i] == 0) {
649
+ document.getElementById("weak200").appendChild(image);
650
+ }
651
+ }
652
+
653
+ typeComp += 1;
654
+
655
+ document.getElementById("p1").src = "Types/" + fmonres1[0] + ".png";
656
+ if (fmonres1.length != 1 && (fmonres1.length == 2 && fmonres1[0] != fmonres1[1])) {
657
+ document.getElementById("p2").style.display = "inline-block";
658
+ document.getElementById("p2").src = "Types/" + fmonres1[1] + ".png";
659
+ } else {
660
+ document.getElementById("p2").style.display = "none";
661
+ }
662
+
663
+ document.getElementById("p3").src = "Types/" + fmonres2[0] + ".png";
664
+
665
+ if (fmonres2.length != 1 && (fmonres2.length == 2 && fmonres2[0] != fmonres2[1])) {
666
+ document.getElementById("p4").style.display = "inline-block";
667
+ document.getElementById("p4").src = "Types/" + fmonres2[1] + ".png";
668
+ } else {
669
+ document.getElementById("p4").style.display = "none";
670
+ }
671
+
672
+ //Picture of fusion (if inside CustomBattlers)
673
+ showFusion("pic1", pic1);
674
+ showFusion("pic2", pic2);
675
+
676
+ var listAb1 = "ABILITY: ";
677
+ for (i = 0; i < abres1.length; i++) {
678
+ listAb1 = listAb1 + abres1[i].charAt(0).toUpperCase() + abres1[i].slice(1) + " / ";
679
+ }
680
+ listAb1 = listAb1.slice(0, listAb1.length - 1);
681
+ listAb1 = listAb1.split("-").join(" ")
682
+ listAb1 = listAb1.split(" ")
683
+ for (i = 0, x = listAb1.length; i < x; i++) {
684
+ listAb1[i] = listAb1[i][0].toUpperCase() + listAb1[i].substr(1);
685
+ }
686
+ listAb1 = listAb1.join(" ").slice(0, -2);
687
+
688
+ document.getElementById("ab1").innerHTML = " ";
689
+ document.getElementById("ab1").innerHTML = listAb1;
690
+
691
+ var listAb2 = "ABILITY: ";
692
+ for (i = 0; i < abres2.length; i++) {
693
+ listAb2 = listAb2 + abres2[i].charAt(0).toUpperCase() + abres2[i].slice(1) + " / ";
694
+ }
695
+ listAb2 = listAb2.slice(0, listAb2.length - 1);
696
+ listAb2 = listAb2.split("-").join(" ")
697
+ listAb2 = listAb2.split(" ")
698
+ for (i = 0, x = listAb2.length; i < x; i++) {
699
+ listAb2[i] = listAb2[i][0].toUpperCase() + listAb2[i].substr(1);
700
+ }
701
+ listAb2 = listAb2.join(" ").slice(0, -2);
702
+ document.getElementById("ab2").innerHTML = " ";
703
+ document.getElementById("ab2").innerHTML = listAb2;
704
+
705
+ /*
706
+ //Fusion is already in Showdown or not
707
+ if (listfusion.includes(fmon1.toLowerCase() + "/" + fmon2.toLowerCase())) {
708
+ document.getElementById("IG1").style.color = "green";
709
+ document.getElementById("IG1").innerHTML = "In Showdown";
710
+ } else {
711
+ document.getElementById("IG1").style.color = "red";
712
+ document.getElementById("IG1").innerHTML = "Not in Showdown";
713
+ }
714
+
715
+ if (listfusion.includes(fmon2.toLowerCase() + "/" + fmon1.toLowerCase())) {
716
+ document.getElementById("IG2").style.color = "green";
717
+ document.getElementById("IG2").innerHTML = "In Showdown";
718
+ } else {
719
+ document.getElementById("IG2").style.color = "red";
720
+ document.getElementById("IG2").innerHTML = "Not in Showdown";
721
+ }
722
+ */
723
+
724
+ document.getElementById("r1").disabled = false
725
+ document.getElementById("r2").disabled = false
726
+ document.getElementById("r3").disabled = false
727
+ document.getElementById("random").disabled = false
728
+
729
+ //Post first fusion
730
+ if (saveInit >= 0) {
731
+
732
+ //Fusion w/o using "Next" or "Previous", otherwise it doesn't add said fusion in saves
733
+ if (!saveBtn) {
734
+
735
+ if (!(saveIndex == (saves.length)-1)) {
736
+ saves.splice(saveIndex + 1)
737
+ }
738
+ saves.push([(document.getElementById("fname1")).value,(document.getElementById("fname2")).value]);
739
+ saveIndex += 1
740
+ }
741
+
742
+ //Disable "Previous" if first fusion
743
+ if (saveIndex > 0) {
744
+ document.getElementById("previous").disabled = false
745
+ } else {
746
+ document.getElementById("previous").disabled = true
747
+ }
748
+
749
+ //Disable "Next" if last fusion
750
+ if (saveIndex < (saves.length)-1) {
751
+ document.getElementById("next").disabled = false
752
+ } else {
753
+ document.getElementById("next").disabled = true
754
+ }
755
+
756
+ //Reset
757
+ saveBtn = false
758
+
759
+ //First fusion
760
+ } else {
761
+ saves.push([(document.getElementById("fname1")).value,(document.getElementById("fname2")).value]);
762
+ saveInit += 1
763
+ }
764
+ }
765
+ }
766
+ }
767
+ }
768
+ }
769
+ }
770
+
771
+
772
+ function typeId(ftype) {
773
+ var ty1 = typeName.indexOf(ftype[0]);
774
+ if (ftype.length == 2) {
775
+ var ty2 = typeName.indexOf(ftype[1]);
776
+ } else {
777
+ var ty2 = 18;
778
+ }
779
+ return [ty1, ty2];
780
+ }
781
+
782
+ //Custom sprite fusion function
783
+ function showFusion(elementId, fusionId) {
784
+
785
+ fusionUrl = "https://raw.githubusercontent.com/Aegide/custom-fusion-sprites/main/CustomBattlers/" + fusionId;
786
+
787
+ if (doesImageExists(fusionUrl)) {
788
+ document.getElementById(elementId).src = fusionUrl;
789
+ }
790
+ else {//Screenshot of autogen pokemon
791
+ fallbackFusionRepository = "https://raw.githubusercontent.com/Aegide/autogen-fusion-sprites/master/Battlers/"
792
+ headId = fusionId.split(".")[0];
793
+ fallbackFusionUrl = fallbackFusionRepository + headId + "/" + fusionId;
794
+
795
+ document.getElementById(elementId).src = fallbackFusionUrl;
796
+ }
797
+ }
798
+
799
+ //Error detection
800
+ function doesImageExists(imageUrl) {
801
+ var http = new XMLHttpRequest();
802
+ http.open('HEAD', imageUrl, false);
803
+ http.send();
804
+ return http.status != 404;
805
+ }
806
+
807
+ //Picks the first option from the input datalist
808
+ function outputClosest(mon) {
809
+ var saveWrite = mon
810
+ mon = mon[0].toUpperCase() + mon.substring(1)
811
+ for (var i = 0; i < ids.length; i++) {
812
+ if (ids[i][0].substring(0, mon.length) == mon) {
813
+ return ids[i][0]
814
+ }
815
+ }
816
+ return saveWrite
817
+ }
818
+
819
+ //Verify inputs on 'Enter' press (and soon too 'Fuse' button)
820
+ function verifInputs() {
821
+ var i = 0
822
+ var bx1 = nameCheck(box1.value[0].toUpperCase() + box1.value.substring(1))
823
+ var bx2 = nameCheck(box2.value[0].toUpperCase() + box2.value.substring(1))
824
+ var bx3 = nameCheck(box3.value[0].toUpperCase() + box3.value.substring(1))
825
+ var boxbool1 = false
826
+ var boxbool2 = false
827
+ while (i < ids.length) {
828
+ if (ids[i].includes(bx1)) {
829
+ var boxbool1 = true
830
+ }
831
+ if (ids[i].includes(bx2)) {
832
+ var boxbool2 = true
833
+ }
834
+ i += 1
835
+ }
836
+ if (boxbool1 == true && boxbool2 == true) {
837
+ event.preventDefault();
838
+ document.getElementById("button").click();
839
+ } else if (boxbool1 == false && boxbool2 == false) {
840
+ box1.value = ""
841
+ box2.value = ""
842
+ alert("Both pokemons were misspelled or aren't in the fangame!")
843
+ } else if (boxbool1 == false) {
844
+ box1.value = ""
845
+ alert("The first pokemon was misspelled or isn't in the fangame!")
846
+ } else if (boxbool2 == false) {
847
+ box2.value = ""
848
+ alert("The second pokemon misspelled or isn't in the fangame!")
849
+ }
850
+ }
851
+
852
+ //Change the pokemon's name if exception (Giratina-origin, Aegislash-shield...)
853
+ function nameCheck(mon) {
854
+ if (nameFix.includes(mon.toLowerCase())) {
855
+ var val = nameException[nameFix.indexOf(mon.toLowerCase())]
856
+ val = val[0].toUpperCase() + val.substring(1)
857
+ } else if (nameException.includes(mon.toLowerCase())) {
858
+ var val = nameFix[nameException.indexOf(mon.toLowerCase())]
859
+ val = val[0].toUpperCase() + val.substring(1)
860
+ } else {
861
+ var val = mon;
862
+ }
863
+ return val
864
+ }
865
+
866
+ //Turns on/off the setting menu
867
+ function menuBtn() {
868
+ var menu = document.getElementById("menu")
869
+ if (menu.hidden == true) {
870
+ menu.hidden = false;
871
+ } else {
872
+ menu.hidden = true;
873
+ }
874
+ }
875
+
876
+ //Previous fusion inputed
877
+ function prevFuse() {
878
+ saveIndex -= 1
879
+ saveBtn = true
880
+ document.getElementById("fname1").value = nameCheck(saves[saveIndex][0])
881
+ document.getElementById("fname2").value = nameCheck(saves[saveIndex][1])
882
+
883
+ document.getElementById("button").click();
884
+ }
885
+
886
+ //Next fusion inputed
887
+ function nextFuse() {
888
+ saveIndex += 1
889
+ saveBtn = true
890
+ document.getElementById("fname1").value = nameCheck(saves[saveIndex][0])
891
+ document.getElementById("fname2").value = nameCheck(saves[saveIndex][1])
892
+
893
+ document.getElementById("button").click();
894
+ }
895
+
896
+ //Sort ids list by evolution line
897
+ function orderByEvo() {
898
+ var chk2 = []
899
+ var matches = document.querySelectorAll('input[type="checkbox"]:not(:checked)');
900
+ for (var i=0; i<matches.length; i++) {
901
+ chk2.push(matches[i].value)
902
+ }
903
+ if (chk2.length > 0 && JSON.stringify(chk) !== JSON.stringify(chk2)) {
904
+ ids2 = []
905
+ if (!chk2.includes("1")) {
906
+ for (var i = 0; i<ids.length; i++) {
907
+ if (ids[i][2]==1) {
908
+ ids2.push(ids[i])
909
+ }
910
+ }
911
+ }
912
+ if (!chk2.includes("2")) {
913
+ for (var i = 0; i<ids.length; i++) {
914
+ if (ids[i][2]==2) {
915
+ ids2.push(ids[i])
916
+ }
917
+ }
918
+ }
919
+ if (!chk2.includes("3")) {
920
+ for (var i = 0; i<ids.length; i++) {
921
+ if (ids[i][2]==3) {
922
+ ids2.push(ids[i])
923
+ }
924
+ }
925
+ }
926
+ if (!chk2.includes("4")) {
927
+ for (var i = 0; i<ids.length; i++) {
928
+ if (ids[i][2]==4) {
929
+ ids2.push(ids[i])
930
+ }
931
+ }
932
+ }
933
+ if (!chk2.includes("5")) {
934
+ for (var i = 0; i<ids.length; i++) {
935
+ if (ids[i][2]==5) {
936
+ ids2.push(ids[i])
937
+ }
938
+ }
939
+ }
940
+ chk = chk2
941
+ } else if (chk2.length == 0) {
942
+ ids2 = ids
943
+ }
944
+ return ids2
945
+ }
946
+
947
+ //Ability fusion function
948
+ function fusAb(mon1, mon2) {
949
+ var fabs = [];
950
+ var H0 = mon1[0][0].name;
951
+ if (mon1.length == 3 && mon1[2][1] == true) {
952
+ var H1 = mon1[1][0].name;
953
+ var HH = mon1[2][0].name;
954
+ } else if (mon1.length == 2 && mon1[1][1] == true) {
955
+ var HH = mon1[1][0].name;
956
+ } else if (mon1.length == 2 && mon1[1][1] == false) {
957
+ var H1 = mon1[1][0].name;
958
+ }
959
+
960
+ var B0 = mon2[0][0].name;
961
+ if (mon2.length == 3 && mon2[2][1] == true) {
962
+ var B1 = mon2[1][0].name;
963
+ var BH = mon2[2][0].name;
964
+ } else if (mon2.length == 2 && mon2[1][1] == true) {
965
+ var BH = mon2[1][0].name;
966
+ } else if (mon1.length == 2 && mon1[1][1] == false) {
967
+ var B1 = mon2[1][0].name;
968
+ }
969
+
970
+ //case H0/null/null + B0/null/null
971
+ //case H0/H1/null + B0/null/null
972
+
973
+ if ((mon1.length == 1 && mon2.length == 1) || (mon1.length == 2 && mon2.length == 1 && mon1[1][1] == false)) {
974
+ //[H0=B0] -> H0/null/null
975
+ if (H0 == B0) {
976
+ fabs.push(H0);
977
+ //[H0#B0] -> H0/B0/null
978
+ } else {
979
+ fabs.push(H0);
980
+ fabs.push(B0);
981
+ }
982
+
983
+ //case H0/null/HH + B0/null/null
984
+ //case H0/H1/HH + B0/null/null
985
+
986
+ } else if ((mon1.length == 2 && mon2.length == 1 && mon1[1][1] == true) || (mon1.length == 3 && mon2.length == 1)) {
987
+ //[H0=B0] -> H0/null/HH
988
+ if (H0 == B0) {
989
+ fabs.push(H0);
990
+ fabs.push(HH);
991
+ //[HH=B0] -> H0/B0/null
992
+ } else if (HH == B0) {
993
+ fabs.push(H0);
994
+ fabs.push(B0);
995
+ //[H0#B0 && HH#B0] -> H0/B0/HH
996
+ } else {
997
+ fabs.push(H0);
998
+ fabs.push(B0);
999
+ fabs.push(HH);
1000
+ }
1001
+
1002
+ //case H0/null/null + B0/null/BH
1003
+ //case H0/H1/null + B0/null/BH
1004
+ } else if ((mon1.length == 1 && mon2.length == 2 && mon2[1][1] == true) || (mon1.length == 2 && mon2.length == 2 && mon1[1][1] == false && mon2[1][1] == true)) {
1005
+ //[H0=B0] -> H0/null/null
1006
+ if (H0 == B0) {
1007
+ fabs.push(H0);
1008
+ //[H0#B0] -> H0/B0/null
1009
+ } else {
1010
+ fabs.push(H0);
1011
+ fabs.push(B0);
1012
+ }
1013
+
1014
+ //case H0/null/HH + B0/null/BH
1015
+ //case H0/H1/HH + B0/null/BH
1016
+ } else if ((mon2.length == 2 && mon2.length == 2 && mon1[1][1] == true && mon2[1][1] == true) || (mon1.length == 3 && mon2.length == 2 && mon2[1][1] == true)) {
1017
+ //[H0=B0] -> H0/null/HH
1018
+ if (H0 == B0) {
1019
+ fabs.push(H0);
1020
+ fabs.push(HH);
1021
+ }
1022
+ //[HH=B0] -> H0/B0/null
1023
+ else if (HH == B0) {
1024
+ fabs.push(H0);
1025
+ fabs.push(B0);
1026
+ }
1027
+ //[H0#B0 && HH#B0] -> H0/B0/HH
1028
+ else {
1029
+ fabs.push(H0);
1030
+ fabs.push(B0);
1031
+ fabs.push(HH);
1032
+ }
1033
+
1034
+ //case H0/null/null + B0/B1/null
1035
+ //case H0/H1/null + B0/B1/null
1036
+
1037
+ } else if ((mon1.length == 1 && mon2.length == 2 && mon2[1][1] == false) || (mon1.length == 2 && mon2.length == 2 && mon1[1][1] == false && mon2[1][1] == false)) {
1038
+ //[H0=B1] -> H0/B0/null
1039
+ if (H0 == B1) {
1040
+ fabs.push(H0);
1041
+ fabs.push(B0);
1042
+ //[H0#B1] -> H0/B1/null
1043
+ } else {
1044
+ fabs.push(H0);
1045
+ fabs.push(B1);
1046
+ }
1047
+
1048
+ //case H0/null/HH + B0/B1/null
1049
+ //case H0/H1/HH + B0/B1/null
1050
+
1051
+ } else if ((mon1.length == 2 && mon2.length == 2 && mon1[1][1] == true && mon2[1][1] == false) || (mon1.length == 3 && mon2.length == 2 && mon2[1][1] == false)) {
1052
+ //[H0=B1] -> H0/B0/HH
1053
+ if (H0 == B1) {
1054
+ fabs.push(H0);
1055
+ fabs.push(B0);
1056
+ fabs.push(HH);
1057
+ //[HH=B1] -> H0/B1/null
1058
+ } else if (HH == B1) {
1059
+ fabs.push(H0);
1060
+ fabs.push(B1);
1061
+ //[H0#B1 && HH#B1] -> H0/B0/HH
1062
+ } else {
1063
+ fabs.push(H0);
1064
+ fabs.push(B1);
1065
+ fabs.push(HH);
1066
+ }
1067
+
1068
+ //case H0/null/null + B0/B1/BH
1069
+ //case H0/H1/null + B0/B1/BH
1070
+
1071
+ } else if ((mon1.length == 1 && mon2.length == 3) || (mon1.length == 2 && mon2.length == 3 && mon1[1][1] == false)) {
1072
+ //[H0=B1]
1073
+ if (H0 == B1) {
1074
+ fabs.push(H0);
1075
+ fabs.push(B0);
1076
+ //[H0#B1]
1077
+ } else {
1078
+ fabs.push(H0);
1079
+ fabs.push(B1);
1080
+ }
1081
+
1082
+ //case H0/null/HH + B0/B1/BH
1083
+ //case H0/H1/HH + B0/B1/BH
1084
+
1085
+ } else if ((mon1.length == 2 && mon2.length == 3 && mon1[1][1] == true) || (mon1.length == 3 && mon2.length == 3)) {
1086
+ //[H0=B1] -> H0/B0/HH
1087
+ if (H0 == B1) {
1088
+ fabs.push(H0);
1089
+ fabs.push(B0);
1090
+ fabs.push(HH);
1091
+ //[HH=B1] -> H0/B1/null
1092
+ } else if (HH == B1) {
1093
+ fabs.push(H0);
1094
+ fabs.push(B1);
1095
+ //[H0#B1 && HH#B1] -> H0/B0/HH
1096
+ } else {
1097
+ fabs.push(H0);
1098
+ fabs.push(B1);
1099
+ fabs.push(HH);
1100
+ }
1101
+ }
1102
+ return fabs
1103
+ }
1104
+
1105
+
1106
+ //Type fusion function
1107
+ function fusType(mon1, mon2) {
1108
+ var fmon = []
1109
+
1110
+ //cas H0/null + B0/null [H0#B0] -> H0/B0
1111
+ if (mon1.length == 1 && mon2.length == 1) {
1112
+ if (mon1[0] != mon2[0]) {
1113
+ fmon.push(mon1[0]);
1114
+ fmon.push(mon2[0])
1115
+
1116
+ //cas H0/null + B0/null [H0=B0] -> H0/null
1117
+ } else {
1118
+ fmon.push(mon1[0]);
1119
+ }
1120
+ } else if (mon1.length == 2 && mon2.length == 1) {
1121
+
1122
+ //cas H0/H1 + B0/null [H0#B0] -> H0/B0
1123
+ if (mon1[0] != mon2[0]) {
1124
+ fmon.push(mon1[0]);
1125
+ fmon.push(mon2[0]);
1126
+ fmon.push(mon3[0]);
1127
+
1128
+ // Exception:
1129
+ // The body will provide its primary type
1130
+ // instead of the secondary
1131
+ // if the head is already providing that element.
1132
+
1133
+ //cas H0/H1 + B0/null [H0=B0] -> H0
1134
+ } else {
1135
+ fmon.push(mon1[0]);
1136
+ }
1137
+ } else if (mon1.length == 1 && mon2.length == 2) {
1138
+
1139
+ //cas H0/null + B0/B1 [H0#B1] -> H0/B1
1140
+ if (mon1[0] != mon2[1]) {
1141
+ fmon.push(mon1[0]);
1142
+ fmon.push(mon2[1]);
1143
+ fmon.push(mon3[2]);
1144
+
1145
+ //cas H0/null + B0/B1 [H0=B1] -> H0/B0
1146
+ } else {
1147
+ fmon.push(mon1[0])
1148
+ fmon.push(mon2[0])
1149
+ fmon.push(mon3[0]);
1150
+ }
1151
+
1152
+ //cas H0/H1 + B0/B1 [H0=B1] -> H0/B0
1153
+ } else if (mon1.length == 2 && mon2.length == 2) {
1154
+ if (mon1[0] == mon2[1]) {
1155
+ fmon.push(mon1[0]);
1156
+ fmon.push(mon2[0]);
1157
+ fmon.push(mon3[0]);
1158
+
1159
+ //cas H0/H1 + B0/B1 [H0#B1] -> H0/B1
1160
+ } else {
1161
+ fmon.push(mon1[0]);
1162
+ fmon.push(mon2[1]);
1163
+ fmon.push(mon3[2]);
1164
+ }
1165
+ }
1166
+ return fmon
1167
+ }