-
Notifications
You must be signed in to change notification settings - Fork 4
/
Neopets - Battledome Set Selector.user.js
1825 lines (1677 loc) · 61.7 KB
/
Neopets - Battledome Set Selector.user.js
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
// ==UserScript==
// @name Neopets - Battledome Set Selector (BD+) <MettyNeo>
// @description Adds a toolbar to define and select up to 5 different loadouts. can default 1 loadout to start as selected. Also adds other QoL battledome features, such as disabling battle animations and auto-selecting 1P opponent.
// @author Metamagic
// @version 2.8.4
// @icon https://i.imgur.com/RnuqLRm.png
// @match https://www.neopets.com/dome/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @downloadURL https://github.com/Mettymagic/np-userscripts/raw/main/Neopets%20-%20Battledome%20Set%20Selector.user.js
// @updateURL https://github.com/Mettymagic/np-userscripts/raw/main/Neopets%20-%20Battledome%20Set%20Selector.user.js
// @run-at document-start
// ==/UserScript==
// Trans rights are human rights ^^
// metty says hi
// You are free to modify this script for personal use but modified scripts must not be shared publicly without permission.
// Modify aspects of this script at your own risk as modifications that give an advantage are against the Neopets rules.
// Feel free to contact me at @mettymagic on discord for any questions or inquiries. ^^
const HIGHLIGHT_MAX_REWARDS = true //makes the victory box green tinted if you're maxed on items. set to false to disable
const ANIMATION_DELAY = 0 //delay (in ms) before skipping animations. 0 = no animation, -1 = disable animation skip
const HIDE_USELESS_BUTTONS = true //hides the useless chat/animation buttons
const IMPROVE_CHALLENGER_LIST = true //enables the 1P challenger list improvements, such as the favorites list and auto-selection.
const LOOT_DISPLAY = true //displays earned loot in the form of pretty progress bars
const INDEX_REDIRECT = true //redirects off the main index page to the fight page
const LOOSE_OBELISK_RESTRICTIONS = true //allows the script to be used in obelisk battles if you haven't done your 10 battles or if you haven't earned your 15 items. honor means nothing compared to convenience.
const MAX_NP = 50000
const MAX_ITEMS = 15
const MAX_PP = 200
//TO-DO:
// - give obelisk opponents own section in BD list
//==========
// constants
//==========
let firstLoad = true
//button colors in rgb
const red = [180,75,75]
const blue = [107,168,237]
const green = [123,199,88]
const yellow = [249,204,14]
const magenta = [179,89,212]
const gray = [99,99,99]
const colormap = [red,blue,green,magenta,yellow]
const nullset = {set:null, name:null, default:null}
const nullautofill = {turn1:null, turn2:null, default:null}
const ROW_COLORS = {
1:"#a9bad4",
2:"#cce9eb",
3:"#cae3cf",
4:"#e3cbc8",
5:"#9fb9cc",
6:"#d6cbc1",
7:"#e6e4d8",
8:"#dcd3e3"
}
//=====
// main
//=====
//index page - redirects
if(window.location.href.includes("/dome/index.phtml") || window.location.href == "https://www.neopets.com/dome/" || window.location.href.includes("/dome/?")) {
window.location.replace("https://www.neopets.com/dome/fight.phtml")
}
let difficulty = null //tracked for obelisk point calculation
let obeliskContribution = 0
let isTVW = false
//runs on page load
window.addEventListener("DOMContentLoaded", function() {
//arena page (battle)
if(window.location.href.includes("/dome/arena.phtml")) {
addArenaCSS()
//adds set selector bar once bd intro disappears
//the magic happens from there :)
const introObs = new MutationObserver(mutations => {
introbreak:
for(const mutation of mutations) {
for(const removed of mutation.removedNodes) {
if(removed.id === "introdiv") {
isTVW = isVoidOpponent() //plot stuff
difficulty = $("#p2hp")[0].innerHTML
addBar() //adds set bar
handleRewards() //deals with winning rewards
//removes buttons if bar isn't disabled and animations are disabled
if(HIDE_USELESS_BUTTONS && (!limitObelisk() && !is2Player()) && ANIMATION_DELAY >= 0) {
$("#skipreplay")[0].style.visibility = "hidden"
$("#chatbutton")[0].style.visibility = "hidden"
}
introObs.disconnect() //observation done
break introbreak
}
}
}
})
introObs.observe($("#arenacontainer #playground")[0], {childList: true})
}
//fight page (select)
else if(window.location.href.includes("/dome/fight.phtml") && IMPROVE_CHALLENGER_LIST) {
applyDefaultNPC()
applyDefaultPet()
addFightCSS()
addTableCollapse()
modifyTable()
addStep3Toggle()
//obelisk npc special case
let favobnpcs = GM_getValue("favobnpcs", [])
for(const id of favobnpcs) {
popObeliskFavorite(id)
}
}
})
//TVW stuff
const tvw_tag = "_tvw"
function isVoidOpponent() {
let url = $("#p2image")[0].style.backgroundImage.slice(4, -1).replace(/"/g, "")
let regex = new RegExp(`.*?dome\/npcs.*?_tvw\/.*`)
return regex.test(url)
}
//================
// create elements
//================
function addBar() {
let bar = document.createElement("div")
bar.id = "bdsetbar"
bar.classList.add("bdsetbar", "bdbartext")
bar.style.fontSize = "24px"
bar.innerHTML = "(waiting for battle to start)"
//place bar above status
let status = $("#statusmsg")[0]
status.parentNode.insertBefore(bar, status)
let autofilled = -1 //prevents autofilling twice in same round
//checks status bar for when turn is ready
const statusObs = new MutationObserver(mutations => {
if(status.textContent == "Plan your next move..."){
//populates the bar
if(firstLoad) {
bar.innerHTML = ""
fillBar(bar)
}
//after first load, skips animation if not obelisk
else if(!limitObelisk()){
skipAnimation()
}
if(autofilled < getRoundCount() && (!limitObelisk() && !is2Player())) {
autofilled = getRoundCount()
setDefault()
if(firstLoad) skipAnimation(true) //fuck neopets for this one frfr
}
firstLoad = false
}
})
statusObs.observe(status, {childList: true})
//checks hud for when battle is over
let hud = $("#arenacontainer #playground #gQ_scenegraph #hud")[0]
const hpObs = new MutationObserver(mutations => {
for(const mutation of mutations) {
//battle ends when someone reaches 0 hp
if(hud.children[5].innerHTML <= 0 || hud.children[6].innerHTML <= 0) {
let obelisktrack = GM_getValue("obelisktrack", {count:0, points:0, date:-1})
//resets tracked loot on new day
if(getDate() != GM_getValue("bdloottrack", {items:0, np:0, date:null}).date)
{
GM_deleteValue("bdloottrack")
GM_deleteValue("bdtvwtrack")
}
//resets obelisk data after 4 days (aka the duration of the war)
if(new Date().valueOf() - obelisktrack.date > 1000*60*60*24*4) GM_deleteValue("obelisktrack")
//skips final animation
if(!limitObelisk() && ANIMATION_DELAY >= 0) skipAnimation()
//tracks obelisk contribution
if(isObelisk()) {
//both hp = 0, tie
if(hud.children[5].innerHTML == 0 && hud.children[6].innerHTML == 0) obeliskContribution = difficulty * 0.5
//enemy hp 0, player win
if(hud.children[6].innerHTML == 0) obeliskContribution = difficulty * 1.0
//player hp is 0, either lose or draw
else if(hud.children[5].innerHTML == 0) obeliskContribution = difficulty * 0.2
obelisktrack.count += 1
obelisktrack.points += obeliskContribution
if(obelisktrack.date < 0) obelisktrack.date = new Date().valueOf()
GM_setValue("obelisktrack", obelisktrack)
}
hpObs.disconnect()
break
}
}
})
hpObs.observe(hud, {childList: true, subtree: true})
}
//checks to see if bar should be populated before doing that
function fillBar(bar) {
//script is disabled for obelisk once item limit hit
if(isObelisk()) {
if(!limitObelisk()) {
if(firstLoad) {
console.log("[BSS] Obelisk battle permitted, honor discarded.")
console.log("[BSS] Populating BSS bar.")
}
else console.log("[BSS] Refreshing BSS bar.")
populateBar(bar)
}
//hit item limit today, blocked
else {
console.log("[BSS] Obelisk battle detected, BSS denied to prevent advantage.")
bar.innerHTML = "<i>A true warrior enters the battlefield with honor.</i>\n<i><small>The Obelisk rejects those who require assistance in battle. Prove your faction's worth on your own.</small></i>"
}
}
//script is disabled for 2p
else if(is2Player()) {
console.log("[BSS] 2P battle detected, BSS disabled.")
bar.innerHTML = "<i>A true warrior enters the battlefield with honor.</i><i><small>League regulations require you to be on your own in these battles. May fate be by your side.</small></i>"
}
else {
if(firstLoad) console.log("[BSS] Populating BSS bar.")
else console.log("[BSS] Refreshing BSS bar.")
populateBar(bar)
}
}
function populateBar(bar) {
//puts each sets container on the bar
let bdsetdata = getData("bdsets")
//in cases where setdata gets set to undefined/null by accident
if(!bdsetdata) {
setData("bdsets", clone([nullset,nullset,nullset,nullset,nullset]))
setData("bdautofill", nullautofill)
bdsetdata = getData("bdsets")
window.alert("BSS data corrupted, clearing sets.\nSorry for any inconvenience.")
}
bdsetdata.forEach((set, index) => {
//main container of a set
let container = document.createElement("div"), options = document.createElement("div")
//sets element classes
container.classList.add("bdsetcontainer", "bdbartext")
container.id = `bdsetc${index}`
container.style.backgroundColor = getHex(colormap[index])
let button = makeSetButton(set.name, set.set, index)
container.appendChild(button)
//adds option buttons to container
options.classList.add("bdsetoptioncontainer")
container.appendChild(options)
let save = makeSaveButton(index)
let opt = makeSettingsButton(index)
//adds label to container
let defc = document.createElement("div")
defc.style.textAlign = "right"
defc.style.marginTop = "2px"
switch(set.default) {
case "1":
defc.innerHTML = "<b>T1</b>"
break
case "2":
defc.innerHTML = "<b>T2</b>"
break
case "3":
defc.innerHTML = "<b>Default</b>"
break
}
options.appendChild(save)
options.appendChild(opt)
options.appendChild(defc)
//adds container to bar
bar.appendChild(container)
})
}
//main button to select set
function makeSetButton(name, itemurls, i) {
//null name means empty set
//button
let button = document.createElement("div")
button.classList.add("bdsetbutton", "bdbarclickable", "setbutton")
if(name != null) button.classList.add("activebutton")
else {
button.style.color = "#949494"
button.style.backgroundColor = "#DEDEDE"
}
if(itemurls != null) {
button.setAttribute("item1", itemurls[0])
button.setAttribute("item2", itemurls[1])
button.setAttribute("ability", itemurls[2])
button.addEventListener("click", function(){useSet(itemurls[0], itemurls[1], itemurls[2], i)})
}
//icons on top of button
let icons = document.createElement("div")
icons.classList.add("bdsetthumbnail")
if(itemurls != null) {
itemurls.forEach(url => {
let iconc = document.createElement("div")
iconc.classList.add("bdseticoncontainer")
if(url != null) iconc.innerHTML = `<img src='${url}' class='bdseticon'>`
icons.appendChild(iconc)
})
}
button.appendChild(icons)
//title on bottom of button
let text = document.createElement("div")
text.classList.add("bdbartext")
if(name == null) {
text.innerHTML = "(empty set)"
}
else text.innerHTML = name
button.appendChild(text)
return button
}
//button to save set
function makeSaveButton(i) {
let button = document.createElement("div")
button.classList.add("bdsetoption", "bdbarclickable", "bdbartext", "activeoption")
button.index = i
button.innerHTML = "Save Set"
button.addEventListener("click", function(){saveNewSet(i)})
return button
}
//button to set autofill options
function makeSettingsButton(i) {
let button = document.createElement("div")
button.classList.add("bdsetoption", "bdbarclickable", "bdbartext")
if(getData("bdsets", i).name != null) {
button.classList.add("activeoption")
button.addEventListener("click", function(){makeSettingsMenu(i)})
}
else {
button.style.color = "#4C5252"
button.style.backgroundColor = "#A5B5B5"
}
button.index = i
button.innerHTML = "Options"
return button
}
//one hell of a functiont hat uses JS to make the setting menu
function makeSettingsMenu(i) {
closeSettingsMenus() //closes other menus
let set = getData("bdsets", i)
let isEmptySet = JSON.stringify(set) == JSON.stringify(nullset)
//menu box
let menuc = document.createElement("div")
menuc.id = "bdsettingsmenu"
menuc.classList.add("settingswindow")
menuc.setAttribute("index", i)
let header = document.createElement("div")
header.style.display = "flex"
header.style.justifyContent = "space-between"
header.style.cursor = "pointer"
header.style.backgroundColor = getHex(colormap[i])
header.innerHTML = `<b>Set ${i+1} Options</b>`
header.style.padding = "4px"
let x = document.createElement("a")
x.innerHTML = "<b>x</b>"
x.style.marginRight = "4px"
x.addEventListener("click", function(){closeSettingsMenus(false, i)})
header.append(x)
let container = document.createElement("div")
container.classList.add("container-vertical")
menuc.appendChild(header)
menuc.appendChild(container)
//change name
let namec = document.createElement("div")
namec.classList.add("container-horizontal")
let nametext = document.createElement("div")
nametext.innerHTML = "Name:"
let namebox = document.createElement("INPUT")
namebox.id = "setname"
namebox.type = "text"
namebox.style.width = "65%"
if(set.name == null) namebox.value = "(empty set)"
else namebox.value = set.name
//adjusts name length to fit
namebox.addEventListener("focus", function(){namebox.setAttribute("old", namebox.value)})
namebox.addEventListener("blur", function(){
namebox.value = namebox.value.substring(0, 12);
if(namebox.value.length < 3) {
window.alert("ERROR: The name is too short! (3-12 characters)")
namebox.value = namebox.getAttribute("old")
}
})
if(isEmptySet) namebox.disabled = true
namec.appendChild(nametext)
namec.appendChild(namebox)
container.appendChild(namec)
//change autofill settings
let defc = document.createElement("div")
defc.classList.add("container-horizontal")
let deftext = document.createElement("div")
deftext.innerHTML = "Autofill:"
let defselect = createSelect(i, set)
if(isEmptySet) defselect.disabled = true
defc.appendChild(deftext)
defc.appendChild(defselect)
container.appendChild(defc)
//delete
let del = document.createElement("BUTTON")
del.innerHTML = "Delete Set"
del.style.marginRight = "0"
del.style.marginLeft = "auto"
del.style.width = "120px"
//disabled if empty set
if(isEmptySet) del.disabled = true
else {
del.addEventListener("click", function(){
if(deleteSet(i)) {
closeSettingsMenus(false, i)
window.alert(`Set ${i+1} successfully deleted.`)
}
})
}
container.appendChild(del)
let div = document.createElement("div")
div.style.height = "12px"
container.appendChild(div)
//close menu
let close = document.createElement("BUTTON")
close.innerHTML = "Save Changes"
close.addEventListener("click", function(){closeSettingsMenus(true, i)})
container.appendChild(close)
$("#arenacontainer")[0].parentElement.appendChild(menuc)
}
//saves and closes the setting menu
function closeSettingsMenus(save, i) {
let menu = $("#bdsettingsmenu")[0]
if(menu == undefined) return
//save changes
if(save) {
//check for differences
let oldset = getData("bdsets", i)
let name = $("#bdsettingsmenu #setname")[0].value
let autofill = $("#bdsettingsmenu #setautofill")[0].value
//if no differences, do nothing
if(name == oldset.name && autofill == oldset.default)
window.alert("No changes were saved.")
//if differences, update the set
else {
oldset.name = name
oldset.default = autofill
updateStoredSet(i, oldset, oldset.default == autofill)
}
}
//remove setting menu
menu.innerHTML = ""
menu.remove()
}
function createSelect(i, set) {
let afset = getData("bdautofill")
let defselect = document.createElement("SELECT")
defselect.id = "setautofill"
//options
let o1=document.createElement("OPTION"), o2=document.createElement("OPTION"), o3=document.createElement("OPTION"), o4=document.createElement("OPTION")
o1.value = null
o1.label = "Never"
o1.innerHTML = "Never"
o2.value = 1
o2.label = "First Turn"
o2.innerHTML = "First Turn"
if(afset.turn1 != null && afset.turn1 != i) o2.disabled = true
o3.value = 2
o3.label = "Second Turn"
o3.innerHTML = "Second Turn"
if(afset.turn2 != null && afset.turn2 != i) o3.disabled = true
o4.value = 3
o4.label = "Default"
o4.innerHTML = "Default"
if(afset.default != null && afset.default != i) o4.disabled = true
//adds options
defselect.appendChild(o1)
defselect.appendChild(o2)
defselect.appendChild(o3)
defselect.appendChild(o4)
//sets default value
defselect.value = set.default
console.log(defselect)
return defselect
}
//=====================
// button functionality
//=====================
//selects items from saved set
function useSet(item1, item2, ability, i) {
//clears slots before selecting
clearSlots()
let error = false //doesnt check rest of slots if error encountered
//item 1
if(item1 != null) error = selectSlot($("#arenacontainer #p1e1m")[0], item1)
//item 2
if(item2 != null && !error) {
//selects second available if 2 of same item chosen
if(item1 == item2) error = selectSlot($("#arenacontainer #p1e2m")[0], item2, 2)
else error = selectSlot($("#arenacontainer #p1e2m")[0], item2)
}
//ability
if(ability != null && !error) selectSlot($("#arenacontainer #p1am")[0], ability)
console.log(`[BSS] Set ${i} applied.`)
}
//save current selection to set
function saveNewSet(i) {
let oldset = getData("bdsets", i)
let newset = getCurrentItems()
//if the new set is empty
if(JSON.stringify(newset) == JSON.stringify([null,null,null])) {
window.alert("ERROR: You cannot save an empty set!")
return
}
//if there are no changes
else if(JSON.stringify(oldset.set) == JSON.stringify(newset)) {
window.alert("ERROR: There are no changes to save!")
return
}
else if(JSON.stringify(oldset) != JSON.stringify(nullset)){
if(!window.confirm("WARNING: Are you sure you wish to update your previous set?")) return
}
//creates new set object
let bdset = {set:newset, name:oldset.name, default:oldset.default}
//choose a name if no name
if(oldset.name == null) {
let n = prompt("Enter a name for the set:", `Weapon Set ${i+1}`)
if(n == null) return
while(n.length < 3 || n.length > 12) {
n = prompt("ERROR: Name must be between 3-12 chars!\nEnter a name for the set:", `Weapon Set ${i+1}`)
}
bdset.name = n
}
updateStoredSet(i, bdset)
console.log(`[BSS] Set slot ${i} saved.`)
updateBar()
}
function clearSlots() {
let e1 = $("#arenacontainer #p1e1m")[0]
e1.children[1].style.opacity = "1"
if(e1.classList.contains("selected")) e1.click()
let e2 = $("#arenacontainer #p1e2m")[0]
if(e2.classList.contains("selected")) e2.click()
e2.children[1].style.opacity = "1"
let a = $("#arenacontainer #p1am")[0]
a.children[1].style.opacity = "1"
if(a.classList.contains("selected")) {
a.click()
$("#arenacontainer #p1ability")[0].style.display = "none"
}
}
//=================
// helper functions
//=================
async function skipAnimation(ignoreDelay = false) {
let d = ANIMATION_DELAY
if(ignoreDelay) d = 0
if(d == 0) {
pressSkipButton()
if(firstLoad) console.log(`[BSS] First animation cancelled.`)
else console.log(`[BSS] Animation cancelled.`)
}
else if(d > 0) {
setTimeout(pressSkipButton, d)
setTimeout(() => {console.log(`[BSS] Animation skipped after ${d}ms.`)}, d)
}
}
function pressSkipButton() {
let button = $("#arenacontainer #skipreplay")[0]
button.click()
}
//selects the default set
function setDefault() {
let round = getRoundCount()
let autofill = getData("bdautofill")
if(round == 1 && autofill.turn1 != null) applyDefaultSet(autofill.turn1)
else if(round == 2 && autofill.turn2 != null) applyDefaultSet(autofill.turn2)
else if(autofill.default != null) applyDefaultSet(autofill.default)
}
function applyDefaultSet(i) {
let set = getData("bdsets", i).set
if(set == null) {
setData("bdautofill", nullautofill)
window.alert("BSS data corrupted, clearing autofill settings.\nSorry for any inconvenience.")
return
}
useSet(set[0],set[1],set[2], i)
console.log(`[BSS] Set ${i} autofilled.`)
}
//gets the selection id from an item's image url
//selects the nth occurrence of the item (defaults to first)
function getItemInfo(url, n=1) {
let info = null
let itemlist = $("#arenacontainer #p1equipment")[0].children[2].getElementsByTagName("li")
let count = 0
//iterates through each item in bd menu (even if its hidden it still exists)
for(const item of itemlist) { //each column
if(item.children[0].src == url) {
count++
if(count == n) {
info = {id:item.children[0].id, name:item.children[0].alt, node:item.children[0]}
break
}
}
}
return info
}
//for some reason ability list is a table whereas item lists arent??
function getAbilityInfo(url) {
let info = null
let table = $("#arenacontainer #p1ability")[0].children[2].children[0].getElementsByTagName("td")
for(const node of table) {
if(node.getAttribute("title") != null) {
//we found our node
let nodeurl = node.children[0].innerHTML.match(/img src=\"(.*?)\"/)[1]
//sometimes image links dont include 'https:' for some reason
if(!nodeurl.includes("https:")) {
nodeurl = "https:"+nodeurl
}
if(nodeurl == url) {
//ability on cd
if(node.children[0].classList.contains("cooldown")) info = -1
else info = {id: node.children[0].getAttribute("data-ability"), name: node.title, node:node}
break
}
}
}
return info
}
//sets a bd item to a saved slot's item
function selectSlot(slot, item, n=1) {
let isAbility = slot.id == "p1am"
let info = null
if(isAbility)
info = getAbilityInfo(item, n)
else
info = getItemInfo(item, n)
if(info == -1 && isAbility) {
window.alert("WARNING: The selected ability is on cooldown and has not been selected!")
return true
}
if(info == null) {
window.alert(`ERROR: Tried to assign item not equipped to pet!\nURL of missing item: ${item}`)
return true
}
let slotid = slot.id.slice(0, -1)
$(`#arenacontainer #${slotid}`)[0].value = info.id
//updates slot icon
slot.classList.add("selected")
slot.children[1].style.backgroundPosition = "0px 0px"
slot.children[1].style.backgroundSize = "60px 60px"
slot.children[1].style.backgroundImage = `url("${item}")`
if(!isAbility) {
slot.addEventListener("click", function(){ info.node.removeAttribute("style") })
info.node.style.display = "none"
}
return false
}
//remove and re-adds bar to update visuals
function updateBar() {
let bar = $("#bdsetbar")[0]
bar.innerHTML = ""
fillBar(bar)
}
//returns array of currently selected stuff from arena
function getCurrentItems() {
return [getItemURL($("#arenacontainer #p1e1m")[0]),
getItemURL($("#arenacontainer #p1e2m")[0]),
getItemURL($("#arenacontainer #p1am")[0], true)]
}
//==================
// challenger select
//==================
function applyDefaultPet() {
let name = GM_getValue("skiptopet")
if(name) {
let icon = $(`#bxlist > li > div.petThumbContainer[data-name="${name}"]`)
if(icon.length == 0) {
GM_deleteValue("skiptopet")
console.log(`[BD+] Pet ${name} not found, pet selection cleared.`)
}
else {
console.log(`[BD+] Skipping to Step 3 with pet ${name}.`)
//1ms delay added between clicks
icon[0].click()
setTimeout(()=>{$("#bdFightStep1 > div.nextStep").click()},1)
setTimeout(()=>{$("#bdFightStep2 > div.nextStep").click()},2)
}
}
}
function applyDefaultNPC() {
let npc = GM_getValue("defnpc")
let applyDefault = true //to prevent it from being applied multiple times
const obs = new MutationObserver(mutations => {
if($("#bdFightStep3").css("display") == "block" && applyDefault) {
if(npc) {
console.log("[BD+] Default challenger selected.")
$(`#npcTable tr.npcRow.favorite.default div.tough[data-tough="${npc.diff}"`)[0].click()
}
applyDefault = false
}
else {
applyDefault = true
}
})
obs.observe($("#bdFightStep3")[0], {attributes:true})
}
function addStep3Toggle() {
let div = document.createElement("div")
div.id = "step3toggle"
div.innerHTML = "Automatically select this pet for 1P"
let toggle = document.createElement("label")
toggle.classList.add("switch")
toggle.innerHTML = `<input type="checkbox"><span class="slider round"></span>`
if(GM_getValue("skiptopet")) toggle.querySelector("input").checked = true
//records pet name
toggle.addEventListener("click", (event)=>{
//overrides default behavior
event.stopPropagation()
event.preventDefault()
let toggled = !($("#step3toggle > label > input")[0].checked)
$("#step3toggle > label > input")[0].checked = toggled
if(toggled) {
let name = $(`#bdFightPetInfo > div.petInfoBox[style="display: block;"]`)[0].getAttribute("data-name")
GM_setValue("skiptopet", name)
console.log(`[BD+] Set to automatically select ${name} next time.`)
}
else {
GM_deleteValue("skiptopet")
console.log(`[BD+] Removed automatic pet selected.`)
}
})
//updates recorded pet name if pet is swapped
$("#bxlist")[0].addEventListener("click", (event) => {
if((event.target.tagName.toLowerCase() == "div" || event.target.tagName.toLowerCase() == "img") && $("#step3toggle > label > input")[0].checked) {
let name = $(`#bdFightPetInfo > div.petInfoBox[style="display: block;"]`)[0].getAttribute("data-name")
GM_setValue("skiptopet", name)
console.log(`[BD+] Set to automatically select ${name} next time.`)
}
})
div.appendChild(toggle)
$("#bdFightStep1")[0].appendChild(div)
}
function addTableCollapse() {
let collapse = document.createElement("div")
collapse.classList.add("npccollapse")
//starts collapsed if user has any favorites
if(GM_getValue("favnpcs", []).length > 0) {
$("#bdFightStep3UI > div.npcContainer")[0].classList.add("collapsed")
collapse.innerHTML = "▼"
}
else {
collapse.innerHTML = "▲"
collapse.style.display = "none"
}
//toggles between all and favorites on click
collapse.addEventListener("click", () => {
//expand
if($("#bdFightStep3UI > div.npcContainer")[0].classList.contains("collapsed")) {
$("#bdFightStep3UI > div.npcContainer")[0].classList.remove("collapsed")
$(".npccollapse")[0].innerHTML = "▲"
}
//retract
else {
$("#bdFightStep3UI > div.npcContainer")[0].classList.add("collapsed")
$(".npccollapse")[0].innerHTML = "▼"
}
//recalculate height - from page source code
let tableHeight = $("#npcTable").outerHeight();
$('#bdFight').css('min-height', tableHeight + 257);
let containerHeight = $('#bdFight').outerHeight();
$('#bdFightStepContainer').css('min-height', containerHeight + -60);
$('#bdFightStep3').css('min-height', containerHeight + -63);
$('#bdFightBorderExpansion').css('min-height', containerHeight + -263);
$('#bdFightBorderBottom').css('top', containerHeight + -18);
})
$("#domeTitle")[0].appendChild(collapse)
}
//sorts the "better" domes first
function getDomePriority(id) {
switch(id) {
case 1:
return 6
case 2:
return 3
case 3:
return 7
case 4:
return 2
case 5:
return 1
case 6:
return 5
case 7:
return 4
case 8:
return 0
default:
return 10
}
}
function getDifficulty(tr) {
return tr.querySelector("td.diff").getAttribute("data-diffs").replaceAll(",","").split(";").map(Number)
}
function compareDifficulty(a, b) {
let da = getDifficulty(a), db = getDifficulty(b)
for (let i = 0; i < 3; i++) {
let n = da[i] - db[i]
if(n != 0) return n
}
return 0
}
function modifyTable() {
//gets and sorts rows
let rows = Array.from($("#npcTable > tbody > tr.npcRow"))
rows.sort((a,b) => {
let t = getDomePriority(+a.getAttribute("data-domeid")) - getDomePriority(+b.getAttribute("data-domeid"))
if(t == 0) return compareDifficulty(a,b) //sorts by difficulties within its row
else return t
})
$("#npcTable > tbody")[0].innerHTML = ""
//modifies each row and adds it back
for(const row of rows) {
let newrow = modifyRow(row)
$("#npcTable > tbody")[0].appendChild(newrow)
}
}
function isObeliskNPC(tr) {
let style = tr.querySelector("td.image > div").getAttribute("style")
for(const tag of obelisktags){
if(style.includes(tag)) {
let regex = new RegExp(`.*?dome\/npcs.*?${tag}(\\d).*`)
let n = style.match(regex)[1]
return n
}
}
return false
}
function popObeliskFavorite(n) {
//add to favorites list
if(GM_getValue("favobnpcs", []).includes(n)) {
let list = Array.from($("#npcTable tr.npcRow:not(.favorite)")).filter((tr)=>{
let x = isObeliskNPC(tr)
return x == n
})
for(let tr of list) {
tr.classList.add("favorite")
}
}
//remove from favorites list
else {
let list = Array.from($("#npcTable tr.npcRow.favorite")).filter((tr)=>{
let x = isObeliskNPC(tr)
return x == n
})
for(let tr of list) {
tr.classList.remove("favorite")
}
}
}
function modifyRow(tr) {
//adds favorite button
let fav = document.createElement("div")
fav.classList.add("fav")
//updates favorite list on click
fav.addEventListener("click", (event) => {
const target = event.target || event.srcElement
const oppID = target.parentElement.getAttribute("data-oppid")
let favNPCs = GM_getValue("favnpcs", [])
//favorites list, sets default
if($("#bdFightStep3UI > div.npcContainer.collapsed").length > 0) {
//make new default
if(!target.parentElement.classList.contains("default")) {
//get toughness selected
let diff = target.parentElement.querySelector("div.tough.selected")?.getAttribute("data-tough")
if(!diff) window.alert("You must select a difficulty to set this challenger as your default!")
else {
//remove any other defaults
if($("tr.npcRow.favorite.default").length > 0) $("tr.npcRow.favorite.default")[0].classList.remove("default")
//sets new default
target.parentElement.classList.add("default")
GM_setValue("defnpc", {id:tr.getAttribute("data-oppid"), diff:diff})
console.log(`[BD+] NPC ID ${oppID} at difficulty ${diff} set as default.`)
}
}
//remove default
else {
target.parentElement.classList.remove("default")
GM_deleteValue("defnpc")
console.log(`[BD+] Default NPC removed.`)
}
}
else {
//remove as favorite
let n = target.parentElement.getAttribute("obelisk-id")
if(target.parentElement.classList.contains("favorite")) {
//special case for obelisk challenger
if(n) {
let favobnpcs = GM_getValue("favobnpcs", [])
let i = favobnpcs.indexOf(n);
if (i !== -1) {
favobnpcs.splice(i, 1);
}
GM_setValue("favobnpcs", favobnpcs)
popObeliskFavorite(n)
}
else {
let i = favNPCs.indexOf(oppID);
if (i !== -1) {
favNPCs.splice(i, 1);
}
GM_setValue("favnpcs", favNPCs)
target.parentElement.classList.remove("favorite")
//also removes as a default
if(target.parentElement.classList.contains("default")) {
target.parentElement.classList.remove("default")
GM_deleteValue("defnpc")
}
}
}