Hentai Heroes Helper (auto collect and button press)

Add in the Hentai Heroes game.

Versión del día 6/1/2022. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name			Hentai Heroes Helper (auto collect and button press)
// @description		Add in the Hentai Heroes game.
// @version			1.4.1
// @match			https://www.hentaiheroes.com/*
// @match			https://nutaku.haremheroes.com/*
// @match			https://eroges.hentaiheroes.com/*
// @match			https://thrix.hentaiheroes.com/*
// @match			https://www.gayharem.com/*
// @match			https://nutaku.gayharem.com/*
// @match			https://www.comixharem.com/*
// @match			https://nutaku.comixharem.com/*
// @match			https://*.hornyheroes.com/*
// @run-at			document-end
// @grant			none
// @license         MIT
// @author			Morry98
// @namespace https://greasyfork.org/users/807892
// ==/UserScript==

// add auto click troll
// leagues remember datas
// add config section (reset to default) / some btn faster than other (for reward still see it)
// popup cliccabile al di sotto

// also with animation view images and in season
// add random select avatar / remove new skin notification

// fix: diminuisco time dopo del reload harem: check
// fix: time troll press ok e in generale su mac: check

is_numeric = function(c) {
  return /^\d+$/.test(c);
}
toint_string = function(str) {
  var new_str = '';
  for (i = 0; i < str.length; i++) {
    var char = str.charAt(i)
    if (is_numeric(char))
      new_str += char;
  }
  return +new_str;
}
toint_element = function($el) {
  return toint_string($el.text().replace(/^\D+/g, ''));
}
addCss = function(code, append) {
  if (code != '')
    add_css += '' + code;

  if (typeof append != 'undefined' && append)
    appendCss();
}
appendCss = function() {
  $('#customStyle').remove();
  if (add_css != '')
    $body.append($('<style id="customStyle">' + add_css + '</style>'));
}

toggle_safe_work = function(selector) {
  change_settings('safe_work', !settings.safe_work);
  $(selector).toggleClass('safe-work');
}

var storage_key = 'AutoCollect_Settings',
  default_settings = {
    'safe_work': false,
    'pantheon_auto_enter': true,
    'auto_press_btns': true,
  };
save_settings = function(settings) {
  window.localStorage.setItem(storage_key, JSON.stringify(settings));
}
clear_settings = function() {
  window.localStorage.removeItem(storage_key);
}
get_settings = function() {
  var settings = window.localStorage.getItem(storage_key),
    last_added_settings = Object.keys(default_settings)[Object.keys(default_settings).length - 1],
    key = false;

  if (settings == null) settings = {};
  else settings = JSON.parse(settings);

  if (!settings.hasOwnProperty(last_added_settings)) {
    for (key in default_settings) {
      if (!settings.hasOwnProperty(key))
        settings[key] = default_settings[key];
    }
  }

  for (key in settings) {
    if (!default_settings.hasOwnProperty(key))
      delete settings[key];
  }

  save_settings(settings);
  return settings;
}
change_settings = function(key, value) {
  settings[key] = value;
  save_settings(settings);
}

var settings = get_settings(),
  theme_colors = {
    'green': '#53af00',
    'red': '#b14',
    'gray': '#6a6a6a',
    'shadow_gray': '0 3px 0 rgb(23 33 7 / 60%), inset 0 3px 0 #3c3c3c',
  },
  add_css = '',
  $body = false;
$(function() {
  $body = $('body[page]');
  var page = $body.attr('page');

  if (page == 'harem') {
    var girls = null,
      interval_collect = false,
      can_collect = true,
      $girl_list = $('.girls_list');

    collect = function(start_from) {
      clearInterval(interval_collect);
      interval_collect = setInterval(function() { can_collect = true; }, 30000);
      $girl_list.bind('DOMNodeInserted', function() {
        if (!can_collect) return;

        can_collect = false;
        collect(0);
      });
      girls = $('div.girls_list>div[id_girl]>div[girl]:not(.not_owned)');
      collect_girl(start_from);
    }
    collect_girl = function(i) {
      if (i >= girls.length) return;

      var $girl = $(girls[i]),
        after = 0;
      if (!$girl.find('.salary.loads').length) {
        $girl.trigger('click');
        after = 25;
      }

      var total_salary = toint_element($('#collect_all span[rel="next_salary"]'));
      if (i === girls.length - 1 && total_salary > 0) {
        $girl_list.scrollTop($girl_list.prop('scrollHeight'));
        if (!$girl.parent().next().find('div[girl]').hasClass('not_owned'))
          can_collect = true;
        else $girl.trigger('click');
      } else setTimeout(function() {
        collect_girl(i + 1);
      }, after);
    }
    is_cheat_click = function(e) { return false; }

    collect(0);

    // SFW
    retrive_img = function() {
      return 'https://hh.hh-content.com/' + (settings.safe_work ?
        'design/menu/ic_eyeopen.svg' :
        'quest/ic_eyeclosed.svg');
    }
    var harem_right = '#harem_whole #harem_right',
      $btnSafeWork = $('<img class="view" src="' + retrive_img() + '">'),
      addSafeWork = function() {
        if (settings.safe_work)
          $(harem_right).find('.avatar').addClass('safe-work');
      };
    $(harem_right)
      .append($btnSafeWork)
      .bind('DOMNodeInserted', addSafeWork);
    $btnSafeWork.click(function() {
      toggle_safe_work(harem_right + ' .avatar');
      $(this).attr('src', retrive_img());
    });
    addSafeWork();

    addCss(
      harem_right + '{position: relative}' +
      harem_right + ' img.view{' +
      '  width: 25px;' +
      '  position: absolute;' +
      '  bottom: 20px;' +
      '  left: -10px;' +
      '  cursor: pointer;' +
      '  z-index: 9;' +
      '}'
    );
  } else if (page == 'quest') {
    var scene_selector = '#scene #background';
    if (settings.safe_work)
      $(scene_selector).addClass('safe-work');
    // $('#scene .eye').click(function() { toggle_safe_work(scene_selector); });
  } else if (page == 'season_arena') {
    var css_hero = '#season-arena .battle_hero .hero_stats_row',
      hero_power = toint_element($(css_hero + ':first-child>div:first-child')),
      hero_crown = toint_element($(css_hero + ':nth-child(2)>div:first-child')),
      opponent_index = 0;
    $('.opponents_arena .season_arena_opponent_container').each(function() {
      var $opponent_power = $(this).find('.hero_stats_row:first-child>div:first-child'),
        opponent_power = toint_element($opponent_power),
        $opponent_crown = $(this).find('.hero_stats_row:nth-child(2)>div:first-child'),
        opponent_crown = toint_element($opponent_crown),
        result_power = (hero_power >= opponent_power),
        result_crown = (hero_crown >= opponent_crown);
      // anche arancione se nel 2.2% circa
      $opponent_power.css('color', result_power ? theme_colors.green : theme_colors.red);
      $opponent_crown.css('color', result_crown ? theme_colors.green : theme_colors.red);
      if (!result_power || !result_crown)
        $('.opponents_arena .opponent_perform_button_container').eq(opponent_index).find('button').css({
          'background': theme_colors.gray,
          'box-shadow': theme_colors.shadow_gray,
          '-webkit-box-shadow': theme_colors.shadow_gray,
        });
      opponent_index++;
    });
  } else if (page == 'shop') {
    var $girl_title = $('#girls_list h3'),
      last_girl_name = '',
      interval_try = false;
    awakening_view = function() {
      var girl_name = $girl_title.clone().children().remove().end().text();
      if (last_girl_name == girl_name) return;

      last_girl_name = girl_name;
      clearInterval(interval_try);
      interval_try = setInterval(function() {
        var girl_awakening = $('#girls_list img.icon').attr('hh_title'),
          $btn_awakening = $('#inventory .blue_text_button');
        if (girl_awakening != undefined) {
          $('#inventory .slot').first().trigger('click');
          var split_awakening = girl_awakening.split(':'),
            split_awakening_values = split_awakening[1].split('/'),
            total_awakening = toint_string(split_awakening_values[1]),
            required_awakening = toint_string(split_awakening_values[0]),
            color = 'inherit',
            cant_awake = (required_awakening < total_awakening),
            full_exp_bar = $btn_awakening.find('span[rel="girl"] span span').hasClass('hudAwaken_mix_icn');
          $btn_awakening.attr('disabled', cant_awake && full_exp_bar);
          if (cant_awake)
            color = theme_colors.red;
          $girl_title.html(girl_name + '<span style="color:' + color + '">' + girl_awakening + '</span>');
          clearInterval(interval_try);
        }
      }, 200);
    }

    $girl_title.bind('DOMNodeInserted', awakening_view);
    awakening_view();

    addCss(
      '#girls_list h3{' +
      '  display: flex;' +
      '  justify-content: center;' +
      '  flex-wrap: wrap;' +
      '  line-height: 20px;' +
      '}' +
      '' +
      '#girls_list h3 span{' +
      '  width: 100%;' +
      '  font-size: 12px;' +
      '}'
    );
  } else if (page == 'leaderboard') {
    var opponents_list = '.lead_table table tbody tr:not(.personal_highlight)',
      $opponents_list = false,
      stop_simulation = false,
      simulationTimeout = false,
      nextTimeout = false;
    simulation = function() {
      if (stop_simulation) return;

      $opponents_list = $(opponents_list);
      stop_simulation = false;
      $('.btnStopSimulation').show();
      $('.lead_table_view').scrollTop(0);
      $('.matchRating').remove();
      simulate(0);
    }
    simulate = function(i) {
      if (i >= $opponents_list.length || stop_simulation) {
        $btnStopSimulation.click();
        return;
      }

      var $opponent = $($opponents_list[i]),
        opponent_full = $opponent.find('td:nth-child(4)').text();

      if ($('.lead_table table tbody tr:last-child').attr('sorting_id') == $opponent.attr('sorting_id'))
        stop_simulation = true;

      if (opponent_full == '3/3')
        simulate(i + 1);
      else {
        // $('.matchRating').remove();
        $opponent.trigger('click');
        wait_simulate($opponent, i);
      }
    }
    wait_simulate = function($opponent, position) {
      var $rating = $('.matchRating'),
        next = false;
      if (!$rating.length)
        next = function() {
          wait_simulate($opponent, position);
        }
      else {
        var color = $rating.css('color');
        $opponent.find('td').css('color', color);
        if (position != -1) {
          $rating.remove();
          next = function() {
            simulate(position + 1);
          }
        }
      }
      nextTimeout = setTimeout(next, 25);
    }
    setTimeout(simulation, 5000);

    var $leaguesTable = $('.leagues_table');
    $btnStopSimulation = $('<a class="blue_button_L btnStopSimulation">Stop</a>');
    $btnStopSimulation.click(function() {
      clearTimeout(simulationTimeout);
      clearTimeout(nextTimeout);
      stop_simulation = true;
      $(this).hide();
    });
    $leaguesTable.append($btnStopSimulation);

    $leaguesTable.find('th').click(function() {
      if (!$(this).find('span').length) return;

      $btnStopSimulation.click();
      stop_simulation = false;
      simulationTimeout = setTimeout(simulation, 1000);
    });
    $(opponents_list).click(function() {
      if (stop_simulation) {
        $('.matchRating').remove();
        wait_simulate($(this), -1);
      }
    });

    addCss(
      '.leagues_table{position: relative}' +
      '.btnStopSimulation{' +
      '  position: absolute;' +
      '  top: 0;' +
      '  left: 0;' +
      '  z-index: 99;' +
      '}'
    );
  } else if (page == 'missions') {
    change_tab = function() {
      var $tab = $('.tabs h4.selected'),
        $btnClaim = false;
      if ($tab.hasClass('pop')) {
        if (settings.safe_work)
          $('.pop_thumb_container img, img[girl-ava-src]').addClass('safe-work');

        addCss('#pop .pop_list .pop_list_scrolling_area .pop_thumb_container {' +
          '  margin: 0px 2px 10px;' +
          '  width: 103px;' +
          '}' +
          '#pop .pop_list .pop_list_scrolling_area .pop_thumb>.pop_thumb_progress_bar,' +
          '#pop .pop_list .pop_list_scrolling_area .pop_thumb_expanded .pop_thumb_title{' +
          '  width: 97px;' +
          '}' +
          '#pop .pop_list .pop_list_scrolling_area .pop_thumb>button{' +
          '  width: 95px;' +
          '}' +
          '#pop .pop_list .pop_list_scrolling_area .pop_thumb>.pop_thumb_progress_bar .pop_thumb_remaining,' +
          '#pop .pop_list .pop_list_scrolling_area .pop_thumb>.pop_thumb_title span{' +
          '  font-size:10px' +
          '}' +
          '#pop .pop_list .pop_list_scrolling_area .pop_thumb>.pop_thumb_progress_bar .hh_bar>.backbar{' +
          '  width: 90px!important' +
          '}' +
          '#pop .pop_list .pop_list_scrolling_area{' +
          '  margin-top: 40px' +
          '}' +
          '.nicescroll-rails{display:none!important}', true);
        // Find a best selector
        // console.table($('button[rel="pop_thumb_claim"]:not(:disabled)'));
      } else if ($tab.hasClass('contests')) {
        if (settings.safe_work)
          $('.right_part>img').addClass('safe-work');
      } else $btnClaim = $('.mission_object:not([data-d*=\'"remaining_time":null\']) button.purple_button_L:visible');

      if ($btnClaim.length)
        $btnClaim.trigger('click');

      if (settings.safe_work)
        $('.mission_image').addClass('safe-work');
    }

    change_tab();
    $('.tabs h4').click(change_tab);
  } else if (page == 'pantheon') {
    if (settings.safe_work)
      $('.team-girl-container').addClass('safe-work');
    if (settings.pantheon_auto_enter) {
      auto_enter = function() {
        var $btnPantheon = $('.pantheon-pre-battle-btn');
        if ($btnPantheon.length && $('#tabs_switcher #pantheon_tab').hasClass('underline-tab'))
          location.href = $btnPantheon.attr('href');
      }
      setTimeout(auto_enter, 2500);
      $('#tabs_switcher .switch-tab').click(auto_enter);
    }
  } else if (page == 'battle') {
    if (settings.safe_work)
      $('.new-battle-image').addClass('safe-work');
  } else if (page == 'champions' || page == 'club_champion') {
    if (settings.safe_work) {
      $('.new-battle-image, .champions-over__girl-image, .champions-over__champion-image').addClass('safe-work');
      var interval = setInterval(function() {
        $girl = $('.section__preview-characters>div');
        if ($girl.length) {
          $girl.addClass('safe-work');
          clearInterval(interval);
        }
      }, 5);
    }
  } else if (page == 'event') {
    if (settings.safe_work)
    $('.nc-event-list-reward-container').click(function() {
      var interval = setInterval(function() {
        $girl = $('.animated-girl-display, img[girl-ava-src]');
        if ($girl.length) {
          $girl.addClass('safe-work');
          clearInterval(interval);
        }
      }, 5);
    });
  } else if (page == 'side-quests') {
    if (settings.safe_work)
      $('.side-quest-image').addClass('safe-work');
  } else if (page == 'pachinko') {
    if (settings.safe_work) {
      $('canvas, .pachinko_img').addClass('safe-work');
      $('.game-simple-block').click(function() {
        $('.pachinko_img').addClass('safe-work');
      });
    }
  }

  // Global
  if (settings.auto_press_btns) {
    var to_press = true;
    setInterval(function() {
      $btns = $('.popup_buttons .blue_button_L, button[rel="pop_claim"]:not(:disabled)');
      if ($btns.length && $btns.is(':visible') && to_press) {
        to_press = false;
        setTimeout(function() {
          $btns.trigger('click');
          to_press = true;
        }, 1000);
      }
    }, 300);

    var to_press_fast = true;
    setInterval(function() {
      $btnsFast = $('#new-battle-skip-btn, .skip-button, .not-supported-browser .blue_button_L,' +
        'button[rel="pop_auto_assign"]:not(:disabled), button[rel="pop_action"]:not(:disabled)');
      if ($btnsFast.length && to_press_fast) {
        // to_press_fast = false;
        $btnsFast.trigger('click');
        // to_press_fast = true;
      }
    }, 50);
  }
  if (settings.safe_work) {
    var to_check = true;
    setInterval(function() {
      $heroPage = $('#hero_pages');
      if ($heroPage.length && to_check) {
        to_check = false;
        $heroPage.find('.girls, .img_wrapper').addClass('safe-work');
        to_check = true;
      }
    }, 10);
    $('#girls_holder #left_girl, #girls_holder #right_girl, .animated-girl-display').addClass('safe-work');
  }
  $(document).on('keypress', function(e) {
    if (e.which == 13)
      $('.blue_button_L').trigger('click');
  });

  addCss(
    '#popups>#confirm_HC>label, img.classGirl{display: none}' +
    '#leagues_middle .lead_table .nicescroll-rails, #leagues_middle .use-lead-table .nicescroll-rails{top: 0!important}' +
    '.safe-work{' +
    '  opacity: 0.05!important;' +
    '  transition: none;' +
    '  filter: grayscale(1);' +
    '}'
  );

  appendCss();
});