Hentai Heroes Helper (auto collect and button press)

Add in the Hentai Heroes game.

2022-04-11 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

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

// also in greasyfork add script
// add config section (reset to default) IMPORTANT
// last champion visited, market place and activities (all tab)
// random girl waifu (from girls_data list)
// add auto click troll (scegli fino a quanti ticket avere ancora)
// remember leagues datas x 1gg o clear in conf
// leagues check list di chi attaccare
// remember girls_data for 1gg
// color orange nel caso di % in più non solo rosso
// se il prox champion è già finito vai di nuovo al prox

// Search best item
// "rarity":"legendary",
//    no rare o epic
//    "level":"337", > actual - 2
//    se almeno 3 verdi non nascondere
//    "subtype":"5",
//    values
//       "carac1_equip":"2279",
//       "carac2_equip":"2328",
//       "carac3_equip":"2204",
//       "chance_equip":"3151.82",
//       "endurance_equip":"2338",
// count how many point can get selling all items (50xItems), meanwhile

// can convert animated waifu
// collect auto if stackable items
// retest do auto story mode
// fix if in leagues hidden is selected or 3/3 select first line

// also with animation view images and in season
// Panel if double click on any girl image with all form of girl (i need only id of girl) (reward_wrap for champion)

// next amount? maybe calculate in harem
// add random select avatar / remove new skin notification
// possibili:
// salva lista log (message top right)
// a quali girl dare exp quali son le più utili?
// create team in base al colore da fare (4 + forti più prime colorate)

// console.table(Hero);
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>'));
};
toCsv = function (objArray, separator = ',', eol = '\r\n') {
  var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
  var str = '';

  for (var i = 0; i < array.length; i++) {
    var line = '';
    for (var index in array[i]) {
      if (line !== '') line += separator;
      line += array[i][index];
    }
    str += line + eol;
  }

  return str;
}

// Settings
var storage_key = 'AutoCollect_Settings',
  default_settings = {
    safe_work: false,
    pantheon_auto_enter: true,
    auto_press_btns: true,
    girls_data_print: false,
    last_id_troll: 1,
    last_bang_team: 1,
    last_side_quest: false,
    min_collect_exp: 10000,
    journey_champion_active: true,
    journey_champion: false,
    not_collect_full_graded: false,
    last_link_activity: false,
    last_link_shop: false,
    last_link_champion: false,
  },
  links = {
    'troll': '/troll-pre-battle.html?id_opponent=',
    'activity': '/activities.html?tab=',
    'shop': '/shop.html?type=',
  },
  NOT_FOUND = 'NOT_FOUND';
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);
};

// Story functions
questLink = function () {
  $('#canvas_quest_energy .energy_counter_bar .bar-wrapper .over').wrap('<a href="' + Hero.infos.questing.current_url + '" style="width:100%;text-decoration:none;z-index:2"></a>');
  $('.energy_counter_amount, span[rel="count_txt"]').css('z-index', '1');
};
addBackToLink = function (link, to_selector = '#pre-battle') {
  $('<a href="' + link + '" class="back-to">&lt;- BACK</a>').appendTo($(to_selector));
};
toggleSafeWork = function (selector) {
  change_settings('safe_work', !settings.safe_work);
  $(selector).toggleClass('safe-work');
};
safeWorkBackground = function (selector) {
  $(selector).css({
    'background-color': '#7c7c7c',
    'background-blend-mode': 'exclusion',
  });
}
getLastLink = function ($el, type) {
  var link = $el.attr('href');
  if (typeof link == 'undefined')
    link = $el.attr('data-href');
  if (typeof link != 'undefined' && link.includes(links[type]))
    return link.split(links[type])[1];
  return NOT_FOUND;
};
changeLastTroll = function () {
  var result = getLastLink($(this), 'troll');
  if (result == NOT_FOUND) return;
  change_settings('last_id_troll', toint_string(result));
};
trollMenuLink = function () {
  var $trollMenu = $('.TrollsMenu');
  if (!$trollMenu.length) {
    setTimeout(trollMenuLink, 200);
    return;
  }
  $trollMenu.find('a[href^="' + links.troll + '"]').click(changeLastTroll);
};
changeLastActivityLink = function () {
  var result = getLastLink($(this), 'activity');
  if (result == NOT_FOUND) return;
  change_settings('last_link_activity', result);
};
changeLastShopLink = function () {
  var result = getLastLink($(this), 'shop');
  if (result == NOT_FOUND)
    result = false;
  change_settings('last_link_shop', result);
};
shopMenuLink = function () {
  var $shopMenuLinks = $('a[rel="shop"] .market_menu');
  if (!$shopMenuLinks.length) {
    setTimeout(shopMenuLink, 200);
    return;
  }
  $shopMenuLinks.click(changeLastShopLink);
};
changeLastChampionLink = function () {
  change_settings('last_link_champion', $(this).attr('href'));
};
championMenuLink = function () {
  var $championMenuLinks = $('a[rel="sex-god-path"] .champions_menu');
  if (!$championMenuLinks.length) {
    setTimeout(championMenuLink, 200);
    return;
  }
  $championMenuLinks.click(changeLastChampionLink);
};
goToChampion = function (id_champion) {
  location.href = "/champions/" + id_champion;
};
journeyChampion = function (id_champion) {
  if (settings.journey_champion) {
    goToChampion(settings.journey_champion);
    change_settings('journey_champion', false);
  }
};
waifuSafeWork = function () {
  $('.waifu-girl-container img').addClass('safe-work');
  $('.diamond-bar .diamond').click(function () {
    setTimeout(waifuSafeWork, 200);
  });
};
// Other plugins
fixDiamondImg = function () {
  setTimeout(function () {
    $('.diamond-bar .diamond:first-child').trigger('mouseenter');
  }, 500);
};

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');
  // console.log(page);

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

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

        can_collect = false;
        collect();
      });
      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,
        skip_girl = false,
        $stars = $girl.find('.graded g');

      girls_data.push({
        'name': $girl.find('h4').text(),
        'id': +$girl.attr("girl"),
        'rarity': $girl.find('.left').attr("rarity"),
        'domination': $girl.find('.domination-toggle').attr("generic-tooltip"),
        'level': toint_element($girl.find('.lvl span:nth-child(2)')),
        'grade': $stars.length
      });

      $girl.click(function () {
        setTimeout(function () {
          $('.diamond-bar .diamond.selected').trigger('mouseenter');
        }, 500);
      });

      if (settings.not_collect_full_graded) {
        // if ($girl.find('h4').text() == 'Donatella')
        //   console.log('debug girl name');
        var class_attr = $stars.last().attr('class');
        class_count = 0;
        if (typeof class_attr != 'undefined')
          class_count = class_attr.split(/\s+/).length;
        skip_girl = (
          class_count > 0 ||
          $girl.find('.can_upgrade').length
        );
      }

      if (!$girl.find('.salary.loads').length && !skip_girl) {
        $girl.trigger('click');
        after = 25;
      }

      // Commented to let work girls_data / add again if girls data is valid in same day or option not set
      // var total_salary = toint_element(
      //   $('#collect_all span[rel="next_salary"]')
      // );
      if (i === girls.length - 1) {
        $girl_list.scrollTop($girl_list.prop('scrollHeight') - 300);
        if (!$girl.parent().next().find('div[girl]').hasClass('not_owned'))
          can_collect = true;
        else {
          console.clear();
          console.table(girls_data);
          if (settings.girls_data_print) {
            console.log(toCsv([{
              'name': 'Name',
              'id': 'Id',
              'rarity': 'Rarity',
              'domination': 'Domination',
              'level': 'Level',
              'grade': 'Grade'
            },
            ...girls_data
            ]));
          }
          // maybe better do not click last girl, expecially for next run
          // $girl.trigger('click');
        }
      } else
        setTimeout(function () {
          start_from = i;
          collect_girl(i + 1);
        }, after);
    };
    is_cheat_click = function (e) {
      return false;
    };

    collect();
    $('select').change(restart_collect);

    // 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-box').addClass('safe-work');
      };
    $(harem_right).append($btnSafeWork).bind('DOMNodeInserted', addSafeWork);
    $btnSafeWork.click(function () {
      toggleSafeWork(harem_right + ' .avatar-box');
      $(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') {
    if (settings.safe_work) {
      var scene_selector = '#scene #background';
      $(scene_selector).addClass('safe-work');
      $('#scene .eye').click(function () {
        toggleSafeWork(scene_selector);
      });
    }
    $('button[rel="next"]').click(function () {
      setTimeout(function () {
        location.href = "/harem.html";
      }, 1000);
    });
  } 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++;
    });
    questLink();
  } 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 .selected .inventory_slots .slot:not(.mythic)').last().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();

    setInterval(function () {
      $('.CustomStats').text('');
    }, 100);

    $('#type_item>div').click(function () {
      change_settings('last_link_shop', $(this).attr('type'));
    });

    addCss(
      '#girls_list h3{' +
      '  display: flex;' +
      '  justify-content: center;' +
      '  flex-wrap: wrap;' +
      '  line-height: 20px;' +
      '}' +
      '#girls_list h3 span{' +
      '  width: 100%;' +
      '  font-size: 12px;' +
      '}' +
      '#type_item .text{' +
      '  font-size: 10px;' +
      '}' +
      '#hideText{text-shadow: 0 0 3px #057}' +
      '#hideSellButton{left: 39px!important}'
    );
  } else if (page == 'leaderboard') {
    var opponents_list = '.lead_table table tbody tr:not(.personal_highlight):visible',
      $opponents_list = false,
      stop_simulation = false,
      simulationTimeout = false,
      nextTimeout = false;
    simulation = function () {
      if (stop_simulation) return;

      $opponents_list = $(opponents_list);
      $(opponents_list).click(function () {
        if (stop_simulation) {
          $('.matchRating').remove();
          wait_simulate($(this), -1);
        }
      });

      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;

      // fix se -/-/-
      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);
    };
    var after = 5000;
    if (toint_element($('.challenge_points .over span[energy]')) < 1) after = 120000;
    setTimeout(simulation, after);

    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);
    });

    if (!$('.challenge .blue_button_L').length)
      $(opponents_list).first().trigger('click');

    addCss(
      '.leagues_table{position: relative}' +
      '.btnStopSimulation{' +
      '  position: absolute;' +
      '  top: 0;' +
      '  left: 0;' +
      '  z-index: 99;' +
      '}'
    );
  } else if (page == 'activities') {
    change_tab = function () {
      var $tab = $('.tabs h4.selected');
      change_settings('last_link_activity', $tab.attr('rel'));
      if ($tab.hasClass('pop')) {
        var $btnPurple = $('.purple_button_L:visible').first();
        $btnPurple.trigger('click');
        if (!$btnPurple.length)
          $('.pop_thumb_container').each(function () {
            if (!$(this).find('.pop_thumb_progress_bar:visible').length)
              $(this).find('button[rel="pop_thumb_info"]:visible').trigger('click');
          });

        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
        );
      } else if ($tab.hasClass('contests')) {
        if (settings.safe_work) {
          $('.right_part>img').addClass('safe-work');
          safeWorkBackground('.contest_header');
        }
      } else if ($tab.hasClass('daily_goals')) {
        if (settings.safe_work)
          $('.daily-goals-right-part>img').addClass('safe-work');
      } else {
        if (Hero.infos.Xp.left > settings.min_collect_exp)
          $('.mission_object:not([data-d*=\'"remaining_time":null\']) button.purple_button_L:visible').trigger('click');
        if ($('.end_gift:visible').length)
          $('.end_gift button').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, #rewards-girl-container img').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, 3000);
      $('#tabs_switcher .switch-tab').click(auto_enter);
    }
  } 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);
      $('.champions-over__champion-tier-link').click(function () {
        setTimeout(function () {
          safeWorkBackground('#scene_popup');
        }, 100);
      });
    }
    addCss('.champions-bottom__rest{font-size: 15px}');

    if (page == 'champions') {
      var max_champions = 6,
        champion_id = toint_string(championData.champion.id),
        $btns_container = $('<div class="btns_container"></div>');

      $btns_container.appendTo($('.champions-bottom__wrapper'));

      previous_champion_id = champion_id - 1;
      if (previous_champion_id < 1)
        previous_champion_id = max_champions;
      $('<button class="finished round_blue_button">' +
        '	<img src="https://hh.hh-content.com/design/ic_arrow-left-ffffff.svg">' +
        '</button>')
        .click(function () { goToChampion(previous_champion_id); })
        .appendTo($btns_container);

      next_champion_id = champion_id + 1;
      if (next_champion_id > max_champions)
        next_champion_id = 1;
      $('<button class="finished round_blue_button">' +
        '	<img class="continue" src="https://hh.hh-content.com/design/ic_arrow-right-ffffff.svg">' +
        '</button>')
        .click(function () { goToChampion(next_champion_id); })
        .appendTo($btns_container);

      addCss(
        '.btns_container{' +
        '  display: flex;' +
        '  position: absolute;' +
        '  top: 5px;' +
        '  right: 149px;' +
        '}' +
        '.btns_container .round_blue_button img{height: 75%}'
      );

      if (settings.journey_champion_active) {
        journeyChampion();
        $('button[rel="perform"]').click(function () {
          change_settings('journey_champion', next_champion_id);
        });
      }
    }
  } else if (page == 'champions_map') {
    if (settings.journey_champion_active)
      journeyChampion();
    $('.champion-lair').click(changeLastChampionLink);
  } else if (page == 'event') {
    if (settings.safe_work) {
      $('.girl-avatar').addClass('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);
        fixDiamondImg();
      });
    }
    // Boss bang
    if ($('#boss_bang').length) {
      var bang_selector = '.boss-bang-team-slot';
      if (settings.last_bang_team > 1)
        $(bang_selector + '[data-slot-index="' + settings.last_bang_team + '"]').trigger('click');
      $(bang_selector).click(function () {
        change_settings('last_bang_team', $(this).attr('data-slot-index'));
      });
    }
  } else if (page == 'side-quests') {
    if (settings.safe_work) $('.side-quest-image').addClass('safe-work');
    $('.side-quest-button').click(function () {
      change_settings('last_side_quest', $(this).attr('href'));
    });
  } else if (page == 'pachinko') {
    if (settings.safe_work) {
      setInterval(function () {
        $('.pachinko_img').addClass('safe-work');
      }, 100);
      $('canvas, .pachinko_img, .game-simple-block>img').addClass('safe-work');
    }
    questLink();
  } else if (page == 'teams') {
    if (settings.safe_work) $('.girl-image-container').addClass('safe-work');
  } else if (page == 'home') {
    if (settings.safe_work) {
      $('.news_wrapper').bind('DOMNodeInserted', function () {
        $('.news_thumb_pic, .news_page_pic').addClass('safe-work');
      });
      $('.waifu-container').addClass('safe-work');
    }
    $('#collect_all_container').click(function () {
      location.href = "/harem.html";
    });
    $('#collect_all .collect-infos .sum').after($('<br>'));
    // Last links
    if (settings.last_side_quest)
      $('.continue_side_quest_home, .side_quests').attr('href', settings.last_side_quest);
    var $activitiesLink = $('a[rel="activities"]');
    $activitiesLink.find('a[href^="' + links.activity + '"]').click(changeLastActivityLink);
    if (settings.last_link_activity)
      $activitiesLink.attr('href', links.activity + settings.last_link_activity);
    shopMenuLink();
    if (settings.last_link_shop)
      $('a[rel="shop"]').attr('href', links.shop + settings.last_link_shop);
    championMenuLink();
    if (settings.last_link_champion)
      $('a[rel="sex-god-path"]').attr('href', settings.last_link_champion);

    addCss(
      'span.pay-in{display: initial!important}' +
      '#collect_all{cursor: pointer}' +
      '#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .collect-button #collect_all_container #collect_all .collect-infos .cost-text span[cur=hard_currency]::before {' +
      '  width: 13px;' +
      '  height: 15px;' +
      '}' +
      '#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-container .pov-button > a > .button-notification-icon, #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-container .season-button > a > .button-notification-icon{margin-top: 0}' +
      '#homepage .main-container .left-side-container .quest-container>a>.button-notification-icon, #homepage .main-container .left-side-container>a>.button-notification-icon{z-index: 999}' +
      '#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .collect-button #collect_all_container #collect_all .collect-infos .cost-text{margin-top: 0}' +
      '#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-container .pov-button, #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-container .season-button{z-index: 1}' +
      '#home_pov_bar .text{width: 100%}'
    );
  } else if (page == 'world') {
    if (settings.safe_work)
      $('div.girl_world, div.troll_world').addClass('safe-work');
  } else if (page == 'path-of-valor') {
    if (settings.safe_work) $('.girl-preview>img').addClass('safe-work');
  } else if (page == 'sex-god-path') {
    if (settings.safe_work) $('.feature-categories img').addClass('safe-work');
  } else if (page == 'hero_pages') {
    if (settings.safe_work) $('img[girl-ava-src]').addClass('safe-work');
  } else if (page == 'edit-team' || page == 'add-boss-bang-team') {
    if (settings.safe_work) $('.girl-display img[girl-ava-src]').addClass('safe-work');
  } else if (page == 'troll-pre-battle') {
    questLink();
    addBackToLink('/world/' + (settings.last_id_troll + 1));
  } else if (page == 'pantheon-pre-battle') {
    questLink();
    addBackToLink('/sex-god-path.html');
  } else if (page == 'battle' /* probably deprecated */ ||
    page == 'league-battle' ||
    page == 'pantheon-battle' ||
    page == 'season-battle' ||
    page == 'troll-battle' ||
    page == 'boss-bang-battle') {
    if (settings.safe_work) $('.new-battle-image').addClass('safe-work');
  } else if (page == 'waifu') {
    if (settings.safe_work) {
      setTimeout(waifuSafeWork, 500);
      $('.harem-girl-container').click(waifuSafeWork);
    }
  }

  // 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.journey_champion)
    change_settings('journey_champion', false);

  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;
      }
      $(
        '#girls_holder #left_girl, #girls_holder #right_girl, .animated-girl-display, .payments-left-girl, .payments-right-girl, #no_energy_worship>img, #no_energy_fight>img, #no_energy_kiss>img, #no_energy_challenge>img, #awakening_popup .awakening-avatar'
      ).addClass('safe-work');
    }, 10);
    $('#no_HC').bind('DOMNodeInserted', function () {
      $('.season_pass #left_girl_sp, .season_pass #right_girl_sp, .payments .product-background').addClass('safe-work');
    });
  }

  $(document).on('keypress', function (e) {
    if ($(e.target).is('.club-chat-input')) return;
    if (e.which == 13) $('.blue_button_L:visible').first().trigger('click');
  });

  $('a[href^="' + links.troll + '"]').click(changeLastTroll);
  $('button[data-href^="' + links.troll + '"]').click(changeLastTroll);
  trollMenuLink();

  $('.energy_counter[type="fight"] .energy_counter_amount').wrap('<a href="' + links.troll + settings.last_id_troll + '" class="link_last_troll"></a>');

  fixDiamondImg();

  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);' +
    '}' +
    '.link_last_troll{' +
    '  color: #fff;' +
    '  text-decoration: none;' +
    '}' +
    '#collect_all_container #collect_all{' +
    '  -webkit-box-shadow: 0 2px 0 rgb(13 22 25 / 35%), inset 0 3px 0 #f9b12e;' +
    '  -moz-box-shadow: 0 2px 0 rgba(13,22,25,.35),inset 0 3px 0 #f9b12e;' +
    '  box-shadow: 0 2px 0 rgb(13 22 25 / 35%), inset 0 3px 0 #f9b12e;' +
    '}' +
    '#popups.fixed_scaled, #sliding-popups.fixed_scaled, #black_screen{top: 10%}' +
    '.back-to {' +
    '  position: absolute;' +
    '  top: 0;' +
    '  left: 50%;' +
    '  transform: translateX(-50%);' +
    '  color: white;' +
    '  text-decoration: none;' +
    '  text-shadow: 0 0px 2px black;' +
    '}'
  );

  appendCss();
});


// Dont work on iframe
// copyToClipboard = function (str) {
//   try {
//     var el = document.createElement('textarea');
//     el.value = str;
//     el.setAttribute('readonly', '');
//     el.style.position = 'absolute';
//     el.style.left = '-0';
//     el.style.top = '-0';
//     document.body.appendChild(el);
//     el.select();
//     document.execCommand('copy');
//     navigator.clipboard.writeText(str);
//     document.body.removeChild(el);
//     console.log('Copied to clipboard');
//   } catch (e) {
//     console.error(e);
//   }
// };