Roukys / HHauto

GNU General Public License v3.0
45 stars 44 forks source link

Enhancement : getSalary #122

Closed Nico2d closed 3 years ago

Nico2d commented 3 years ago

Which feature is concerned

I suggest enhancement to collecting salary, it's a way to do it direct by API prowided by HH, Thanks to that, script can work much faster becouse it will not cooperate with frontend and can be run in background. In my example it run only on /harem page but this can be changed. Timeout can be smaller but you have to carefull, becouse if you send to many requests, server will ban you for 15minuts and doesn't answer to any requests.

Describe alternatives you've considered

There is my code which you can follow:

const collectSalary = (girlID) => {
  var xhr = new XMLHttpRequest();

  xhr.open("POST", "https://nutaku.haremheroes.com/ajax.php", true);
  xhr.setRequestHeader("Accept",`application/json, text/javascript, */*; q=0.01`);
  xhr.setRequestHeader("content-type","application/x-www-form-urlencoded; charset=UTF-8");
  xhr.setRequestHeader("x-requested-with", "XMLHttpRequest");

  xhr.send(`class=Girl&which=${girlID}&action=get_salary`);
  xhr.onreadystatechange = function () {
    if (xhr.readyState == 4 && xhr.status == 200) {
      console.log(JSON.parse(xhr.responseText).money);
      return JSON.parse(xhr.responseText).money;
    }
  };

  return 0;
};

(function () {
  "use strict";

  if (window.location.href.indexOf("/harem") > -1) {
    const girlsToCollectList = document.querySelectorAll(".salary:not(.loads)");

    Array.from(girlsToCollectList).map((girl, index) => {
      const girlID = girl.parentElement.parentElement.getAttribute("girl");
      if (girlID !== null) {
        setTimeout(() => {
          collectSalary(girlID);
        }, 500 * index);
      }
    });
  }
})();
Knatan commented 3 years ago

In my example it run only on /harem page but this can be changed.

This sounds fantastic. Loading that Harem page constantly is probably the most stressful thing we are subjecting the server to.

OldRon1977 commented 3 years ago

Hmmm... Be careful! If you address an API directly, they can monitor that! This might be a possibility to identify who is using the script.

Roukys commented 3 years ago

@OldRon1977 I think API is in the end used when yourself you click on collect, I'll check on that

@Nico2d the way I understand your code it does means we still have to load harem page, but as soon as loaded and we have the girl list we can continue on while still picking salary, am I right ?

Nico2d commented 3 years ago

@Roukys you have to load harem page only becouse it was easier to test it. You can call request to API from anywhere, don't even have to start the game, but the problem is to have girlsToCollectList . Its not ready scrpit - just wanted to show you better way to do this.

Roukys commented 3 years ago

:) yes for me girlToCollectList is on harem that why I was saying we still have to go on harem, until we find a way to remotely generate list , but that a good idea, today the script rely on clicking all collect button