eileen12 / HaremHeroes Automatic

setTimeout(autoLoop, Number(sessionStorage.autoLoopTimeMili))

to

setTimeout(autoLoop, Number(sessionStorage.autoLoopTimeMili));
return ""

to

return "";
var togoto = undefined;

to

var togoto;
if(togoto != undefined)

to

if(togoto !== undefined)

If I find more I will add to this topic. These may help fix some errors that may or may not ever show themselves but I thought I may as well point them out.

var closestTime = undefined;

to

var closestTime;
if(worldPage == undefined)

to

if(worldPage === undefined)
console.log("No arena opponents found, storing nextArenaTime...")

to

console.log("No arena opponents found, storing nextArenaTime...");
console.log("battle price: "+battle_price+"P")

to

console.log("battle price: "+battle_price+"P");

Found this site after finding those remaining errors. The configure option is really neat with all the different options. Considering this site doesn't do a full check this may help in future bug prevention.

Full script free from errors (minus the ones that pop up for $ and the like) and end_play button fixed, as I noticed that the button when needing money or energy still didn't work at times.

EDITED By OUJS Admin

--- a.user.js	2018-07-17 00:05:16.215352417 -0600
+++ b.user.js	2018-07-17 00:06:33.351884738 -0600
@@ -20,7 +20,7 @@
 {
     if(unsafeWindow.Hero === undefined)
     {
-        setTimeout(autoLoop, Number(sessionStorage.autoLoopTimeMili))
+        setTimeout(autoLoop, Number(sessionStorage.autoLoopTimeMili));
         //console.log(window.wrappedJSObject)
     }
     return unsafeWindow.Hero;
@@ -43,7 +43,7 @@
     }
     catch(err)
     {
-        return ""
+        return "";
     }
 }
 
@@ -57,7 +57,7 @@
     else
     {
         console.log("Navigating to page: "+page);
-        var togoto = undefined;
+        var togoto;
         // get page path
         switch(page)
         {
@@ -84,7 +84,7 @@
             default:
                 console.log("Unknown goto page request. No page \'"+page+"\' defined.");
         }
-        if(togoto != undefined)
+        if(togoto !== undefined)
         {
             sessionStorage.autoLoop = "false";
             window.location = window.location.origin + togoto;
@@ -108,6 +108,8 @@
     var proceedCostEnergy = Number($("#controls .cost span[cur='*']").text());
     var proceedCostMoney = Number($("#controls .cost span[cur='$']").text().trim().replace(',', ''));
     var proceedType = proceedButtonMatch.attr("act");
+    var energyCurrent = getHero().infos.energy_quest;
+    var moneyCurrent = getHero().infos.soft_currency;
 
     if (proceedButtonMatch.length === 0) console.log("Could not find resume button.");
     else if (proceedType === "free") {
@@ -115,8 +117,6 @@
         proceedButtonMatch.click();
     }
     else if (proceedType === "pay") {
-        var energyCurrent = getHero().infos.energy_quest;
-        var moneyCurrent = getHero().infos.soft_currency;
         if(proceedCostEnergy <= energyCurrent)
         {
             // We have energy.
@@ -161,6 +161,28 @@
         proceedButtonMatch.click();
     }
     else if (proceedType === "end_play") {
+        if(proceedCostEnergy <= energyCurrent)
+        {
+            // We have energy.
+            console.log("Spending "+proceedCostEnergy+" Energy to proceed.");
+        }
+        else
+        {
+            console.log("Quest requires "+proceedCostEnergy+" Energy to proceed.");
+            sessionStorage.questRequirement = "*"+proceedCostEnergy;
+            return;
+        }
+        if(proceedCostMoney <= moneyCurrent)
+        {
+            // We have money.
+            console.log("Spending "+proceedCostMoney+" Money to proceed.");
+        }
+        else
+        {
+            console.log("Spending "+proceedCostEnergy+" Money to proceed.");
+            sessionStorage.questRequirement = "$"+proceedCostMoney;
+            return;
+        }
         console.log("Reached end of current play. Proceeding to next play.");
         sessionStorage.autoLoop = "false";
         proceedButtonMatch.click();
@@ -430,7 +452,7 @@
             });
             console.log("Salary fetched. Getting next fetch time");
             // In seconds
-            var closestTime = undefined;
+            var closestTime;
             var gMap = getGirlsMap();
             if(gMap === undefined)
             {
@@ -516,7 +538,7 @@
             return;
         }
         var worldPage = worldMap.get(sessionStorage.trollToFight);
-        if(worldPage == undefined)
+        if(worldPage === undefined)
         {
             console.log("ERROR! worldPage undefined for troll at: "+sessionStorage.trollToFight);
             return;
@@ -564,7 +586,7 @@
             var selbutton = $(".opponents_arena .sub_block button:contains('Select')");
             if(selbutton.length<1)
             {
-                console.log("No arena opponents found, storing nextArenaTime...")
+                console.log("No arena opponents found, storing nextArenaTime...");
                 var arenatime = 0;
                 for(var e in unsafeWindow.HHTimers.timers){
                     if(unsafeWindow.HHTimers.timers[e].$elm.selector.startsWith(".arena_refresh_counter"))
@@ -612,7 +634,7 @@
                 }
                 return;
             }
-            console.log("battle price: "+battle_price+"P")
+            console.log("battle price: "+battle_price+"P");
             if(currentPower >= battle_price)
             {
                 // We have the power.
@@ -682,6 +704,7 @@
             if(npach !== undefined || npach !== 0)
             {
                 Cookies.set('nextPachinkoTime',npach,{expires:new Date(new Date().getTime() + npach * 1000)});
+                console.log('Next free pachinko in : ' + Cookies.get('nextPachinkoTime') + ' secs');
             }
             else
             {
@@ -909,18 +932,15 @@
     }
     // Add UI buttons.
     var UIcontainer = $("#contains_all nav div[rel='content']");
-    UIcontainer.html('<div style="position: absolute;right: 18.66%; padding: 10px;width: inherit;text-align: center;display:flex;flex-direction:column;">'
-                     + '<span>AutoSal.</span><div><label class=\"switch\"><input id=\"autoSalaryCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'
-                     + '<span>AutoContest</span><div><label class=\"switch\"><input id=\"autoContestCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'
-                     + '<span>AutoMission</span><div><label class=\"switch\"><input id=\"autoMissionCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'
-                     +'<span>AutoQuest</span><div><label class=\"switch\"><input id=\"autoQuestCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'
-                     +'<span>AutoTrollBattle</span><div>\
-                     <label class=\"switch\"><input id=\"autoBattleCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label>\
-                     <select id=\"autoTrollSelector\"><option value=\"latest\">Latest</option></select>\
-                     </div>'
-                     +'<span>AutoArenaBattle</span><div><label class=\"switch\"><input id=\"autoArenaCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'
-                     +'<span>AutoPachinko(Free)</span><div><label class=\"switch\"><input id=\"autoFreePachinko\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'
-                     +'</div>'+UIcontainer.html());
+    UIcontainer.html('<div style="position: absolute;right: 18.66%; padding: 10px;width: inherit;text-align: center;display:flex;flex-direction:column;">'+
+                     '<span>AutoSal.</span><div><label class=\"switch\"><input id=\"autoSalaryCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'+
+                     '<span>AutoContest</span><div><label class=\"switch\"><input id=\"autoContestCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'+
+                     '<span>AutoMission</span><div><label class=\"switch\"><input id=\"autoMissionCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'+
+                     '<span>AutoQuest</span><div><label class=\"switch\"><input id=\"autoQuestCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'+
+                     '<span>AutoTrollBattle</span><div><label class=\"switch\"><input id=\"autoBattleCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label><select id=\"autoTrollSelector\"><option value=\"latest\">Latest</option></select></div>'+
+                     '<span>AutoArenaBattle</span><div><label class=\"switch\"><input id=\"autoArenaCheckbox\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'+
+                     '<span>AutoPachinko(Free)</span><div><label class=\"switch\"><input id=\"autoFreePachinko\" type=\"checkbox\"><span class=\"slider round\"></span></label></div>'+
+                     '</div>'+UIcontainer.html());
     // Add auto troll options
     var trollOptions = document.getElementById("autoTrollSelector");
     globalWorldMap.forEach(function(val,key){

Missed some errors. Which may be the entire cause of the pachinko, as well as others?, problem(s).

for(var e in unsafeWindow.HHTimers.timersListMin){
    if(unsafeWindow.HHTimers.timersListMin[e].$elm.selector.startsWith(".pachinko_change"))
        npach=unsafeWindow.HHTimers.timersListMin[e].remainingTime;
}

to

for(var e in unsafeWindow.HHTimers.timersListMin){
    if(unsafeWindow.HHTimers.timersListMin[e].$elm.selector.startsWith(".pachinko_change"))
    {
        npach=unsafeWindow.HHTimers.timersListMin[e].remainingTime;
    }
}
for(var e in unsafeWindow.HHTimers.timers){
    if(unsafeWindow.HHTimers.timers[e].$elm.selector.startsWith(".arena_refresh_counter"))
        arenatime=unsafeWindow.HHTimers.timers[e];
}

to

for(var e in unsafeWindow.HHTimers.timers){
    if(unsafeWindow.HHTimers.timers[e].$elm.selector.startsWith(".arena_refresh_counter"))
    {
        arenatime=unsafeWindow.HHTimers.timers[e];
    }
}
for(e in unsafeWindow.HHTimers.timers){
    if(unsafeWindow.HHTimers.timers[e].$elm[0].className.includes("contest_timer"))
        // get closest time
        if(!(unsafeWindow.HHTimers.timers[e].remainingTime>time))
            time=unsafeWindow.HHTimers.timers[e].remainingTime;
}

to

for(e in unsafeWindow.HHTimers.timers){
    if(unsafeWindow.HHTimers.timers[e].$elm[0].className.includes("contest_timer"))
    {
        // get closest time
        if(!(unsafeWindow.HHTimers.timers[e].remainingTime>time))
        {
            time=unsafeWindow.HHTimers.timers[e].remainingTime;
        }
    }
}
for(var e in unsafeWindow.HHTimers.timers){
    if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes(".contest_timer"))
        time=unsafeWindow.HHTimers.timers[e];
}

to

for(var e in unsafeWindow.HHTimers.timers){
    if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes(".contest_timer"))
    {
        time=unsafeWindow.HHTimers.timers[e];
    }
}
for(e in unsafeWindow.HHTimers.timers){
    if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes(".after_gift"))
        time=unsafeWindow.HHTimers.timers[e];
}

to

for(e in unsafeWindow.HHTimers.timers){
    if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes(".after_gift"))
    {
        time=unsafeWindow.HHTimers.timers[e];
    }
}
for(var e in unsafeWindow.HHTimers.timers){
    if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes("#missions_counter"))
        time=unsafeWindow.HHTimers.timers[e];
}

to

for(var e in unsafeWindow.HHTimers.timers){
    if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes("#missions_counter"))
    {
        time=unsafeWindow.HHTimers.timers[e];
    }
}

There is also a redundant nested block. So after all of this the code now looks like ::
EDITED by OUJS Admin

--- b.user.js	2018-07-17 00:06:33.351884738 -0600
+++ c.user.js	2018-07-17 00:20:39.757760066 -0600
@@ -283,7 +283,7 @@
             data.missionObject = missionObject;
             var rewards = [];
             // set rewards
-            {
+
                 // get Reward slots
                 var slots = missionObject.querySelectorAll(".slot");
                 // traverse slots
@@ -322,7 +322,7 @@
                     }
                     rewards.push(reward);
                 });
-            }
+
             data.rewards = rewards;
             missions.push(data);
         });
@@ -369,7 +369,9 @@
             var time = 0;
             for(var e in unsafeWindow.HHTimers.timers){
                 if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes("#missions_counter"))
+                {
                     time=unsafeWindow.HHTimers.timers[e];
+                }
             }
             time = time.remainingTime;
             if(time === undefined)
@@ -377,7 +379,9 @@
                 //try again with different selector
                 for(e in unsafeWindow.HHTimers.timers){
                     if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes(".after_gift"))
+                    {
                         time=unsafeWindow.HHTimers.timers[e];
+                    }
                 }
                 time = time.remainingTime;
             }
@@ -411,7 +415,9 @@
         var time = 0;
         for(var e in unsafeWindow.HHTimers.timers){
             if(unsafeWindow.HHTimers.timers[e].$elm.selector.includes(".contest_timer"))
+            {
                 time=unsafeWindow.HHTimers.timers[e];
+            }
         }
         time = time.remainingTime;
         if(time === undefined)
@@ -420,9 +426,13 @@
             time = undefined;
             for(e in unsafeWindow.HHTimers.timers){
                 if(unsafeWindow.HHTimers.timers[e].$elm[0].className.includes("contest_timer"))
+                {
                     // get closest time
                     if(!(unsafeWindow.HHTimers.timers[e].remainingTime>time))
+                    {
                         time=unsafeWindow.HHTimers.timers[e].remainingTime;
+                    }
+                }
             }
         }
         if(time === undefined){
@@ -590,7 +600,9 @@
                 var arenatime = 0;
                 for(var e in unsafeWindow.HHTimers.timers){
                     if(unsafeWindow.HHTimers.timers[e].$elm.selector.startsWith(".arena_refresh_counter"))
+                    {
                         arenatime=unsafeWindow.HHTimers.timers[e];
+                    }
                 }
                 arenatime = arenatime.remainingTime;
                 Cookies.set('nextArenaTime',arenatime,{expires:new Date(new Date().getTime() + arenatime * 1000)});
@@ -699,7 +711,9 @@
             var npach;
             for(var e in unsafeWindow.HHTimers.timersListMin){
                 if(unsafeWindow.HHTimers.timersListMin[e].$elm.selector.startsWith(".pachinko_change"))
+                {
                     npach=unsafeWindow.HHTimers.timersListMin[e].remainingTime;
+                }
             }
             if(npach !== undefined || npach !== 0)
             {
@@ -722,6 +736,7 @@
     var busy = false;
     var page = window.location.href;
     var currentPower = getHero().infos.energy_fight;
+    var hardCurrency = getHero().infos.hard_currency;
     //console.log("sal="+sessionStorage.autoSalary);
     if(sessionStorage.autoFreePachinko === "true" && busy === false){
         // Navigate to pachinko

There may or may not be changes in there that are not actually needed. Personally I have no idea I was just going through and correcting as many warnings and errors that I could find.

Ignore the hardCurrency var in autoLoop I am currently trying to make a script for the payed version of pachinko which is actually finished just waiting on the kobans to hit 90 for it to be tested.

Lines 258 and 295 were the lines with the redundant nested block aka {}. The only warnings remaining is resulting from the $ and Cookies portions of the code and the ES6 line of code ([...map]). I hope all of the time spent going through and fixing things that may or may not have been needed to be fixed helps in some way.

Re: @3jameo3:

@3jameeo3

I realize you are trying to help out here but please don't post entire scripts. That is what forking is for. Then you can refer to it on your fork. Just rename the @version to something unique.

If you need to show differences please utilize this FAQ.

Thank you for your cooperation,
OUJS Admin

Re: @3jameo3:

The prior changes have been diffed as follows:

  • a.user.js is @eileen12 's @version of 3.22+0552534
  • b.user.js is your original full script source diff'ed to what full source was at this comment
  • c.user.js is your original full script source diff'ed from b.user.js to what full source was at this comment

I don't understand the code change part of the FAQ

I will try to update it a little bit for Windows users since it's mainly for git-scm. I diffed the prior comments using Linux diff -u command after downloading all the sources and then diffing a to b, then b to c. As you can see it's intensely clearer. I left your original "this" to "that" change comparisons. I've done this myself.

I also need to find a DOM diff package (or make one) that we can stick next to beautify/wrap of @eileen12 's source code and then you can choose your method of presentation by dropping in your changes without forking (but forking is still the preferred at this time since it makes way shorter discussions and doesn't open up a security issue... you can delete a fork at a later date if @eileen12 adopts the changes). It's on my long list of things to add to the site. :)

Re: @Marti:

Sounds like a good amount of interesting updates to the site will be coming.

I will try to update it a little bit for Windows users

I look forward to that as I have little to no Linux knowledge.

Thank you for all of your help once again, the change to -diff really does make a huge difference.

Re: @3jameo3:

Sounds like a good amount of interesting updates to the site will be coming.

Time permitting... just tested the "top" diff type package and it locked up my browser with a and b sources. I have a pretty hefty multi-core machine too so that particular package probably isn't going to happen for everyone.

I look forward to that as I have little to no Linux knowledge.

Hope I've improved it a little bit... see the FAQ section. With Windows it's best to use git-scm. All others like it are getting older, and perhaps a bit overly bulky.

Anyhow... sorry about the intervention... but maintaining integrity of the forums here. You should see what we get to remove sometimes. ;)

Re: @Marti:

The flow of the FAQ was greatly improved. Maybe it would be possible to make an application for the -diff, I might try my hand in creating a python code to compare 2 different codes in the future.

Intervene anytime in my posts as I always learn about new things when you do, so thank you for that.

Re: @3jameo3:

I might try my hand in creating a python code to compare 2 different codes in the future.

Seriously doubt the browser itself can handle this... but I also haven't looked to see if there is a runtime client side. Since this would need to be DOM side it would need to be JavaScript. I seem to remember there's some upcoming compiled language but haven't relooked into it (or remembered it's name too ;).

In short this needs to be pure JavaScript and on the client side... perhaps with some optional workers to utilize more cores. The one I twiddled with did too much. We just need the text and not the prettyfication which is probably what slowed it down to a halt.

Anywho... GH is a better place to discuss this rather than here. ;)