forked from Roukys/HHauto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHHAuto.user.js
13830 lines (13082 loc) · 627 KB
/
HHAuto.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 HaremHeroes Automatic++
// @namespace https://github.com/Roukys/HHauto
// @version 5.6.61
// @description Open the menu in HaremHeroes(topright) to toggle AutoControlls. Supports AutoSalary, AutoContest, AutoMission, AutoQuest, AutoTrollBattle, AutoArenaBattle and AutoPachinko(Free), AutoLeagues, AutoChampions and AutoStatUpgrades. Messages are printed in local console.
// @author JD and Dorten(a bit), Roukys, cossname, YotoTheOne, CLSchwab, deuxge
// @match http*://*.haremheroes.com/*
// @match http*://*.hentaiheroes.com/*
// @match http*://*.gayharem.com/*
// @match http*://*.comixharem.com/*
// @match http*://*.hornyheroes.com/*
// @grant GM_addStyle
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM.openInTab
// @license MIT
// @updateURL https://github.com/Roukys/HHauto/raw/main/HHAuto.user.js
// @downloadURL https://github.com/Roukys/HHauto/raw/main/HHAuto.user.js
// ==/UserScript==
//CSS Region
GM_addStyle('.HHAutoScriptMenu .switch { position: relative; display: inline-block; width: 34px; height: 20px }/* The switch - the box around the slider */ '
+'.HHAutoScriptMenu .switch input { display:none } /* Hide default HTML checkbox */ '
+'.HHAutoScriptMenu .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; -webkit-transition: .4s; transition: .4s; } /* The slider */'
+'.HHAutoScriptMenu .slider.round:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; -webkit-transition: .4s; transition: .4s; } '
+'.HHAutoScriptMenu input:checked + .slider { background-color: #2196F3; } '
+'.HHAutoScriptMenu input:focus + .slider { box-shadow: 0 0 1px #2196F3; } '
+'.HHAutoScriptMenu input:checked + .slider:before { -webkit-transform: translateX(10px); -ms-transform: translateX(10px); transform: translateX(10px); } '
+'.HHAutoScriptMenu .slider.round { border-radius: 14px; }/* Rounded sliders */ '
+'.HHAutoScriptMenu .slider.round:before { border-radius: 50%; }');
GM_addStyle('.HHAutoScriptMenu input:checked + .slider.kobans { background-color: red; }'
+'.HHAutoScriptMenu input:not(:checked) + .slider.round.kobans:before { background-color: red }'
+'.HHAutoScriptMenu input:checked + .slider.round.kobans:before { background-color: white }')
GM_addStyle('#pInfo {padding-left:3px; z-index:1;white-space: pre;position: absolute;right: 5%; left:77%; height:auto; top:11%; overflow: hidden; border: 1px solid #ffa23e; background-color: rgba(0,0,0,.5); border-radius: 5px; font-size:9pt;}');
//GM_addStyle('span.HHMenuItemName {font-size: xx-small; line-height: 150%}');
//GM_addStyle('span.HHMenuItemName {font-size: smaller; line-height: 120%}');
GM_addStyle('span.HHMenuItemName {padding-bottom:2px; line-height:120%}');
GM_addStyle('div.optionsRow {display:flex; flex-direction:row; justify-content: space-between}'); //; padding:3px;
GM_addStyle('span.optionsBoxTitle {padding-left:5px}'); //; padding-bottom:2px
GM_addStyle('div.optionsColumn {display:flex; flex-direction:column; justify-content: space-between}'); //; padding:3px;
GM_addStyle('div.optionsBoxWithTitle {display:flex; flex-direction:column}');
GM_addStyle('img.iconImg {max-width:15px; height:15px}');
GM_addStyle('div.optionsBoxTitle {padding:5px 15px 0px 5px; height:15px; display:flex; flex-direction:row; justify-content:center; align-items:center;}'); //; padding:2px; padding-bottom:0px;
GM_addStyle('div.rowOptionsBox {margin:3px; padding:3px; font-size:smaller; display:flex; flex-direction:row; align-items:flex-start; border: 1px solid #ffa23e; border-radius: 5px}');
GM_addStyle('div.optionsBox {margin:3px; padding:3px; font-size:smaller; display:flex; flex-direction:column; border:1px solid #ffa23e; border-radius:5px}');
GM_addStyle('div.internalOptionsRow {display:flex; flex-direction:row; justify-content: space-between; align-items: flex-end}'); //; padding:3px;
GM_addStyle('div.imgAndObjectRow {display:flex; flex-direction:row; justify-content:flex-start; align-items:center}'); //; padding:3px;//class="internalOptionsRow" style="justify-content:flex-start; align-items:center"
GM_addStyle('div.labelAndButton {padding:3px; display:flex;flex-direction:column}');
GM_addStyle('div.HHMenuItemBox {padding:0.2em}');
GM_addStyle('div.HHMenuRow {display:flex; flex-direction:row; align-items:center; align-content:center; justify-content:flex-start}');
GM_addStyle('input.maxMoneyInputField {text-align:right; width:70px}');
GM_addStyle('.myButton {box-shadow: 0px 0px 0px 2px #9fb4f2; background:linear-gradient(to bottom, #7892c2 5%, #476e9e 100%); background-color:#7892c2; border-radius:10px; border:1px solid #4e6096; display:inline-block; cursor:pointer; color:#ffffff; font-family:Arial; font-size:8px; padding:3px 7px; text-decoration:none; text-shadow:0px 1px 0px #283966;}'
+'.myButton:hover { background:linear-gradient(to bottom, #476e9e 5%, #7892c2 100%); background-color:#476e9e; }'
+'.myButton:active { position:relative; top:1px;}');
GM_addStyle('.HHEventPriority {position: absolute;z-index: 500;background-color: black}');
GM_addStyle('.HHPopIDs {background-color: black;z-index: 500;position: absolute;margin-top: 25px}');
GM_addStyle('.tooltipHH:hover { cursor: help; position: relative; }'
+'.tooltipHH span.tooltipHHtext { display: none }');
GM_addStyle('#popup_message_league { border: #666 2px dotted; padding: 5px 20px 5px 5px; display: block; z-index: 1000; background: #e3e3e3; left: 0px; margin: 15px; width: 500px; position: absolute; top: 15px; color: black}');
GM_addStyle('#sliding-popups#sliding-popups { z-index : 1}');
//END CSS Region
function replaceCheatClick()
{
is_cheat_click=function(e) {
return false;
};
}
const thousandsSeparator = nThousand(11111).replace(/1+/g, '');
function nThousand(x) {
if (typeof x != 'number') {
x = 0;
}
return x.toLocaleString();
}
function addEventsOnMenuItems()
{
for (let i of Object.keys(HHStoredVars))
{
if (HHStoredVars[i].HHType !== undefined )
{
let menuID = HHStoredVars[i].customMenuID !== undefined?HHStoredVars[i].customMenuID:i.replace("HHAuto_"+HHStoredVars[i].HHType+"_","");
if ( HHStoredVars[i].valueType === "Long Integer")
{
document.getElementById(menuID).addEventListener("keyup",add1000sSeparator1);
}
if (HHStoredVars[i].events !== undefined )
{
for (let event of Object.keys(HHStoredVars[i].events))
{
document.getElementById(menuID).addEventListener(event,HHStoredVars[i].events[event]);
}
}
if (HHStoredVars[i].kobanUsing !== undefined && HHStoredVars[i].kobanUsing)
{
document.getElementById(menuID).addEventListener("change",preventKobanUsingSwitchUnauthorized);
}
if (HHStoredVars[i].menuType !== undefined && HHStoredVars[i].menuType === "checked")
{
document.getElementById(menuID).addEventListener("change",function (){setStoredValue(i,this.checked)});
}
}
}
}
function add1000sSeparator1()
{
var nToFormat = this.value;
this.value = add1000sSeparator(nToFormat);
}
function add1000sSeparator(nToFormat)
{
return nThousand(remove1000sSeparator(nToFormat));
}
function remove1000sSeparator(nToFormat)
{
return Number(nToFormat.replace(/\D/g, ''));
}
function getStorage()
{
return getStoredValue("HHAuto_Setting_settPerTab") === "true"?sessionStorage:localStorage;
}
function getStoredValue(inVarName)
{
return HHStoredVars.hasOwnProperty(inVarName)?getStorageItem(HHStoredVars[inVarName].storage)[inVarName]:undefined;
}
function deleteStoredValue(inVarName)
{
if (HHStoredVars.hasOwnProperty(inVarName))
{
getStorageItem(HHStoredVars[inVarName].storage).removeItem(inVarName);
}
}
function setStoredValue(inVarName, inValue)
{
if (HHStoredVars.hasOwnProperty(inVarName))
{
getStorageItem(HHStoredVars[inVarName].storage)[inVarName] = inValue;
}
}
function getCallerFunction()
{
return getCallerFunction.caller.name
}
function getCallerCallerFunction()
{
return getCallerCallerFunction.caller.caller.name
}
function getDSTOffset()
{
function stdTimezoneOffset()
{
var jan = new Date(0, 1);
var jul = new Date(6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}
var today = new Date();
function isDstObserved(today)
{
return today.getTimezoneOffset() < stdTimezoneOffset();
}
if (isDstObserved(today))
{
return -60;
}
else
{
return 0;
}
}
function getServerTS()
{
let sec_num = parseInt(getHHVars('server_now_ts'), 10);
const DST = new Date().getTimezoneOffset();
sec_num -= getDSTOffset() * 60;
let days = Math.floor(sec_num / 86400);
let hours = Math.floor(sec_num / 3600) % 24;
let minutes = Math.floor(sec_num / 60) % 60;
let seconds = sec_num % 60;
return {days:days,hours:hours,minutes:minutes,seconds:seconds};
}
function getSecondsLeftBeforeEndOfHHDay()
{
let HHEndOfDay = {days:0,hours:13,minutes:0,seconds:0};
let server_TS = getServerTS();
HHEndOfDay.days = server_TS.hours<HHEndOfDay.hours?server_TS.days:server_TS.days+1;
return (HHEndOfDay.days - server_TS.days)*86400 + (HHEndOfDay.hours - server_TS.hours)*3600 + (HHEndOfDay.minutes - server_TS.minutes)*60 + (HHEndOfDay.days - server_TS.days);
}
function getSecondsLeftBeforeNewCompetition()
{
let HHEndOfDay = {days:0,hours:13,minutes:30,seconds:0};
let server_TS = getServerTS();
HHEndOfDay.days = server_TS.hours<HHEndOfDay.hours?server_TS.days:server_TS.days+1;
return (HHEndOfDay.days - server_TS.days)*86400 + (HHEndOfDay.hours - server_TS.hours)*3600 + (HHEndOfDay.minutes - server_TS.minutes)*60 + (HHEndOfDay.days - server_TS.days);
}
function logHHAuto(...args)
{
let currDate = new Date();
var prefix = currDate.toLocaleString()+"."+currDate.getMilliseconds()+":"+getCallerCallerFunction();
var text;
var currentLoggingText;
var nbLines;
var maxLines = 500;
if (args.length === 1)
{
if (typeof args[0] === 'string' || args[0] instanceof String)
{
text = args[0];
}
else
{
text = JSON.stringify(args[0], null, 2);
}
}
else
{
text = JSON.stringify(args, null, 2);
}
currentLoggingText = getStoredValue("HHAuto_Temp_Logging")!==undefined?getStoredValue("HHAuto_Temp_Logging"):"reset";
//console.log("debug : ",currentLoggingText);
if (!currentLoggingText.startsWith("{"))
{
//console.log("debug : delete currentLog");
currentLoggingText={};
}
else
{
currentLoggingText = JSON.parse(currentLoggingText);
}
nbLines = Object.keys(currentLoggingText).length;
//console.log("Debug : Counting log lines : "+nbLines);
if( nbLines >maxLines)
{
var keys=Object.keys(currentLoggingText);
//console.log("Debug : removing old lines");
for(var i = 0; i < nbLines-maxLines; i++)
{
//console.log("debug delete : "+currentLoggingText[keys[i]]);
delete currentLoggingText[keys[i]];
}
}
let count=1;
let newPrefix = prefix;
while (currentLoggingText.hasOwnProperty(newPrefix) && count < 10)
{
newPrefix = prefix + "-" + count;
count++;
}
prefix=newPrefix;
console.log(prefix+":"+text);
currentLoggingText[prefix]=text;
setStoredValue("HHAuto_Temp_Logging", JSON.stringify(currentLoggingText));
}
function getHero()
{
if(unsafeWindow.Hero === undefined)
{
setTimeout(autoLoop, Number(getStoredValue("HHAuto_Temp_autoLoopTimeMili")))
//logHHAuto(window.wrappedJSObject)
}
//logHHAuto(unsafeWindow.Hero);
return unsafeWindow.Hero;
}
function getHHVars(infoSearched, logging = true)
{
let returnValue = unsafeWindow;
if (getHHScriptVars(infoSearched,false) !== null)
{
infoSearched = getHHScriptVars(infoSearched);
}
let splittedInfoSearched = infoSearched.split(".");
for (let i=0;i<splittedInfoSearched.length;i++)
{
if (returnValue[splittedInfoSearched[i]] === undefined)
{
if (logging)
{
logHHAuto("HH var not found : "+infoSearched+" ("+splittedInfoSearched[i]+" not defined).");
}
return null;
}
else
{
returnValue = returnValue[splittedInfoSearched[i]];
}
}
return returnValue;
}
function setHHVars(infoSearched,newValue)
{
let returnValue = unsafeWindow;
if (getHHScriptVars(infoSearched,false) !== null)
{
infoSearched = getHHScriptVars(infoSearched);
}
let splittedInfoSearched = infoSearched.split(".");
for (let i=0;i<splittedInfoSearched.length;i++)
{
if (returnValue[splittedInfoSearched[i]] === undefined)
{
logHHAuto("HH var not found : "+infoSearched+" ("+splittedInfoSearched[i]+" not defined).");
return -1;
}
else if ( i === splittedInfoSearched.length - 1)
{
returnValue[splittedInfoSearched[i]] = newValue;
return 0;
}
else
{
returnValue = returnValue[splittedInfoSearched[i]];
}
}
}
function getGirlsMap()
{
return unsafeWindow.GirlSalaryManager.girlsMap;
}
function getPage()
{
var ob = document.getElementById(getHHScriptVars("gameID"));
if(ob===undefined || ob === null)
{
logHHAuto("Unable to find page attribute, stopping script");
setStoredValue("HHAuto_Setting_master", "false");
setStoredValue("HHAuto_Temp_autoLoop", "false");
logHHAuto("setting autoloop to false");
throw new Error("Unable to find page attribute, stopping script.");
return "";
}
//var p=ob.className.match(/.*page-(.*) .*/i)[1];
let activitiesMainPage = 'activities';
var p=ob.getAttribute('page');
if (p==activitiesMainPage && $('h4.contests.selected').size()>0)
{
return "contests"
}
if (p==activitiesMainPage && $('h4.missions.selected').size()>0)
{
return "missions"
}
if (p==activitiesMainPage && $('h4.daily_goals.selected').size()>0)
{
return "daily_goals"
}
if (p==activitiesMainPage && $('h4.pop.selected').size()>0)
{
// if on Pop menu
var t;
var popList= $("div.pop_list")
if (popList.attr('style') !='display:none' )
{
t = 'main';
}
else
{
t=$(".pop_thumb_selected").attr("pop_id");
if (t === undefined)
{
var index = queryStringGetParam(window.location.search,'index');
if (index !== null)
{
addPopToUnableToStart(index,"Unable to go to Pop "+index+" as it is locked.");
removePopFromPopToStart(index);
t='main';
}
}
}
return "powerplace"+t
}
else
{
return p;
}
}
function queryStringGetParam(inQueryString, inParam)
{
let urlParams = new URLSearchParams(inQueryString);
return urlParams.get(inParam);
}
function url_add_param(url, param, value) {
if (url.indexOf('?') === -1) url += '?';
else url += '&';
return url+param+"="+value;
}
// Returns true if on correct page.
function gotoPage(page,inArgs,delay = -1)
{
var cp=getPage();
logHHAuto('going '+cp+'->'+page);
if (typeof delay != 'number')
{
delay = -1;
}
if (delay === -1 )
{
delay = randomInterval(300,500);
}
var togoto = undefined;
// get page path
switch(page)
{
case "home":
togoto = getHHScriptVars("gotoPageHome");
break;
case "activities":
togoto = getHHScriptVars("gotoPageActivities");
break;
case "harem":
togoto = getHHScriptVars("gotoPageHarem");
break;
case "map":
togoto = getHHScriptVars("gotoPageMap");
break;
case "pachinko":
togoto = getHHScriptVars("gotoPagePachinko");
break;
case "leaderboard":
togoto = getHHScriptVars("gotoPageLeaderboard");
break;
case "shop":
togoto = getHHScriptVars("gotoPageShop");
break;
case "quest":
togoto = getHHVars('Hero.infos.questing.current_url');
if (togoto.includes("world"))
{
logHHAuto("All quests finished, turning off AutoQuest!");
setStoredValue("HHAuto_Setting_autoQuest", false);
location.reload();
return false;
}
logHHAuto("Current quest page: "+togoto);
break;
case "pantheon":
togoto = getHHScriptVars("gotoPagePantheon");
break;
case "pantheon-pre-battle":
togoto = getHHScriptVars("gotoPagePantheonPreBattle");
break;
case "champions_map":
togoto = getHHScriptVars("gotoPageChampionsMap");
break;
case "season" :
togoto = getHHScriptVars("gotoPageSeason");
break;
case "season_arena" :
togoto = getHHScriptVars("gotoPageSeasonArena");
break;
case "club_champion" :
togoto = getHHScriptVars("gotoPageClubChampion");
break;
case "league-battle" :
togoto = getHHScriptVars("gotoPageLeagueBattle");
break;
case "troll-pre-battle" :
togoto = getHHScriptVars("gotoPageTrollPreBattle");
break;
case "event" :
togoto = getHHScriptVars("gotoPageEvent");
break;
case "clubs" :
togoto = getHHScriptVars("gotoPageClub");
break;
case "path-of-valor" :
togoto = getHHScriptVars("gotoPagePoV");
break;
case (page.match(/^\/champions\/[123456]$/) || {}).input:
togoto = page;
break;
case (page.match(/^\/harem\/\d+$/) || {}).input:
togoto = page;
break;
default:
logHHAuto("Unknown goto page request. No page \'"+page+"\' defined.");
}
if(togoto != undefined)
{
setLastPageCalled(togoto);
if (typeof inArgs === 'object' && Object.keys(inArgs).length > 0)
{
for (let arg of Object.keys(inArgs))
{
togoto = url_add_param(togoto, arg,inArgs[arg]);
}
}
setStoredValue("HHAuto_Temp_autoLoop", "false");
logHHAuto("setting autoloop to false");
logHHAuto('GotoPage : '+togoto+' in '+delay+'ms.');
setTimeout(function () {window.location = window.location.origin + togoto;},delay);
}
else
{
logHHAuto("Couldn't find page path. Page was undefined...");
setTimeout(function () {location.reload();},delay);
}
}
function setLastPageCalled(inPage)
{
//console.log("testingHome : setting to : "+JSON.stringify({page:inPage, dateTime:new Date().getTime()}));
setStoredValue("HHAuto_Temp_LastPageCalled", JSON.stringify({page:inPage, dateTime:new Date().getTime()}));
}
var proceedQuest = function () {
//logHHAuto("Starting auto quest.");
// Check if at correct page.
if (getPage() !== "quest") {
// Click on current quest to naviagte to it.
logHHAuto("Navigating to current quest.");
gotoPage("quest");
return;
}
$("#popup_message close").click();
// Get the proceed button type
var proceedButtonMatch = $("#controls button:not([style*='display:none']):not([style*='display: none'])");
if (proceedButtonMatch.length === 0)
{
proceedButtonMatch = $("#controls button#free");
}
var proceedCostEnergy = Number($("#controls .cost span[cur='*']").text());
var proceedCostMoney = manageUnits($("#controls .cost span[cur='$']").text());
var proceedType = proceedButtonMatch.attr("id");
//console.log("DebugQuest proceedType : "+proceedType);
if (proceedButtonMatch.length === 0)
{
logHHAuto("Could not find resume button.");
return;
}
else if (proceedType === "free") {
logHHAuto("Proceeding for free.");
//setStoredValue"HHAuto_Temp_autoLoop", "false");
//logHHAuto("setting autoloop to false");
//proceedButtonMatch.click();
}
else if (proceedType === "pay") {
var energyCurrent = getHHVars('Hero.energies.quest.amount');
var moneyCurrent = getHHVars('Hero.infos.soft_currency');
let payType = $("#controls .cost span[cur]:not([style*='display:none']):not([style*='display: none'])").attr('cur');
//console.log("DebugQuest payType : "+payType);
if (payType === "*")
{
//console.log("DebugQuest payType : "+payType+" for : "+proceedCostEnergy);
if(proceedCostEnergy <= energyCurrent)
{
// We have energy.
logHHAuto("Spending "+proceedCostEnergy+" Energy to proceed.");
}
else
{
logHHAuto("Quest requires "+proceedCostEnergy+" Energy to proceed.");
setStoredValue("HHAuto_Temp_questRequirement", "*"+proceedCostEnergy);
return;
}
}
else if (payType === "$")
{
//console.log("DebugQuest payType : "+payType+" for : "+proceedCostMoney);
if(proceedCostMoney <= moneyCurrent)
{
// We have money.
logHHAuto("Spending "+proceedCostMoney+" Money to proceed.");
}
else
{
logHHAuto("Spending "+proceedCostMoney+" Money to proceed.");
setStoredValue("HHAuto_Temp_questRequirement", "$"+proceedCostMoney);
return;
}
}
//proceedButtonMatch.click();
//setStoredValue("HHAuto_Temp_autoLoop", "false");
//logHHAuto("setting autoloop to false");
}
else if (proceedType === "use_item") {
logHHAuto("Proceeding by using X" + Number($("#controls .item span").text()) + " of the required item.");
//proceedButtonMatch.click();
//setStoredValue("HHAuto_Temp_autoLoop", "false");
//logHHAuto("setting autoloop to false");
}
else if (proceedType === "battle") {
logHHAuto("Quest need battle...");
setStoredValue("HHAuto_Temp_questRequirement", "battle");
// Proceed to battle troll.
//proceedButtonMatch.click();
//setStoredValue("HHAuto_Temp_autoLoop", "false");
//logHHAuto("setting autoloop to false");
}
else if (proceedType === "end_archive") {
logHHAuto("Reached end of current archive. Proceeding to next archive.");
//setStoredValue("HHAuto_Temp_autoLoop", "false");
//logHHAuto("setting autoloop to false");
//proceedButtonMatch.click();
}
else if (proceedType === "end_play") {
logHHAuto("Reached end of current play. Proceeding to next play.");
//setStoredValue("HHAuto_Temp_autoLoop", "false");
//logHHAuto("setting autoloop to false");
//proceedButtonMatch.click();
}
else {
logHHAuto("Could not identify given resume button.");
setStoredValue("HHAuto_Temp_questRequirement", "unknownQuestButton");
return;
}
setStoredValue("HHAuto_Temp_autoLoop", "false");
logHHAuto("setting autoloop to false");
setTimeout(function ()
{
proceedButtonMatch.click();
setStoredValue("HHAuto_Temp_autoLoop", "true");
logHHAuto("setting autoloop to true");
setTimeout(autoLoop,randomInterval(500,800));
},randomInterval(500,800));
//setTimeout(function () {location.reload();},randomInterval(800,1500));
};
/**
* Recieves a list of mission objects and returns the mission object to use.
* A mission object looks similar to this :-
* Eg 1: {"id_member_mission":"256160093","id_mission":"23","duration":"53","cost":"1","remaining_time":"-83057","rewards":[{"classList":{"0":"slot","1":"slot_xp"},"type":"xp","data":28},{"classList":{"0":"slot","1":"slot_SC"},"type":"money","data":277}]}
* Eg 2: {"id_member_mission":"256160095","id_mission":"10","duration":"53","cost":"1","remaining_time":"-81330","rewards":[{"classList":{"0":"slot","1":"slot_xp"},"type":"xp","data":28},{"classList":{"0":"slot","1":"rare"},"type":"item","data":{"id_item":"23","type":"gift","subtype":"0","identifier":"K3","rarity":"rare","value":"80","carac1":0,"carac2":0,"carac3":0,"endurance":0,"chance":0,"ego":0,"damage":0,"duration":0,"level_mini":"1","name":"Bracelet","Name":"Bracelet","ico":"https://content.haremheroes.com/pictures/items/K3.png","price_sell":5561,"count":1,"id_m_i":[]}}]}
* Eg 3: {"id_member_mission":"256822795","id_mission":"337","duration":"17172","cost":"144","remaining_time":null,"remaining_cost":"144","rewards":[{"classList":{"0":"slot","1":"slot_HC"},"type":"koban","data":11}]}
* Eg 1 has mission rewards of xp and money.
* Eg 2 has mission rewards of xp and item.
* Eg 3 has mission rewards of koban/hard_currency.
* cost is the koban price for instant complete.
*/
function getSuitableMission(missionsList)
{
var msn = missionsList[0];
for(var m in missionsList)
{
if (JSON.stringify(missionsList[m].rewards).includes("koban") && getStoredValue("HHAuto_Setting_autoMissionKFirst") === "true")
{
return missionsList[m];
}
if(Number(msn.duration) > Number(missionsList[m].duration))
{
msn = missionsList[m];
}
}
return msn;
}
// returns boolean to set busy
function doMissionStuff()
{
if(getPage() !== "missions")
{
logHHAuto("Navigating to missions page.");
gotoPage("activities",{tab:"missions"});
// return busy
return true;
}
else
{
logHHAuto("On missions page.");
let canCollect = getStoredValue("HHAuto_Setting_autoMissionCollect") ==="true" && $(".mission_button button:visible[rel='claim']").length >0 && getSecondsLeftBeforeNewCompetition() > 35*60 && getSecondsLeftBeforeNewCompetition() < (24*3600-5*60);
if (canCollect)
{
logHHAuto("Collecting finished mission's reward.");
$(".mission_button button:visible[rel='claim']").click();
gotoPage("activities",{tab:"missions"},1500);
return true;
}
// TODO: select new missions and parse reward data from HTML, it's there in data attributes of tags
var missions = [];
var allGood = true;
// parse missions
$(".mission_object").each(function(idx,missionObject){
var data = $.data(missionObject).d;
// Do not list completed missions
var toAdd=true;
if(data.remaining_time !== null){
// This is not a fresh mission
if(data.remaining_time > 0)
{
if ($('.finish_in_bar[style*="display:none"], .finish_in_bar[style*="display: none"]', missionObject).length === 0)
{
logHHAuto("Unfinished mission detected...("+data.remaining_time+"sec. remaining)");
setTimer('nextMissionTime',Number(data.remaining_time)+1);
allGood = false;
return;
}
else
{
allGood = false;
}
}
else
{
if (canCollect)
{
logHHAuto("Unclaimed mission detected...");
gotoPage("activities",{tab:"missions"},1500);
return true;
}
}
return;
}
data.missionObject = missionObject;
var rewards = [];
// set rewards
{
// get Reward slots
var slots = missionObject.querySelectorAll(".slot");
// traverse slots
$.each(slots,function(idx,slotDiv){
var reward = {};
// get slot class list
reward.classList = slotDiv.classList;
// set reward type
if(reward.classList.contains("slot_xp"))reward.type = "xp";
else if(reward.classList.contains("slot_soft_currency"))reward.type = "money";
else if(reward.classList.contains("slot_hard_currency"))reward.type = "koban";
else reward.type = "item";
// set value if xp
if(reward.type === "xp" || reward.type === "money" || reward.type === "koban")
{
// remove all non numbers and HTML tags
try{
reward.data = Number(slotDiv.innerHTML.replace(/<.*?>/g,'').replace(/\D/g,''));
}
catch(e){
logHHAuto("Catched error : Couldn't parse xp/money data : "+e);
logHHAuto(slotDiv);
}
}
// set item details if item
else if(reward.type === "item")
{
try{
reward.data = $.data(slotDiv).d;
}
catch(e){
logHHAuto("Catched error : Couldn't parse item reward slot details : "+e);
logHHAuto(slotDiv);
reward.type = "unknown";
}
}
rewards.push(reward);
});
}
data.rewards = rewards;
missions.push(data);
});
if(!allGood && canCollect)
{
logHHAuto("Something went wrong, need to retry in 15secs.");
setTimer('nextMissionTime',15);
return true;
}
logHHAuto("Missions parsed, mission list is:-");
logHHAuto(missions);
if(missions.length > 0)
{
logHHAuto("Selecting mission from list.");
var mission = getSuitableMission(missions);
logHHAuto("Selected mission:-");
logHHAuto(mission);
logHHAuto("Selected mission duration: "+mission.duration+"sec.");
var missionButton = $(mission.missionObject).find("button:visible").first();
logHHAuto("Mission button of type: "+missionButton.attr("rel"));
logHHAuto("Clicking mission button.");
missionButton.click();
gotoPage("activities",{tab:"missions"},1500);
setTimer('nextMissionTime',Number(mission.duration)+1);
}
else
{
logHHAuto("No missions detected...!");
// get gift
var ck = getStoredValue("HHAuto_Temp_missionsGiftLeft");
var isAfterGift = document.querySelector("#missions .after_gift").style.display === 'block';
if(!isAfterGift){
if(ck === 'giftleft')
{
logHHAuto("Collecting gift.");
deleteStoredValue("HHAuto_Temp_missionsGiftLeft");
document.querySelector(".end_gift button").click();
}
else{
logHHAuto("Refreshing to collect gift...");
setStoredValue("HHAuto_Temp_missionsGiftLeft","giftleft");
location.reload();
// is busy
return true;
}
}
var time = 0;
for(var e in unsafeWindow.HHTimers.timers){
try{if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes("#missions_counter"))
time=unsafeWindow.HHTimers.timers[e];
}
catch(e)
{
logHHAuto("Catched error : Could not parse mission timer : "+e);
}
}
if (time !== undefined)
{
time = time.remainingTime;
}
if(time === undefined)
{
//try again with different selector
for(e in unsafeWindow.HHTimers.timers){
try{if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes(".after_gift"))
time=unsafeWindow.HHTimers.timers[e];
}
catch(e)
{
logHHAuto("Catched error : Could not parse after gift timer : "+e);
}
}
if (time !== undefined)
{
time = time.remainingTime;
}
}
if(time === undefined){
logHHAuto("New mission time was undefined... Setting it manually to 10min.");
time = 10*60;
}
setTimer('nextMissionTime',Number(time)+1);
}
// not busy
return false;
}
}
function moduleDisplayPopID()
{
if ($('.HHPopIDs').length > 0) {return}
$('div.pop_list div[pop_id]').each(function() {
$(this).prepend('<div class="HHPopIDs">'+$(this).attr('pop_id')+'</div>');
});
}
function moduleDisplayContestsDeletion()
{
if($('.HHcontest').length > 0)
{
return
}
let contests = $('div.contest:not(.is_legendary)');
let lastContestId = parseInt(contests.last().attr('id_contest'));
let laterDayToCollect = lastContestId - getHHScriptVars("contestMaxDays");
contests.each(function()
{
const activeUntil = parseInt($(this).attr('id_contest')) - laterDayToCollect;
$('.shadow',$(this)).append('<div class="HHcontest">Deleted in '+activeUntil+' days</div>');
});
}
function moduleOldPathOfAttractionHide()
{
//https://nutaku.haremheroes.com/path-of-attraction.html"
let array = $('#path_of_attraction div.poa.container div.all-objectives .objective.completed');
if (array.length == 0) {
return
}
let lengthNeeded = $('.golden-block.locked').length > 0 ? 1 : 2;
for (let i = array.length - 1; i >= 0; i--) {
if ($(array[i]).find('.picked-reward').length == lengthNeeded) {
array[i].style.display = "none";
}
}
}
function modulePathOfAttractionHide()
{
if (getPage() === "event" && window.location.search.includes("tab=path_event") && getStoredValue("HHAuto_Setting_PoAMaskRewards") === "true")
{
let arrayz;
let nbReward;
let modified=false;
arrayz = $('.nc-poa-reward-pair:not([style*="display:none"]):not([style*="display: none"])');
if ($("#nc-poa-tape-blocker").length)
{
nbReward=1;
}
else
{
nbReward=2;
}
var obj;
if (arrayz.length > 0) {
for (var i2 = arrayz.length - 1; i2 >= 0; i2--) {
obj = $(arrayz[i2]).find('.nc-poa-reward-container.claimed');
if (obj.length >= nbReward) {
//console.log("scroll before : "+document.getElementById('rewards_cont_scroll').scrollLeft);
//console.log("width : "+arrayz[i2].offsetWidth);
$("#events .nc-panel-body .scroll-area")[0].scrollLeft-=arrayz[i2].offsetWidth;
//console.log("scroll after : "+document.getElementById('rewards_cont_scroll').scrollLeft);arrayz[i2].style.display = "none";
arrayz[i2].style.display = "none";
modified = true;
}
}
}
}
}
function getPoVRemainingTime()
{
const poVTimerRequest = `#pov_tab_container > div.pov-first-row > div.pov-timer.timer[${getHHScriptVars("PoVTimestampAttributeName")}]`;
if ( $(poVTimerRequest).length > 0 && (getSecondsLeft("PoVRemainingTime") === 0 || getStoredValue("HHAuto_Temp_PoVEndDate") === undefined) )
{
const poVTimer = Number($(poVTimerRequest).attr(getHHScriptVars("PoVTimestampAttributeName")));
setTimer("PoVRemainingTime",poVTimer);
setStoredValue("HHAuto_Temp_PoVEndDate",Math.ceil(new Date().getTime()/1000)+poVTimer);
}
}
function displayPoVRemainingTime()
{
const displayTimer = getStoredValue("HHAuto_Setting_showInfo") === "true";
if(getTimer("PoVRemainingTime") !== -1)
{
if ($("#HHAutoPoVTimer").length === 0)
{
if (displayTimer)
{
$('#homepage a[rel="path-of-valor"').prepend('<span style="position: absolute; top:6px;left:200px;opacity: 80%;background-color: black;font-size: small;" id="HHAutoPoVTimer"></span>')
}
}
else
{
if (! displayTimer)
{
$("#HHAutoPoVTimer")[0].remove();
}
}
if (displayTimer)
{
$("#HHAutoPoVTimer")[0].innerText = getTimeLeft("PoVRemainingTime");
}
}
else
{
if (getStoredValue("HHAuto_Temp_PoVEndDate") !== undefined)
{
setTimer("PoVRemainingTime",getStoredValue("HHAuto_Temp_PoVEndDate")-(Math.ceil(new Date().getTime())/1000));
}
}
}
function moduleSimPoVMaskReward()
{
var arrayz;
var nbReward;
let modified = false;
arrayz = $('.pov-tier:not([style*="display:none"]):not([style*="display: none"])');
//doesn sure about " .purchase-pov-pass"-button visibility
if ($('#pov_tab_container .pov-second-row .purchase-pov-pass:not([style*="display:none"]):not([style*="display: none"])').length)
{
nbReward = 1;