Hentai Heroes++ (OCD) Season version

Adding things here and there in the Hentai Heroes game.

Versión del día 23/02/2024. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name			Hentai Heroes++ (OCD) Season version
// @namespace		https://sleazyfork.org/fr/scripts/415625-hentai-heroes-ocd-season-version
// @description		Adding things here and there in the Hentai Heroes game.
// @version			0.75.4
// @match           https://*.hentaiheroes.com/*
// @match           https://*.haremheroes.com/*
// @match           https://*.gayharem.com/*
// @match           https://*.comixharem.com/*
// @match           https://*.hornyheroes.com/*
// @match           https://*.pornstarharem.com/*
// @match           https://*.transpornstarharem.com/*
// @match           https://www.gaypornstarharem.com/*
// @run-at          document-end
// @grant			none
// @author			Raphael, 1121, Sluimerstand, shal, Tom208, test_anon, 45026831(Numbers)
// @license			MIT
// ==/UserScript==


/*	===========
	 CHANGELOG
	=========== */

// 0.75.4: Fixed links on Nutaku following to the game's update.
// 0.75.3: Fixed minor things.
// 0.75.2: Fixed minor things.
// 0.75.1: Fixed some bugs.
// 0.75.0: Got partial girls data from events and harem pages.
// 0.74.9: Fixed minor things.
// 0.74.8: Fixed minor bugs.
// 0.74.7: Changed minor things.
// 0.74.6: Decreased girls data size in localStorage.
// 0.74.5: Fixed a bug with Teams collector. Added the waifu page to get harem girls data.
// 0.74.4: Added a kind of team filter in Harem.
// 0.74.3: Decreased size of girls data in localStorage. Fixed some bugs with new harem.
// 0.74.2: Fixed some bugs relative to the harem girls following to the game's update (girls data list removed).
// 0.74.1: Fixed a bug to hide claimed rewards in Lusty Race.
// 0.74.0: Fixed minor things.
// 0.73.9: Fixed bugs following to the game's update.
// 0.73.8: Fixed bugs following to the game's update.
// 0.73.7: Fixed another bug with league shortcut.
// 0.73.6: Fixed bugs following to the game's update.
// 0.73.5: Fixed minor things.
// 0.73.4: Fixed minor things.
// 0.73.3: Fixed minor things. Added last world in GH and PSH.
// 0.73.2: Fixed display bugs following to the game update.
// 0.73.1: Fixed a minor bug in league skill filter.
// 0.73.0: Added skill filter for girl selection in the labyrinth. Added a checkbox to select/unselect all skills in 1 click.
// 0.72.9: Fixed minor things.
// 0.72.8: Fixed bugs with "Filter Girls Items" features.
// 0.72.7: Fixed bugs with "Filter Armor Items" features. Fixed minor things.
// 0.72.6: Added support to the Kinkoid's game Gay Pornstar Harem. Fixed minor things.
// 0.72.5: Added labyrinth shortcut to the sex god path menu. Fixed minor things.
// 0.72.4: Changed god sex path menu display on home screen. Fixed minor things.
// 0.72.3: Fixed minor things.
// 0.72.2: Fixed a bug with league sim. Fixed minor things.
// 0.72.1: Fixed some game data in league.
// 0.72.0: Fixed minor things.
// 0.71.9: Added world 18 in HH.
// 0.71.8: Fixed minor things.
// 0.71.7: Fixed minor things. Reorganize mega-event widget on home screen.
// 0.71.6: Fixed changes in stats display in league table.
// 0.71.5: Fixed a bug.
// 0.71.4: Fixed a bug with battle simulations in league table since the PVP mythic booster is no longer displayed. Fixed minor things.
// 0.71.3: Fixed minor bugs.
// 0.71.2: Added an option to hide x3 button in league. Fixed minor things.
// 0.71.1: Fixed a bug with boosters circular progress.
// 0.71.0: Fixed minor things.
// 0.70.9: Fixed a bug in Harem update. Fixed minor things.
// 0.70.8: Added new world in Comix Harem. Removed bug fix for club champion board following to the ingame fix.
// 0.70.7: Fixed minor things.
// 0.70.6: Fixed minor things.
// 0.70.5: Added highlight on league opponents' names according to their tier 5 skill.
// 0.70.4: Added tier 5 skill display for Hero on pre-battle screen. Fixed minor things.
// 0.70.3: Fixed minor things.
// 0.70.2: Fixed a bug with sort by team power in league leaderboard.
// 0.70.1: Added sort by team power in league leaderboard. Fixed minor things.
// 0.70.0: Fixed a bug with tier 5 skill filter in harem. Added a booster filter in league leaderboard.
// 0.69.9: Fixed minor things.
// 0.69.8: Merged hide opponents and tier 5 skill filter in league leaderboard.
// 0.69.7: Fixed minor things.
// 0.69.6: Added tier 5 skill filter in league leaderboard.
// 0.69.5: Fixed a minor bug in season.
// 0.69.4: Fixed minor things.
// 0.69.3: Added display of tier 5 skill on pre-battle screen and league leaderboard.
// 0.69.2: Fixed club champion participants display.
// 0.69.1: Fixed minor things.
// 0.69.0: Added save of league sim score sort. Fixed minor things.
// 0.68.9: Fixed minor things.
// 0.68.8: Fixed minor things.
// 0.68.7: Fixed minor things.
// 0.68.6: Fixed a bug with "Contests expiry timer" function.
// 0.68.5: Changed display of skills filter in harem.
// 0.68.4: Fixed minor things.
// 0.68.3: Fixed minor things.
// 0.68.2: Fixed a bug about script loading.
// 0.68.1: Fixed minor things.
// 0.68.0: Fixed minor things.
// 0.67.9: Fixed some bugs following to the game update.
// 0.67.8: Added filters criteria for team filters.
// 0.67.7: Fixed minor things.
// 0.67.6: Added a tooltip on champion girl's pose. Added the display of last season data. Fixed minor things.
// 0.67.5: Fixed minor things.
// 0.67.4: Added a highlight for champion girl's pose. Added last world in PSH. Fixed minor things.
// 0.67.3: Fixed minor things.
// 0.67.2: Fixed minor things.
// 0.67.1: Fixed minor things. Added shortcuts (in champion module) to navigate between champions.
// 0.67.0: Fixed a bug in the function "get Harem girls data".
// 0.66.9: Fixed minor things.
// 0.66.8: Fixed minor things.
// 0.66.7: Fixed minor things.
// 0.66.6: Fixed a bug relative to tier 5 skill in fight sim.
// 0.66.5: Added the stun skill in fight sim.
// 0.66.4: Added an option for league sim in the leaderboard. Fixed bug with tier 5 skill in fight sim. Added log for season and league fights.
// 0.66.3: Added tier 5 skill in fight sim (not yet the stun skill).
// 0.66.2: Added skilled girls filters into the harem.
// 0.66.1: Added sim fights on league leaderboard.
// 0.66.0: Fixed minor issues.
// 0.65.9: Taken into account for fights sim the girl skill tier 4. Fixed minor things.
// 0.65.8: Added mega event to the "Hide claimed rewards" feature.
// 0.65.7: Improved league leaderboard display. Fixed minor issues.
// 0.65.6: Fixed minor things.
// 0.65.5: Fixed league info tooltip. Renamed localStorage entries which didn't start by 'HHS.'
// 0.65.4: Fixed minor bugs.
// 0.65.3: Fixed issues on mobile desktop display.
// 0.65.2: Fixed minor things.
// 0.65.1: Fixed a bug with Filter girl equipment feature. Fixed minor things.
// 0.65.0: Fixed minor things.
// 0.64.9: Fixed a bug with Hide beaten opponents feature after sorting league table.
// 0.64.8: Fixed a bug on league screen following to the game update.
// 0.64.7: Fixed minor things.
// 0.64.6: Fixed a bug on club champion participants list following to the game update.
// 0.64.5: Fixed minor things on league screen.
// 0.64.4: Fixed league fight simulation on pre battle screen following to the game update.
// 0.64.3: Fixed a bug with gems display in harem.
// 0.64.2: Added team theme display on league leaderboard.
// 0.64.1: Fixed partially league display following to the game update.
// 0.64.0: Fixed minor things.
// 0.63.9: Fixed villains name in GH. Added a timer before the disappearance of contests rewards.
// 0.63.8: Fixed another bug with villains list in PSH.
// 0.63.7: Fixed a bug with villains list in PSH.
// 0.63.6: Added last worlds in PSH and TPSH.
// 0.63.5: Added Pantheon links and timer to PSH.
// 0.63.4: Fixed minor things following to the game update.
// 0.63.3: Fixed minor things.
// 0.63.2: Fixed some bugs following to the game update.
// 0.63.1: Fixed a bug.
// 0.63.0: Fixed some bugs following to the game update.
// 0.62.9: Added Hero progression rewards to the hide claimed rewards feature.
// 0.62.8: Fixed a bug with mythic boosters.
// 0.62.7: Added League Mastery and Season Mastery boosters to the mythic boosters.
// 0.62.6: Fixed a bug with the class girls display in PoP.
// 0.62.5: Fixed different bugs.
// 0.62.4: Fixed minor bugs.
// 0.62.3: Fixed a bug with quest link.
// 0.62.2: Fixed stats costs in the market.
// 0.62.1: Fixed minor things.
// 0.62.0: Fixed minor things.
// 0.61.9: Fixed some bugs with the 'girls shards display' feature following to the game update.
// 0.61.8: Fixed another bug in club champion following to the game update.
// 0.61.7: Fixed some bugs following to the game update.
// 0.61.6: Fixed minor things.
// 0.61.5: Fixed a bug with hide claimed rewards feature in seasonal event.
// 0.61.4: Fixed the non-display of season stats on opponents selection screen. Fixed a bug in equipment part of the market.
// 0.61.3: Fixed minor things.
// 0.61.2: Fixed minor things.
// 0.61.1: Added a sort by Power for the harem teams filter. Added a link to wiki EN in harem when the game is not in English (Thanks to Franck75).
// 0.61.0: Fixed some bugs in girls equipments filter. Improved the equipments filter box display.
// 0.60.9: Fixed some bugs.
// 0.60.8: Fixed some bugs.
// 0.60.7: Added separator values for PoA objectives.
// 0.60.6: Fixed some bugs in market and mythic hero equipment upgrade.
// 0.60.5: Fixed another bug with the display of club champion girl shards following to the game update.
// 0.60.4: Fixed some bugs following to the game update.
// 0.60.3: Fixed a bug with league info tooltip display.
// 0.60.2: Fixed minor bugs.
// 0.60.1: Fixed minor things.
// 0.60.0: Fixed minor things.
// 0.59.9: Added an option to remove the no-girl warning window in Pachinko.
// 0.59.8: Added a reset button for hero equipments and girls equipments filters.
// 0.59.7: Fixed a bug with mythic hero equipment upgrade.
// 0.59.6: Added an auto select filter relative to the current girl for girls equipments
// 0.59.5: Added new world in Comix Harem.
// 0.59.4: Fixed minor bugs.
// 0.59.3: Fixed minor things.
// 0.59.2: Fixed a bug with champions timer.
// 0.59.1: Fixed minor bugs.
// 0.59.0: Added a filter feature for girls equipments.
// 0.58.9: Fixed minor things.
// 0.58.8: Fixed a bug with Activities timer.
// 0.58.7: Fixed a bug with Activities timer due to game update. Added support to the new Kinkoid's game Trans Pornstar Harem.
// 0.58.6: Added new world and villain in Ponstar harem.
// 0.58.5: Minor improvements.
// 0.58.4: Fixed a bug with Sultry Mysteries shop timer.
// 0.58.3: Fixed a bug due to game update.
// 0.58.2: Fixed a bug with timers due to game update.
// 0.58.1: Minor improvements.
// 0.58.0: Minor improvements.
// 0.57.9: Fixed a bug on profile page about tooltip display of equiped equipments. Fixed a change for champion data when he is resting.
// 0.57.8: Fixed a bug about tooltip display of equiped equipments.
// 0.57.7: Fixed a bug in mythic equipment upgrade protection feature.
// 0.57.6: Fixed some minor bugs.
// 0.57.5: Changed the indicator on home screen for a starting event.
// 0.57.4: Removed "Refresh" feature since the game refreshes the home page. Fixed a bug in league info display.
// 0.57.3: Fixed a bug with booster tooltip duration.
// 0.57.2: Fixed a minor bug with the warning about the end of an event.
// 0.57.1: Fixed an issue with champions statistics.
// 0.57.0: Fixed some minor bugs. Fixed a bug with shards display in pachinko.
// 0.56.9: Fixed max values of the ressources following game update.
// 0.56.8: Added an option to hide the x15 button in league.
// 0.56.7: Fixed some minor bugs.
// 0.56.6: Fixed some bugs.
// 0.56.5: Fixed display bugs.
// 0.56.4: Fixed display bugs.
// 0.56.3: Fixed another bug following game update.
// 0.56.2: Fixed a bug in teams collector feature.
// 0.56.1: Fixed a bug with market timer following game update.
// 0.56.0: Fixed bugs following game update.
// 0.55.9: Fixed a bug with DST/non-DST time change.
// 0.55.8: Fixed a bug in league info with mobile display.
// 0.55.7: Fixed some minor bugs.
// 0.55.6: Fixed some minor bugs following game update.
// 0.55.5: Fixed a bug with Harem Teams filter following game update.
// 0.55.4: Fixed some minor bugs following game update.
// 0.55.3: Fixed a bug in league simulation.
// 0.55.2: Fixed battle simulations following game update. Added a notification on home screen for Sultry Mysteries event about the shop refresh.
// 0.55.1: Fixed another bug with the option to hide the "Claim all" button.
// 0.55.0: Fixed a bug with the option to hide the "Claim all" button.
// 0.54.9: Added an option to hide the "Claim all" button in season, PoV and PoG.
// 0.54.8: Moved the "Claim all" button in season far from the "Claim" button to avoid a mis click.
// 0.54.7: Fixed a bug in the daily missions sort by duration (keep the event missions in the first places). Changed a villain name in PSH.
// 0.54.6: Fixed a minor bug.
// 0.54.5: Sorted daily missions by duration
// 0.54.4: Fixed a minor bug and a bug in Hide claimed rewards feature for PoA event.
// 0.54.3: Fixed minor bugs + added awakening infos in harem info.
// 0.54.2: Fixed a bug.
// 0.54.1: Fixed a bug.
// 0.54.0: Added an indicator when an event, season, Pov or Pog is in its last day.
// 0.53.9: Fixed a bug in event trolls location.
// 0.53.8: Fixed a change in event data following game update.
// 0.53.7: Fixed a bug in Gems display in harem on mobile following game update.
// 0.53.6: Fixed a bug in Gems display in harem following game update.
// 0.53.5: Fixed a bug in Hide claimed rewards feature for DP event.
// 0.53.4: Fixed a bug in Hide claimed rewards feature for DP event.
// 0.53.3: Added DP event in Hide claimed rewards feature.
// 0.53.2: Improved Harem info.
// 0.53.1: Added a new world in Pornstar Harem and made Harem info clearer.
// 0.53.0: Fixed a bug in Ponrstar Harem and another bug with Harem filtered girls shortcuts
// 0.52.9: Fixed minor bugs following to Kinkoid changes.
// 0.52.8: Added Pantheon links to Pornstar Harem and Comix Harem.
// 0.52.7: Fixed a bug.
// 0.52.6: Fixed minor bugs.
// 0.52.5: Added sultry coins counter in Harem. Prevent mythic booster selling.
// 0.52.4: Fixed minor bugs.
// 0.52.3: Fixed a bug with the display of class girl in Places of Power.
// 0.52.2: Fixed a bug with the display of battle skip button and changed the info in harem about the number of missing gems to maximize to lvl 750 every legendary 5-star and mythic girl.
// 0.52.1: Fixed minor bugs.
// 0.52.0: Added resonance bonus filter in market equipments filter.
// 0.51.9: Added an info in harem about the number of gems required to maximize to lvl 750 every 5-star and mythic girl.
// 0.51.8: Fixed another tooltip display in league.
// 0.51.7: Fixed waifu animated girl on home screen.
// 0.51.6: Fixed another bug with gems tooltip display following to Kinkoid changes.
// 0.51.5: Fixed bugs with tooltip display following to Kinkoid changes.
// 0.51.4: Fixed minor bug with team power display in season.
// 0.51.3: Fixed minor bugs.
// 0.51.2: Fixed minor changes.
// 0.51.1: Fixed some changes.
// 0.51.0: Fixed minor changes.


/* =========
	GENERAL
   ========= */

// Define jQuery
var $ = window.jQuery;
if ($ == undefined) {
    console.log("Hentai Heroes++ (OCD) Season version WARNING: No jQuery found. Probably an error page. Ending the script here")
    return;
}

// Define CSS
var sheet = (function() {
    let style = document.createElement('style');
    document.head.appendChild(style);
    return style.sheet;
})();

var CurrentPage = window.location.pathname;

const lvl_max_player = 1000;
const lvl_max_girl = 750;

/* ==============
	TRANSLATIONS
   ============== */

var texts = {
    en: {
        optionsVillain: 'Fight a villain menu',
        optionsTiers: 'Show tiers with available girls',
        optionsXPMoney : 'Better XP / Money',
        optionsMarket: 'Market information',
        optionsMarketRestockButton: 'Move the market "Restock" button',
        optionsFilterArmorItems: 'Filter market armors',
        optionsHarem: 'Harem information',
        optionsHaremFilters: 'Add some filters to the harem',
        optionsGirlsItemsFilter: 'Filter the girls equipments',
        optionsLeague: 'League information',
        optionsLeagueBoard: 'Show the league tops',
        optionsSimLeagueBoardFight: 'Show sim in the league table',
        optionsSimFight : 'League / Season / Villains sim',
        optionsTeamsFilter: 'Teams filter',
        optionsChampions: 'Champions information and quick navigation',
        optionsLinks: 'Shortcuts/Timers',
        optionsSeasonStats: 'Season stats',
        optionsPachinkoNames: 'Show names in Pachinko',
        optionsMissionsBackground: 'Change missions background',
        optionsCollectMoneyAnimation: 'Delete the collect money animation',
        optionsActivitiesTabChoice: 'Set Missions as main tab in Activities',
        optionsCustomizedHomeScreen: 'Customized home screen',
        optionsHideClaimedRewards: 'Hide claimed rewards',
        optionsDesktopDisplay: 'Desktop display mode on mobile',
        optionsHideClaimAllButtons: 'Hide "Claim All" button',
        optionsHideMultipleLeagueBattlesButton: 'Hide x15 button in league',
        optionsRemovePachinkoPopup: 'Remove the "no-girl" warning in Pachinko',
        optionsContestsExpiryTimer: 'Timer for contests rewards',
        optionsHideLeaguex3Button: 'Hide x3 button in league',
        and: 'and',
        or: 'or',
        including: 'including',
        affection: 'affection',
        affections: 'affections',
        harem_stats: 'Harem Stats',
        haremettes: 'haremettes',
        hardcore: 'Hardcore',
        charm: 'Charm',
        know_how: 'Know-how',
        shagger: 'Shagger',
        lover: 'Lover',
        expert: 'Expert',
        Defense_against: 'Defense against ',
        specialist_in: 'specialist in ',
        harem_levels: 'harem levels',
        to_go: 'to go',
        unlocked_scenes: 'scenes unlocked',
        money_income: 'Money income',
        per_hour: 'per hour',
        when_all_collectable: 'when all collectable',
        required_to_unlock: 'Required to upgrade all haremettes',
        required_to_get_tier_max_level: 'Required to get all haremettes to the max level of their awakening level',
        required_to_get_max_level: 'Required to get all mythic and 5-star legendary haremettes to the level ' + lvl_max_girl,
        my_stocks: 'My stock',
        equipments: 'equipments',
        boosters: 'boosters',
        with_boosters: 'With boosters',
        no_boosters: 'No boosters',
        books: 'books',
        gifts: 'gifts',
        Equipments: 'Equipments',
        Boosters: 'Boosters',
        Books: 'Books',
        Gifts: 'Gifts',
        equipment: 'equipment',
        booster: 'booster',
        book: 'book',
        gift: 'gift',
        Equipment: 'Equipment',
        Booster: 'Booster',
        Book: 'Book',
        Gift: 'Gift',
        currently_buyable: 'Currently buyable stock',
        visit_the: 'Visit the <a href="' + transformNutakuURL('../shop.html') + '">Market</a> first.',
        not_compatible: 'Your webbrowser is not compatible.',
        or_level: 'or level',
        restock: 'Restock',
        wiki: '\'s wiki page',
        evolution_costs: 'Upgrade costs are',
        world: 'World ',
        villain: ' villain',
        fight_villain: 'Fight a villain',
        you_own: 'You own',
        you_can_give: 'You can give a total of',
        you_can_sell: 'You can sell everything for',
        stat_points_need: 'Stat points buyable to max',
        money_need: 'Money required to max',
        money_spent: 'Money spent in market',
        points_from_level: 'Level-based stat points',
        bought_points: 'Market-bought stat points',
        equipment_points: 'Equipments stat points',
        ginseng_points: 'Boosters stat points',
        club_points: 'Club bonus stat points',
        Xp: 'XP',
        starting: 'Starting',
        common: 'Common',
        rare: 'Rare',
        epic: 'Epic',
        legendary: 'Legendary',
        mythic: 'Mythic',
        day: 'd',
        hour: 'h',
        minute: 'm',
        second: 's',
        demote_up: 'To <u>demote</u> you can have a maximum of ',
        demote_down: 'To <u>demote</u> you must be passed by players with as few as ',
        demote_holdzero: 'To <u>demote</u> you must remain at ',
        stagnate_up: 'To <u>not promote</u> you can have a maximum of ',
        stagnate_down: 'To <u>not promote</u> you must be passed by players with as few as ',
        stagnate_holdzero: 'To <u>not promote</u> you must remain at ',
        top4_up: 'To <u>be in the top 4</u> you must have a minimum of ',
        top4_hold: 'To <u>stay in the top 4</u> you must have a minimum of ',
        top15_up: 'To <u>be in the top 15</u> you must have a minimum of ',
        top15_hold: 'To <u>stay in the top 15</u> you must have a minimum of ',
        top30_up: 'To <u>be in the top 30</u> you must have a minimum of ',
        top30_hold: 'To <u>stay in the top 30</u> you must have a minimum of ',
        points: 'points',
        challenges_regen: 'Natural regeneration: ',
        challenges_left: '<br />Challenges left: ',
        season_fights: 'Season fights: ',
        in: 'in',
        pop: 'Places',
        season: 'Season',
        full_in: 'Full in',
        ends_at: 'Ends at',
        full: 'Full',
        league: 'League',
        boosters_end: 'Boosters end',
        victories: 'Victories',
        defeats: 'Defeats',
        unknown: 'Unknown',
        opponents: 'Opponents',
        notPlayed: 'Not played',
        leaguePoints: 'Points',
        avg: 'Average',
        league_ending: 'League ending on ',
        league_finished: 'League finished on ',
        current_league: 'Current league',
        averageScore: 'Average score per fight: ',
        scoreExpected: 'Score expected: ',
        available_girls: 'Available girls: ',
        fights: 'Fights',
        won_mojo: 'Won mojo',
        lost_mojo: 'Lost mojo',
        won_mojo_avg: 'Won mojo average',
        lost_mojo_avg: 'Lost mojo average',
        mojo_avg: 'Global mojo average',
        filter: 'Filter',
        searched_name : 'Searched name',
        girl_name: 'Girl name',
        searched_class: 'Searched class',
        searched_rarity: 'Searched rarity',
        team_number: 'Team number',
        all: 'All',
        team: 'Team',
        teams: 'Teams',
        save_as: 'Save as',
        load_from: 'Load from',
        level_range: 'Level range',
        searched_aff_category: 'Searched affection category',
        searched_aff_lvl: 'Searched affection <BR>level',
        aff_lvl: 'Affection level',
        zero_star: '0 star',
        one_star: '1 star',
        two_stars: '2 stars',
        three_stars: '3 stars',
        four_stars: '4 stars',
        five_stars: '5 stars',
        six_stars: '6 stars',
        time_passed: 'time has passed',
        combativity: 'Combativity',
        energy: 'Energy',
        sort: 'Sort',
        hide: 'Hide',
        display: 'Display',
        searched_blessed_attributes: 'Searched blessed girls',
        blessed_attributes: 'Blessed girls',
        non_blessed_attributes: 'Non-blessed girls',
        pantheon: 'Pantheon\'s Stairway',
        searched_element: 'Searched Element',
        element: 'Element',
        dominatrix: 'Dominatrix',
        submissive: 'Submissive',
        voyeur: 'Voyeur',
        eccentric: 'Eccentric',
        exhibitionist: 'Exhibitionist',
        physical: 'Physical',
        playful: 'Playful',
        sensual: 'Sensual',
        clubChampDuration: '{{duration}} since round start',
        searched_pose: 'Searched Pose',
        visit_teams: 'Visit <a href="' + transformNutakuURL('../teams.html') + '">Teams</a> first.',
        next: 'Next',
        Side_quests : 'Side quests',
        Club_champion: 'Club champion',
        Current_positions: 'Current positions',
        Current_stage: 'Current stage',
        Statistics: 'Statistics',
        Prev_stage: 'Prev stage',
        attempt: 'attempt',
        attempts: 'attempts',
        Gems_in_stock: 'Gems in stock',
        missing_gems: 'Missing gems to maximize each mythic or legendary 5-star girl',
        date_on: 'on',
        skilledGirls: 'Skilled Girls',
        last_season: 'Last Season',
        champion_girl_pose: 'Champion\'s girl pose',
        none: 'None',
        with: 'With',
        tier5_skill_filter: 'Tier 5 skill',
        already_fought: 'Already fought',
        zodiac: {1: '♈︎ Aries',
                 2: '♉︎ Taurus',
                 3: '♊︎ Gemini',
                 4: '♋︎ Cancer',
                 5: '♌︎ Leo',
                 6: '♍︎ Virgo',
                 7: '♎︎ Libra',
                 8: '♏︎ Scorpio',
                 9: '♐︎ Sagittarius',
                 10: '♑︎ Capricorn',
                 11: '♒︎ Aquarius',
                 12: '♓︎ Pisces'},
        color: {'F99': 'Pink',
                '00F': 'Blue',
                'A55': 'Brown',
                '0F0': 'Green',
                'F0F': 'Purple',
                'FD0': 'Golden',
                'F00': 'Red',
                'B06': 'Dark Pink',
                'F90': 'Orange',
                '888': 'Grey',
                'CCC': 'Silver',
                '000': 'Black',
                'XXX': 'Unknown',
                '321': 'Dark',
                'B62': 'Dark blond',
                'FFF': 'White',
                'FF0': 'Blond',
                'EB8': 'Strawberry blonde',
                'D83': 'Bronze'},
    },

    fr: {
        optionsVillain: 'Menu des combats des trolls',
        optionsTiers: 'Montrer les paliers avec filles disponibles',
        optionsXPMoney : 'XP / Argent + précis',
        optionsMarket: 'Infos marché',
        optionsMarketRestockButton: 'Déplacer le bouton "Remplir" du marché',
        optionsFilterArmorItems: 'Filtrer les équipements du marché',
        optionsHarem: 'Infos harem',
        optionsHaremFilters: 'Ajouter des filtres dans le harem',
        optionsGirlsItemsFilter: 'Filtrer les équipements des filles',
        optionsLeague: 'Infos ligue',
        optionsLeagueBoard: 'Montrer les tops ligue',
        optionsSimLeagueBoardFight: 'Afficher simu dans le classement de ligue',
        optionsSimFight: 'Simu ligue / saison / combats de troll',
        optionsTeamsFilter: 'Filtre d\'équipes',
        optionsChampions: 'Infos + raccourcis champions',
        optionsLinks: 'Raccourcis/Timers',
        optionsSeasonStats: 'Stats de la saison',
        optionsPachinkoNames: 'Montrer les noms au Pachinko',
        optionsMissionsBackground: 'Change l\'arrière-plan des missions',
        optionsCollectMoneyAnimation: 'Désactive l\'animation de récolte d\'argent',
        optionsActivitiesTabChoice: 'Définir l\'onglet principal Missions dans Activités',
        optionsCustomizedHomeScreen: 'Ecran principal personnalisé',
        optionsHideClaimedRewards: 'Masquer les récompenses réclamées',
        optionsDesktopDisplay: 'Mode d\'affichage PC sur mobile',
        optionsHideClaimAllButtons: 'Masquer le bouton "Tout réclamer"',
        optionsHideMultipleLeagueBattlesButton: 'Masquer le bouton x15 dans la ligue',
        optionsRemovePachinkoPopup: 'Supprimer la fenêtre "pas de fille" au Pachinko',
        optionsContestsExpiryTimer: 'Timer pour les récompenses des compét',
        optionsHideLeaguex3Button: 'Masquer le bouton x3 dans la ligue',
        and: 'et',
        or: 'ou',
        including: 'dont',
        affection: 'affection',
        harem_stats: 'Stats du harem',
        haremettes: 'haremettes',
        hardcore: 'Hardcore',
        charm: 'Charme',
        know_how: 'Savoir-faire',
        shagger: 'Niqueur',
        lover: 'Romantique',
        expert: 'Expert',
        Defense_against: 'Défense contre les ',
        specialist_in: 'spécialiste du ',
        harem_levels: 'niveaux de harem',
        to_go: 'restant',
        unlocked_scenes: 'scènes débloquées',
        money_income: 'Revenus',
        per_hour: 'par heure',
        when_all_collectable: 'quand tout est disponible',
        required_to_unlock: 'Requis pour débloquer toutes les scènes',
        required_to_get_tier_max_level: 'Requis pour obtenir toutes les filles au niveau max de leur palier d\'éveil',
        required_to_get_max_level: 'Requis pour obtenir toutes les filles mythiques et légendaires 5 étoiles au niveau ' + lvl_max_girl,
        my_stocks: 'Mes stocks',
        equipments: 'équipements',
        boosters: 'boosters',
        with_boosters: 'Avec boosters',
        no_boosters: 'Sans booster',
        books: 'livres',
        gifts: 'cadeaux',
        Equipments: 'Equipements',
        Boosters: 'Boosters',
        Books: 'Livres',
        Gifts: 'Cadeaux',
        equipment: 'équipement',
        booster: 'booster',
        book: 'livre',
        gift: 'cadeau',
        Equipment: 'Equipement',
        Booster: 'Booster',
        Book: 'Livre',
        Gift: 'Cadeau',
        currently_buyable: 'Stock disponible au marché',
        visit_the: 'Visite le <a href="' + transformNutakuURL('../shop.html') + '">marché</a> first.',
        not_compatible: 'Votre navigateur n\'est pas compatible.',
        or_level: 'ou niveau',
        restock: 'Restock',
        wiki: 'Page wiki de ',
        evolution_costs: 'Ses couts d\'évolution sont',
        world: 'Monde ',
        villain: ' troll',
        fight_villain: 'Combats un troll',
        you_own: 'Tu possèdes',
        you_can_give: 'Tu peux donner un total de',
        you_can_sell: 'Tu peux tout vendre pour',
        stat_points_need: 'Nombre de points requis pour max',
        money_need: 'Argent demandé pour max',
        money_spent: 'Argent dépensé dans le marché',
        points_from_level: 'Points donnés par ton niveau',
        bought_points: 'Points achetés au marché',
        equipment_points: 'Points donnés par ton équipement',
        ginseng_points: 'Points donnés par tes boosters',
        club_points: 'Points donnés par ton club',
        Xp: 'XP',
        starting: 'Fille de départ',
        common: 'Commun',
        rare: 'Rare',
        epic: 'Épique',
        legendary: 'Légendaire',
        mythic: 'Mythique',
        day: 'j',
        hour: 'h',
        minute: 'm',
        second: 's',
        demote_up: 'Pour <u>être rétrogradé</u> vous pouvez avoir un maximum de ',
        demote_down: 'Pour <u>être rétrogradé</u> vous devez être dépassé par les joueurs qui ont ',
        demote_holdzero: 'Pour <u>être rétrogradé</u> vous devez rester avec ',
        stagnate_up: 'Pour <u>ne pas être promu</u> vous pouvez avoir un maximum de ',
        stagnate_down: 'Pour <u>ne pas être promu</u> vous devez être dépassé par les joueurs qui ont ',
        stagnate_holdzero: 'Pour <u>ne pas être promu</u> vous devez rester avec ',
        top4_up: 'Pour <u>être dans le top 4</u> vous devez avoir un minimum de ',
        top4_hold: 'Pour <u>rester dans le top 4</u> vous devez avoir un minimum de ',
        top15_up: 'Pour <u>être dans le top 15</u> vous devez avoir un minimum de ',
        top15_hold: 'Pour <u>rester dans le top 15</u> vous devez avoir un minimum de ',
        top30_up: 'Pour <u>être dans le top 30</u> vous devez avoir un minimum de ',
        top30_hold: 'Pour <u>rester dans le top 30</u> vous devez avoir un minimum de ',
        points: 'points',
        challenges_regen: 'Régénération naturelle: ',
        challenges_left: '<br />Défis restants: ',
        season_fights: 'Combats de Saison: ',
        in: 'dans',
        pop: 'Lieux',
        season: 'Saison',
        full_in: 'Remplie dans',
        ends_at: 'Fin à',
        full: 'Remplie',
        league: 'Ligue',
        boosters_end: 'Fin boosters',
        victories: 'Victoires',
        defeats: 'Defaites',
        unknown: 'Inconnus',
        opponents: 'Adversaires',
        notPlayed: 'Non joués',
        leaguePoints: 'Points',
        avg: 'Moyenne',
        league_ending: 'Ligue terminant le ',
        league_finished: 'Ligue terminée le ',
        current_league: 'Ligue actuelle',
        averageScore: 'Score moyen par combat: ',
        scoreExpected: 'Score attendu: ',
        available_girls: 'Filles disponibles: ',
        fights: 'Combats',
        won_mojo: 'Mojo gagnés',
        lost_mojo: 'Mojo perdus',
        won_mojo_avg: 'Moyenne mojo gagnés',
        lost_mojo_avg: 'Moyenne mojo perdus',
        mojo_avg: 'Moyenne mojo globale',
        filter: 'Filtre',
        searched_name : 'Nom recherché',
        girl_name: 'Nom de la fille',
        searched_class: 'Classe recherchée',
        searched_rarity: 'Rareté recherchée',
        team_number: 'Équipe #',
        all: 'Toutes',
        team: 'Équipe',
        teams: 'Équipes',
        save_as: 'Sauver sous',
        load_from: 'Charger',
        level_range: 'Intervalle de niveaux',
        searched_aff_category: 'Catégorie d\'affection recherchée',
        searched_aff_lvl: 'Niveau d\'affection recherché',
        aff_lvl: 'Niveau d\'affection',
        zero_star: '0 étoile',
        one_star: '1 étoile',
        two_stars: '2 étoiles',
        three_stars: '3 étoiles',
        four_stars: '4 étoiles',
        five_stars: '5 étoiles',
        six_stars: '6 étoiles',
        time_passed: 'du temps a passé',
        combativity: 'Combativité',
        energy: 'Énergie',
        sort: 'Trier',
        hide: 'Masquer',
        display: 'Afficher',
        searched_blessed_attributes: 'Filles bénies recherchées',
        blessed_attributes: 'Filles bénies',
        non_blessed_attributes: 'Filles non bénies',
        pantheon: 'Escaliers du Panthéon',
        searched_element : 'Element recherché',
        element: 'Element',
        dominatrix: 'Dominatrice',
        submissive: 'Soumise',
        voyeur: 'Voyeuse',
        eccentric: 'Excentrique',
        exhibitionist: 'Exhibitioniste',
        physical: 'Physique',
        playful: 'Joueuse',
        sensual: 'Sensuelle',
        clubChampDuration: '{{duration}} depuis le début du tour',
        searched_pose: 'Pose recherchée',
        visit_teams: 'Visiter d\'abord <a href="' + transformNutakuURL('../teams.html') + '">les équipes</a>.',
        next: 'Suiv.',
        Side_quests : 'Quêtes secondaires',
        Club_champion: 'Champion de club',
        Current_positions: 'Positions actuelles',
        Current_stage: 'Niveau actuel',
        Statistics: 'Statistiques',
        Prev_stage: 'Niveau précédent',
        attempt: 'essai',
        attempts: 'essais',
        Gems_in_stock: 'Gemmes en stock',
        missing_gems: 'Gemmes manquantes pour maxer chaque fille mythique ou légendaire 5 étoiles',
        date_on: 'le',
        skilledGirls: 'Filles avec compétences',
        last_season: 'Saison précédente',
        champion_girl_pose: 'Position de la fille du champion',
        none: 'Aucune',
        with: 'Avec',
        tier5_skill_filter: 'Compétences palier 5',
        already_fought: 'Déjà combattus',
        zodiac: {1: '♈︎ Bélier',
                 2: '♉︎ Taureau',
                 3: '♊︎ Gémeaux',
                 4: '♋︎ Cancer',
                 5: '♌︎ Lion',
                 6: '♍︎ Vierge',
                 7: '♎︎ Balance',
                 8: '♏︎ Scorpion',
                 9: '♐︎ Sagittaire',
                 10: '♑︎ Capricorne',
                 11: '♒︎ Verseau',
                 12: '♓︎ Poissons'},
        color: {'F99': 'Rose',
                '00F': 'Bleu',
                'A55': 'Marron',
                '0F0': 'Vert',
                'F0F': 'Violet',
                'FD0': 'Doré',
                'F00': 'Rouge',
                'B06': 'Rose sombre',
                'F90': 'Orange',
                '888': 'Gris',
                'CCC': 'Argent',
                '000': 'Noir',
                'XXX': 'Inconnu',
                '321': 'Brun',
                'B62': 'Châtain',
                'FFF': 'Blanc',
                'FF0': 'Blond',
                'EB8': 'Blond vénitien',
                'D83': 'Bronze'},
    },

    es: {
        optionsVillain: 'Menu Pelear contra villano',
        optionsTiers: 'Mostrar gradas con chicas disponibles',
        optionsXPMoney : 'Mejor XP / Dinero',
        optionsMarket: 'Informacion de Mercado',
        optionsMarketRestockButton: 'Mover el botón "Reponer" del mercado',
        optionsFilterArmorItems: 'Filtrar armaduras del mercado',
        optionsHarem: 'Informacion de Harén',
        optionsHaremFilters: 'Añadir filtros al harén',
        optionsGirlsItemsFilter: 'Filtrar los equipos de chicas',
        optionsLeague: 'Informacion de Liga',
        optionsLeagueBoard: 'Mostrar los mejores de la liga',
        optionsSimLeagueBoardFight: 'Mostrar simulacion en la clasificación de liga',
        optionsSimFight: 'Simulacion de Liga / Temporada / Villano',
        optionsTeamsFilter: 'Filtro de equipos',
        optionsChampions: 'Informacion + atajos para campeones',
        optionsLinks: 'Atajos/Temporizadores',
        optionsSeasonStats: 'Season stats',
        optionsPachinkoNames: 'Mostrar nombres en Pachinko',
        optionsMissionsBackground: 'Cambiar el fondo de las misiones',
        optionsCollectMoneyAnimation: 'Desactivar la animación de recogida de dinero',
        optionsActivitiesTabChoice: 'Establecer misiones como pestaña principal en Actividades',
        optionsCustomizedHomeScreen: 'Pantalla de inicio personalizada',
        optionsHideClaimedRewards: 'Ocultar las recompensas reclamadas',
        optionsDesktopDisplay: 'Modo de visualización PC a móvil',
        optionsHideClaimAllButtons: 'Ocultar el botón "Reclamar todo"',
        optionsHideMultipleLeagueBattlesButton: 'Ocultar el botón x15 en liga',
        optionsRemovePachinkoPopup: 'Eliminar la ventana de "no chica" en Pachinko',
        optionsContestsExpiryTimer: 'Temporizador para recompensas de competitiones',
        optionsHideLeaguex3Button: 'Ocultar el botón x3 en liga',
        and: 'y',
        or: 'o',
        in: 'en',
        including: 'incluido',
        affection: 'afecto',
        harem_stats: 'Estatus del Harén',
        haremettes: 'haremettes',
        hardcore: 'Folladas',
        charm: 'Encanto',
        know_how: 'Saber-hacer',
        shagger: 'Follador',
        lover: 'Amante',
        expert: 'Experto',
        Defense_against: 'Defensa contra ',
        specialist_in: 'especialista en ',
        harem_levels: 'niveles de harén',
        to_go: 'restante',
        unlocked_scenes: 'escenas desbloqueadas',
        money_income: 'Ingreso de dinero',
        per_hour: 'por hora',
        when_all_collectable: 'cuando todo es coleccionable',
        required_to_unlock: 'Requerido para desbloquear todas las escenas bloqueadas',
        required_to_get_tier_max_level: 'Requerido para obtener todas las chicas al máximo nivel de su despertar nivel',
        required_to_get_max_level: 'Requerido para obtener todas las chicas míticas y legendarias de 5 estrellas al nivel ' + lvl_max_girl,
        my_stocks: 'Mi Stock',
        equipments: 'equipos',
        boosters: 'potenciadores',
        with_boosters: 'Con potenciadores',
        no_boosters: 'Sin potenciadores',
        books: 'libros',
        gifts: 'regalos',
        Equipments: 'Equipos',
        Boosters: 'Potenciadores',
        Books: 'Libros',
        Gifts: 'Regalos',
        equipment: 'equipo',
        booster: 'potenciador',
        book: 'libro',
        gift: 'regalo',
        Equipment: 'Equipo',
        Booster: 'Potenciador',
        Book: 'Libro',
        Gift: 'Regalo',
        currently_buyable: 'Stocks Comprables Actualmente',
        visit_the: 'Visita el <a href="' + transformNutakuURL('../shop.html') + '">Mercado</a> primero.',
        not_compatible: 'Tu navegador no es compatible.',
        or_level: 'o nivel',
        restock: 'Restock',
        wiki: 'Página wiki de ',
        evolution_costs: 'Sus costo de evolucion son',
        world: 'Mundo ',
        villain: ' villano',
        fight_villain: 'Pelear un villano',
        you_own: 'Tienes',
        you_can_give: 'Puedes dar un total de',
        you_can_sell: 'Puedes vender todo por',
        stat_points_need: 'Puntos de estatus necesarios para maximo',
        money_need: 'Dinero necesario para maximo',
        money_spent: 'Dinero usado en el mercado',
        points_from_level: 'Puntos de estatus de nivel',
        bought_points: 'Puntos comprados del mercado',
        equipment_points: 'Puntos de estatus de equipamiento',
        ginseng_points: 'Puntos de estatus de los potenciadores',
        club_points: 'Puntos de estatus del club',
        Xp: 'XP',
        starting: 'Principiante',
        common: 'Común',
        rare: 'Raro',
        epic: 'Épico',
        legendary: 'Legendario',
        mythic: 'Mítica',
        day: 'd',
        hour: 'h',
        minute: 'm',
        second: 's',
        demote_up: 'Para <u>degradar</u> puedes tener un máximo de ',
        demote_down: 'Para <u>degradar</u> debes ser superado por jugadores con tan solo ',
        demote_holdzero: 'Para <u>degradar</u> debes mantenerte en ',
        stagnate_up: 'Para <u>no promocionar</u> puedes tener un máximo de ',
        stagnate_down: 'Para <u>no promocionar</u> debes ser superado por jugadores con tan solo ',
        stagnate_holdzero: 'Para <u>no promocionar</u> debes mantenerte en ',
        top4_up: 'Para <u>estar entre los 4 primeros</u> debes tener un mínimo de  ',
        top4_hold: 'Para <u>quedar entre los 4 primeros</u> debes tener un mínimo de  ',
        top15_up: 'Para <u>estar entre los 15 primeros</u> debes tener un mínimo de  ',
        top15_hold: 'Para <u>quedar entre los 15 primeros</u> debes tener un mínimo de  ',
        top30_up: 'Para <u>estar entre los 30 primeros</u> debes tener un mínimo de  ',
        top30_hold: 'Para <u>quedar entre los 30 primeros</u> debes tener un mínimo de  ',
        points: 'puntos',
        challenges_regen: 'Regeneracion naturel: ',
        challenges_left: '<br />Retos pendientes: ',
        pop: 'Lugares',
        season: 'Temporada',
        full_in: 'Completa',
        ends_at: 'Fin a las',
        full: 'Completa',
        league: 'Liga',
        boosters_end: 'Fin potenc.',
        victories: 'Victorias',
        defeats: 'Derrota',
        unknown: 'Desconocido',
        opponents: 'Oponentes',
        notPlayed: 'No jugado',
        leaguePoints: 'Puntos',
        avg: 'Media',
        league_ending: 'Liga termina el ',
        league_finished: 'Liga terminó el ',
        current_league: 'Liga actual',
        averageScore: 'Puntuación media por combate: ',
        scoreExpected: 'Puntuación esperada: ',
        available_girls: 'Chicas disponibles: ',
        fights: 'Fights',
        won_mojo: 'Won mojo',
        lost_mojo: 'Lost mojo',
        won_mojo_avg: 'Won mojo average',
        lost_mojo_avg: 'Lost mojo average',
        mojo_avg: 'Global mojo average',
        filter: 'Filtro',
        searched_name : 'Nombre buscado',
        girl_name: 'Nombre de la chica',
        searched_class: 'Clase buscada',
        searched_rarity: 'Rareza buscada',
        team_number: 'Equipo #',
        all: 'Todo',
        team: 'Equipo',
        teams: 'Equipos',
        save_as: 'Guardar como',
        load_from: 'Carga',
        level_range: 'Rango de nivel',
        searched_aff_category: 'Categoría de afecto buscada',
        searched_aff_lvl: 'Nivel de afecto buscado',
        aff_lvl: 'Nivel de afecto',
        zero_star: '0 estrella',
        one_star: '1 estrella',
        two_stars: '2 estrellas',
        three_stars: '3 estrellas',
        four_stars: '4 estrellas',
        five_stars: '5 estrellas',
        six_stars: '6 estrellas',
        time_passed: 'del tiempo ha pasado',
        combativity: 'Combatividad',
        energy: 'Energía',
        sort: 'Ordenar',
        hide: 'Ocultar',
        display: 'Mostrar',
        searched_blessed_attributes: 'Chicas bendecidas buscadas',
        blessed_attributes: 'Benditas chicas',
        non_blessed_attributes: 'Chicas no bendecidas',
        pantheon: 'Escalera del Panteón',
        searched_element : 'Elemento buscado',
        element: 'Elemento',
        dominatrix: 'Dominatrix',
        submissive: 'Sumisa',
        voyeur: 'Voyeur',
        eccentric: 'Excéntrica',
        exhibitionist: 'Exhibicionista',
        physical: 'Física',
        playful: 'Juguetona',
        sensual: 'Sensual',
        clubChampDuration: '{{duration}} desde el comienzo de la ronda',
        searched_pose: 'Pose buscada',
        visit_teams: 'Visita el <a href="' + transformNutakuURL('../teams.html') + '">Equipos</a> primero.',
        next: 'Sigui.',
        Side_quests : 'Misiones secundarias',
        Club_champion: 'Campeón de club',
        Current_positions: 'Posiciones actuales',
        Current_stage: 'Fase actual',
        Statistics: 'Estadísticas',
        Prev_stage: 'Fase previa',
        attempt: 'intento',
        attempts: 'intentos',
        Gems_in_stock: 'Gemas en stock',
        missing_gems: 'Gemas que faltan para maximizar cada chica mítica o legendaria de 5 estrellas',
        date_on: 'del',
        skilledGirls: 'Chicas con habilidades',
        last_season: 'Temporada anterior',
        champion_girl_pose: 'Pose de chica campeona',
        none: 'Ninguna',
        with: 'Con',
        tier5_skill_filter: 'Habilidades nivel 5',
        already_fought: 'Ya luchó',
        zodiac: {1: '♈︎ Aries',
                 2: '♉︎ Tauro',
                 3: '♊︎ Géminis',
                 4: '♋︎ Cáncer',
                 5: '♌︎ Leo',
                 6: '♍︎ Virgo',
                 7: '♎︎ Libra',
                 8: '♏︎ Escorpión',
                 9: '♐︎ Sagitario',
                 10: '♑︎ Capricornio',
                 11: '♒︎ Acuario',
                 12: '♓︎ Piscis'},
        color: {'F99': 'Rosa',
                '00F': 'Azul',
                'A55': 'Marrón',
                '0F0': 'Verde',
                'F0F': 'Lila',
                'FD0': 'Dorado',
                'F00': 'Rojo',
                'B06': 'Rosa oscuro',
                'F90': 'Naranja',
                '888': 'Gris',
                'CCC': 'Platino',
                '000': 'Negro',
                'XXX': 'Desconocido',
                '321': 'Oscuro',
                'B62': 'Marrón',
                'FFF': 'Blanco',
                'FF0': 'Rubio',
                'EB8': 'Rubio rojizo',
                'D83': 'Cronce'},
    },

    it: {
        optionsVillain: 'Menù battaglia Troll',
        optionsTiers: 'Mostra i livelli con le ragazze disponibili',
        optionsXPMoney : 'Migliora XP / soldi',
        optionsMarket: 'Informazioni negozio',
        optionsMarketRestockButton: 'Spostate il pulsante "Rifornisci" del mercato',
        optionsFilterArmorItems: 'Filtrare armature di mercato',
        optionsHarem: 'Informazioni Harem',
        optionsHaremFilters: 'Aggiungere filtri all\'harem',
        optionsGirlsItemsFilter: 'Filtrare le attrezzature delle ragazze',
        optionsLeague: 'Informazioni sulle Leghe',
        optionsLeagueBoard: 'Mostra i top della lega',
        optionsSimLeagueBoardFight: 'Visualizzazione simulazione nella classifica della lega',
        optionsSimFight: 'Simulazione Leghe / Stagione / Troll',
        optionsTeamsFilter: 'Filtro delle squadre',
        optionsChampions: 'Informazioni + scorciatoie per i campioni',
        optionsLinks: 'Scorciatoie/Timer',
        optionsSeasonStats: 'Season stats',
        optionsPachinkoNames: 'Mostra i nomi in Pachinko',
        optionsMissionsBackground: 'Cambiare lo sfondo delle missioni',
        optionsCollectMoneyAnimation: 'Disattivare l\'animazione di raccolta dei soldi',
        optionsActivitiesTabChoice: 'Impostare Missioni come scheda principale in Attività',
        optionsCustomizedHomeScreen: 'Schermata iniziale personalizzata',
        optionsHideClaimedRewards: 'Nascondere le ricompense reclamate',
        optionsDesktopDisplay: 'Modalità di visualizzazione PC a cellulare',
        optionsHideClaimAllButtons: 'Nascondere il pulsante "Rivendica tutto"',
        optionsHideMultipleLeagueBattlesButton: 'Nascondere il pulsante x15 nella lega',
        optionsRemovePachinkoPopup: 'Rimuovere la finestra "nessuna ragazza" in Pachinko',
        optionsContestsExpiryTimer: 'Timer per i premi dei concorsi',
        optionsHideLeaguex3Button: 'Nascondere il pulsante x3 nella lega',
        and: 'e',
        or: 'o',
        in: 'in',
        including: 'incluso',
        affection: 'affetto',
        harem_stats: 'Stato dell Harem',
        haremettes: 'ragazze dell harem',
        hardcore: 'Prono',
        charm: 'Fascino',
        know_how: 'Competenza',
        shagger: 'Scopata',
        lover: 'Amante',
        expert: 'Esperto',
        Defense_against: 'Difesa contro ',
        specialist_in: 'specialista in ',
        harem_levels: 'livelli harem',
        to_go: 'mancanti',
        unlocked_scenes: 'scene sbloccate',
        money_income: 'Guadagni',
        per_hour: 'orario',
        when_all_collectable: 'quando si può raccogliere tutto',
        required_to_unlock: 'Necessario per sbloccare tutte le scene',
        required_to_get_tier_max_level: 'Necessario per livellare tutte le ragazze al massimo livello di risveglio livello',
        required_to_get_max_level: 'Necessario per livellare tutte le ragazze mitiche e leggendarie a 5 stelle al livello ' + lvl_max_girl,
        my_stocks: 'Mio inventario',
        equipments: 'attrezzature',
        boosters: 'potenziamenti',
        with_boosters: 'Con potenziamenti',
        no_boosters: 'Senza potenziamenti',
        books: 'libri',
        gifts: 'regali',
        Equipments: 'Attrezzature',
        Boosters: 'Potenziamenti',
        Books: 'Libri',
        Gifts: 'Regali',
        equipment: 'attrezzatura',
        booster: 'potenziamento',
        book: 'libro',
        gift: 'regalo',
        Equipment: 'Attrezzatura',
        Booster: 'Potenziamento',
        Book: 'Libro',
        Gift: 'Regalo',
        currently_buyable: 'Correntemente acquistabili',
        visit_the: 'Visita il <a href="' + transformNutakuURL('../shop.html') + '">negozio</a> prima.',
        not_compatible: 'Il tuo browser non è compatibile.',
        or_level: 'o livello',
        restock: 'Rifornimento',
        wiki: 'Pagina wiki di ',
        evolution_costs: 'Il costo del potenziamento è',
        world: 'Mondo ',
        villain: ' nemico',
        fight_villain: 'Combattimenti',
        you_own: 'Possiedi',
        you_can_give: 'Puoi dare il massimo a',
        you_can_sell: 'Puoi vendere tutto per',
        stat_points_need: 'Punti statistica necessari per il massimo',
        money_need: 'Soldi necessari per il massimo',
        money_spent: 'Soldi spesi al negozio',
        points_from_level: 'Punti acquisiti da aumento livello',
        bought_points: 'Punti comprati al negozio',
        equipment_points: 'Punti statistica da equipaggiamento',
        ginseng_points: 'Punti statistica dei potenziamenti',
        club_points: 'Punti statistica bonus del Club',
        Xp: 'XP',
        starting: 'Starter',
        common: 'Comuni',
        rare: 'Rare',
        epic: 'Epiche',
        legendary: 'Leggendarie',
        mythic: 'Mitica',
        day: 'g',
        hour: 'h',
        minute: 'm',
        second: 's',
        demote_up: 'Per <u>il degrado</u> devi avere al massimo ',
        demote_down: 'Per <u>il degrado</u> devi essere sorpassato da giocatori con ',
        demote_holdzero: 'Per <u>il degrado</u> devi rimanere a ',
        stagnate_up: 'Per <u>restare</u> devi avere al massimo ',
        stagnate_down: 'Per <u>restare</u> devi essere sorpassato da giocatori con ',
        stagnate_holdzero: 'Per <u>restare</u> devi rimanere a ',
        top4_up: 'Per <u>essere tra i primi 4</u> devi avere un minimo di ',
        top4_hold: 'Per <u>rimanere tra i primi 4</u> devi avere un minimo di ',
        top15_up: 'Per <u>essere tra i primi 15</u> devi avere un minimo di ',
        top15_hold: 'Per <u>rimanere tra i primi 15</u> devi avere un minimo di ',
        top30_up: 'Per <u>essere tra i primi 30</u> devi avere un minimo di ',
        top30_hold: 'Per <u>rimanere tra i primi 30</u> devi avere un minimo di ',
        points: 'punti',
        challenges_regen: 'Rigenerazione naturale: ',
        challenges_left: '<br />Combattimenti mancanti: ',
        pop: 'Luoghi',
        season: 'Stagione',
        full_in: 'Piena tra',
        ends_at: 'Fine alle',
        full: 'Piena',
        league: 'Leghe',
        boosters_end: 'Fine potenz.',
        victories: 'Vittorie',
        defeats: 'Sconfitte',
        unknown: 'Sconosciuto',
        opponents: 'Avversari',
        notPlayed: 'Non giocato',
        leaguePoints: 'Punti',
        avg: 'Medio',
        league_ending: 'Fine della lega il ',
        league_finished: 'Lega finita il ',
        current_league: 'Lega attuale',
        averageScore: 'Punteggio medio per combattimento: ',
        scoreExpected: 'Punteggio previsto: ',
        available_girls: 'Ragazze disponibili: ',
        fights: 'Fights',
        won_mojo: 'Won mojo',
        lost_mojo: 'Lost mojo',
        won_mojo_avg: 'Won mojo average',
        lost_mojo_avg: 'Lost mojo average',
        mojo_avg: 'Global mojo average',
        filter: 'Filtro',
        searched_name : 'Nome ricercato',
        girl_name: 'Nome della ragazza',
        searched_class: 'Classe ricercata',
        searched_rarity: 'Rarità ricercata',
        team_number: 'Squadra #',
        all: 'Tutti',
        team: 'Squadra',
        teams: 'Squadre',
        save_as: 'Salvare come',
        load_from: 'Caricare',
        level_range: 'Gamma di livelli',
        searched_aff_category: 'Categoria di affetto ricercata',
        searched_aff_lvl: 'Livello di affetto ricercato',
        aff_lvl: 'Livello di affetto',
        zero_star: '0 stella',
        one_star: '1 stella',
        two_stars: '2 stelle',
        three_stars: '3 stelle',
        four_stars: '4 stelle',
        five_stars: '5 stelle',
        six_stars: '6 stelle',
        time_passed: 'del tempo è passato',
        combativity: 'Combattività',
        energy: 'Energia',
        sort: 'Ordinare',
        hide: 'Nascondere',
        display: 'Visualizzare',
        searched_blessed_attributes: 'Cercato ragazze benedette',
        blessed_attributes: 'Ragazze benedette',
        non_blessed_attributes: 'Ragazze non benedette',
        pantheon: 'Scalinata del Pantheon',
        searched_element : 'Elemento ricercato',
        element: 'Elemento',
        dominatrix: 'Dominatrice',
        submissive: 'Sottomessa',
        voyeur: 'Guardona',
        eccentric: 'Eccentrica',
        exhibitionist: 'Esibizionista',
        physical: 'Fisica',
        playful: 'Giocosa',
        sensual: 'Sensuale',
        clubChampDuration: '{{duration}} dall\'inizio del round',
        searched_pose: 'Posa ricercata',
        visit_teams: 'Visita le <a href="' + transformNutakuURL('../teams.html') + '">Squadre</a> prima.',
        next: 'Pross.',
        Side_quests : 'Missioni secondarie',
        Club_champion: 'Campione di club',
        Current_positions: 'Posizioni attuali',
        Current_stage: 'Fase attuale',
        Statistics: 'Statistiche',
        Prev_stage: 'Fase precedente',
        attempt: 'tentativo',
        attempts: 'tentativi',
        Gems_in_stock: 'Gemme in stock',
        missing_gems: 'Gemme mancanti per massimizzare ogni ragazza mitica o leggendaria a 5 stelle',
        date_on: 'del',
        skilledGirls: 'Ragazze con abilità',
        last_season: 'Stagione precedente',
        champion_girl_pose: 'Posa della ragazza del campione',
        none: 'Nessuna',
        with: 'Con',
        tier5_skill_filter: 'Abilità livello 5',
        already_fought: 'Già combattuti',
        zodiac: {1: '♈︎ Ariete',
                 2: '♉︎ Toro',
                 3: '♊︎ Gemelli',
                 4: '♋︎ Cancro',
                 5: '♌︎ Leone',
                 6: '♍︎ Vergine',
                 7: '♎︎ Bilancia',
                 8: '♏︎ Scorpione',
                 9: '♐︎ Sagittario',
                 10: '♑︎ Capricorno',
                 11: '♒︎ Aquario',
                 12: '♓︎ Pesci'},
        color: {'F99': 'Rosa',
                '00F': 'Blu',
                'A55': 'Marrone',
                '0F0': 'Verde',
                'F0F': 'Viola',
                'FD0': 'Dorato',
                'F00': 'Rosso',
                'B06': 'Rosa scuro',
                'F90': 'Arancio',
                '888': 'Grigio',
                'CCC': 'Argento',
                '000': 'Nero',
                'XXX': 'Sconosciuto',
                '321': 'Scuro',
                'B62': 'Castano',
                'FFF': 'Bianco',
                'FF0': 'Biondo',
                'EB8': 'Biondo veneziano',
                'D83': 'Bronzo'},
    },

    de: {
        optionsVillain: 'Widersacher-Menü',
        optionsTiers: 'Stufen mit verfügbaren Mädchen anzeigen',
        optionsXPMoney : 'Migliora XP / soldi',
        optionsMarket: 'Marktplatz-Informationen',
        optionsMarketRestockButton: 'Verschieben Sie die Schaltfläche "Auffüllen"',
        optionsFilterArmorItems: 'Filter Markt Rüstungen',
        optionsHarem: 'Harem-Informationen',
        optionsHaremFilters: 'Filter im Harem hinzufügen',
        optionsGirlsItemsFilter: 'Filtern der Mädchenausrüstungen',
        optionsLeague: 'Liga-Informationen',
        optionsLeagueBoard: 'Die Liga-Spitzen anzeigen',
        optionsSimLeagueBoardFight: 'Anzeige Simulation in der Liga-Rangliste',
        optionsSimFight: 'Liga/Saison/Widersacher-Simulation',
        optionsTeamsFilter: 'Mannschaften filtern',
        optionsChampions: 'Informationen + Abkürzungen für Champions',
        optionsLinks: 'Abkürzungen/Zeitgeber',
        optionsSeasonStats: 'Season stats',
        optionsPachinkoNames: 'Namen in Pachinko anzeigen',
        optionsMissionsBackground: 'Missionshintergrund ändern',
        optionsCollectMoneyAnimation: 'Deaktivieren Sie die Animation "Geld sammeln"',
        optionsActivitiesTabChoice: 'Missionen als Hauptregisterkarte in Aktivitäten festlegen',
        optionsCustomizedHomeScreen: 'Benutzerdefinierter Startbildschirm',
        optionsHideClaimedRewards: 'Beanspruchte Belohnungen ausblenden',
        optionsDesktopDisplay: 'Anzeigemodus PC auf Handy',
        optionsHideClaimAllButtons: 'Schaltfläche "Alles beanspruchen" ausblenden',
        optionsHideMultipleLeagueBattlesButton: 'Schaltfläche x15 in der Liga ausblenden',
        optionsRemovePachinkoPopup: 'Das Fenster "Kein Mädchen" in Pachinko entfernen',
        optionsContestsExpiryTimer: 'Timers für Wettbewerbe Belohnungen',
        optionsHideLeaguex3Button: 'Schaltfläche x3 in der Liga ausblenden',
        and: 'und',
        or: 'oder',
        in: 'in',
        including: 'einschließlich',
        affection: 'Zuneigung',
        harem_stats: 'Harem-Statistiken',
        haremettes: 'Harem-Mädchen',
        hardcore: 'Hardcore',
        charm: 'Charme',
        know_how: 'Wissen',
        shagger: 'Stecher',
        lover: 'Liebhaber',
        expert: 'Experte',
        Defense_against: 'Verteidigung gegen ',
        specialist_in: 'spezialisiert auf ',
        harem_levels: 'Harem-Levels',
        to_go: 'übrig',
        unlocked_scenes: 'Szenen freigeschaltet',
        money_income: 'Einkommen',
        per_hour: 'pro Stunde',
        when_all_collectable: 'wenn komplett einsammelbar',
        required_to_unlock: 'Erforderlich für alle Mädchen-Upgrades',
        required_to_get_tier_max_level: 'Erforderlich für die maximale Mädchen-Level ihrer Erweckungsstufe',
        required_to_get_max_level: 'Erforderlich für alle mythischen und legendären 5-Sterne-Mädchen auf Stufe ' + lvl_max_girl,
        my_stocks: 'Meine Bestände',
        equipments: 'Ausrüstungen',
        boosters: 'Booster',
        with_boosters: 'Mit Booster',
        no_boosters: 'Keine Booster',
        books: 'Bücher',
        gifts: 'Geschenke',
        Equipments: 'Ausrüstungen',
        Boosters: 'Booster',
        Books: 'Bücher',
        Gifts: 'Geschenke',
        equipment: 'Ausrüstung',
        booster: 'Booster',
        book: 'Buch',
        gift: 'Geschenk',
        Equipment: 'Ausrüstung',
        Booster: 'Booster',
        Book: 'Buch',
        Gift: 'Geschenk',
        currently_buyable: 'Aktuelle Marktangebote',
        visit_the: 'Besuche zuerst den <a href="' + transformNutakuURL('../shop.html') + '">Marktplatz</a>.',
        not_compatible: 'Dein Browser ist nicht kompatibel.',
        or_level: 'oder Level',
        restock: 'neue Angebote',
        wiki: '\'s Wiki-Seite',
        evolution_costs: 'Die Upgradekosten betragen',
        world: 'Welt ',
        villain: ' Widersacher',
        fight_villain: 'Widersacher',
        you_own: 'Du besitzt',
        you_can_give: 'Insgesamt verteilbar:',
        you_can_sell: 'Du kannst alles verkaufen für',
        stat_points_need: 'benötigte Statuspunkte bis Maximum',
        money_need: 'nötiges Geld bis Maximum',
        money_spent: 'bisher ausgegeben',
        points_from_level: 'Statuspunkte durch Heldenlevel',
        bought_points: 'gekaufte Statuspunkte',
        equipment_points: 'Statuspunkte durch Ausrüstung',
        ginseng_points: 'Statuspunkte durch Booster',
        club_points: 'Statuspunkte durch Club-Boni',
        Xp: 'XP',
        starting: 'Starter',
        common: 'Gewöhnliche',
        rare: 'Seltene',
        epic: 'Epische',
        legendary: 'Legendäre',
        mythic: 'Mythische',
        day: 'd',
        hour: 'h',
        minute: 'm',
        second: 's',
        demote_up: 'Für den <u>Abstieg</u> maximal möglich: ',
        demote_down: 'Für den <u>Abstieg</u> musst du überholt werden von Spielern mit höchstens ',
        demote_holdzero: 'Für den <u>Abstieg</u> musst du verbleiben bei ',
        stagnate_up: 'Für den <u>Nichtaufstieg</u> maximal möglich: ',
        stagnate_down: 'Für den <u>Nichtaufstieg</u> musst du überholt werden von Spielern mit höchstens ',
        stagnate_holdzero: 'Für den <u>Nichtaufstieg</u> musst du verbleiben bei ',
        top4_up: 'Um <u>in den Top 4 zu kommen</u>, musst du mindestens folgende Voraussetzungen erfüllen  ',
        top4_hold: 'Um <u>in den Top 4 zu bleiben</u>, musst du mindestens folgende Voraussetzungen erfüllen  ',
        top15_up: 'Um <u>in den Top 15 zu kommen</u>, musst du mindestens folgende Voraussetzungen erfüllen  ',
        top15_hold: 'Um <u>in den Top 15 zu bleiben</u>, musst du mindestens folgende Voraussetzungen erfüllen  ',
        top30_up: 'Um <u>in den Top 30 zu kommen</u>, musst du mindestens folgende Voraussetzungen erfüllen  ',
        top30_hold: 'Um <u>in den Top 30 zu bleiben</u>, musst du mindestens folgende Voraussetzungen erfüllen  ',
        points: 'Punkte',
        challenges_regen: 'Regeneration: ',
        challenges_left: '<br />verbleibende Kämpfe: ',
        pop: 'Orte',
        season: 'Saison',
        full_in: 'Voll in',
        ends_at: 'Ende um',
        full: 'Voll',
        league: 'Liga',
        boosters_end: 'Booster enden',
        victories: 'Siege',
        defeats: 'Niederlagen',
        unknown: 'Unbekannt',
        opponents: 'Gegner',
        notPlayed: 'Nicht gespielt',
        leaguePoints: 'Punkte',
        avg: 'Mittelwert',
        league_ending: 'Liga Ende ',
        league_finished: 'Liga endete am',
        current_league: 'Aktuelle Liga',
        averageScore: 'Durchschnitt pro Kampf: ',
        scoreExpected: 'Erwartetes Ergebnis: ',
        available_girls: 'Freie Mädchen: ',
        fights: 'Kämpfe',
        won_mojo: 'gewonnenes Mojo',
        lost_mojo: 'verlorenes Mojo',
        won_mojo_avg: 'im Mittel gewonnenes Mojo',
        lost_mojo_avg: 'im Mittel verlorenes Mojo',
        mojo_avg: 'Globales mittleres Mojo',
        filter: 'Filter',
        searched_name : 'Name',
        girl_name: 'Mädchen Name',
        searched_class: 'Klasse',
        searched_rarity: 'Seltenheit',
        team_number: 'Team #',
        all: 'Alle',
        team: 'Mannschaft',
        teams: 'Mannschaften',
        save_as: 'Speichern',
        load_from: 'Laden',
        level_range: 'Level',
        searched_aff_category: 'Maximale Zuneigung',
        searched_aff_lvl: 'Zuneigungslevel',
        aff_lvl: 'Zuneigungslevel',
        aff_lvl: 'Livello di affetto',
        zero_star: '0 Sterne',
        one_star: '1 Stern',
        two_stars: '2 Sterne',
        three_stars: '3 Sterne',
        four_stars: '4 Sterne',
        five_stars: '5 Sterne',
        six_stars: '6 Sterne',
        time_passed: 'Zeit ist vergangen',
        combativity: 'Kampflust',
        energy: 'Energie',
        sort: 'Sortieren',
        hide: 'Ausblenden',
        display: 'Anzeigen',
        searched_blessed_attributes: 'Segnungen',
        blessed_attributes: 'gesegnet',
        non_blessed_attributes: 'nicht gesegnet',
        pantheon: 'Aufstieg zum Pantheon',
        searched_element : 'Element',
        dominatrix: 'Domina',
        submissive: 'Unterwürfig',
        voyeur: 'Voyeur',
        eccentric: 'Exzentrisch',
        exhibitionist: 'Exhibitionist',
        physical: 'Körperlich',
        playful: 'Verspielt',
        sensual: 'Sinnlich',
        clubChampDuration: '{{duration}} seit Rundenbeginn',
        searched_pose: 'Stellung',
        visit_teams: 'Besuche zuerst die <a href="' + transformNutakuURL('../teams.html') + '">Teams</a>.',
        next: 'Näch.',
        Side_quests : 'Nebenquests',
        Club_champion: 'Clubmeister',
        Current_positions: 'Aktuelle Positionen',
        Current_stage: 'Aktuelle Etappe',
        Statistics: 'Statistik',
        Prev_stage: 'Vorherige Etappe',
        attempt: 'Versuch',
        attempts: 'Versuche',
        Gems_in_stock: 'Edelsteine auf Lager',
        missing_gems: 'Fehlende Edelsteine, um jedes mythische oder legendäre 5-Sterne-Mädchen zu maximieren',
        date_on: 'am',
        skilledGirls: 'Mädchen mit Fertigkeiten',
        last_season: 'Letzte Saison',
        champion_girl_pose: 'Stellung der Championsmädchen',
        none: 'Keine',
        with: 'Mit',
        tier5_skill_filter: 'Stufe 5 Fertigkeiten',
        already_fought: 'Bereits bekämpft',
        zodiac: {1: '♈︎ Widder',
                 2: '♉︎ Stier',
                 3: '♊︎ Zwillinge',
                 4: '♋︎ Krebs',
                 5: '♌︎ Löwe',
                 6: '♍︎ Jungfrau',
                 7: '♎︎ Waage',
                 8: '♏︎ Skorpion',
                 9: '♐︎ Schütze',
                 10: '♑︎ Steinbock',
                 11: '♒︎ Wassermann',
                 12: '♓︎ Fische'},
        color: {'F99': 'Pink',
                '00F': 'Blau',
                'A55': 'Braun',
                '0F0': 'Grün',
                'F0F': 'Lila',
                'FD0': 'Gold',
                'F00': 'Rot',
                'B06': 'Dunkelpink',
                'F90': 'Orange',
                '888': 'Grau',
                'CCC': 'Silber',
                '000': 'Schwarz',
                'XXX': 'Unbekannt',
                '321': 'Dunkel',
                'B62': 'Dunkelblond',
                'FFF': 'Weiß',
                'FF0': 'Blond',
                'EB8': 'Erdbeerblond',
                'D83': 'Bronze'},
    }
}

// Numbers: rounding to K, M, G and T
function nRounding(num, digits, updown) {
    let power = [
        { value: 1, symbol: '' },
        { value: 1E3, symbol: 'K' },
        { value: 1E6, symbol: 'M' },
        { value: 1E9, symbol: 'B' },
        { value: 1E12, symbol: 'T' },
    ];
    let i;
    for (i = power.length - 1; i > 0; i--) {
        if (num >= power[i].value) {
            break;
        }
    }
    if (updown == 1) {
        return nThousand(+(Math.ceil(num / power[i].value * Math.pow(10, digits)) / Math.pow(10, digits)).toFixed(digits)) + power[i].symbol;
    }
    else if (updown == 0) {
        return nThousand(+(Math.round(num / power[i].value * Math.pow(10, digits)) / Math.pow(10, digits)).toFixed(digits)) + power[i].symbol;
    }
    else if (updown == -1) {
        return nThousand(+(Math.floor(num / power[i].value * Math.pow(10, digits)) / Math.pow(10, digits)).toFixed(digits)) + power[i].symbol;
    }
}

// Thousand spacing
function nThousand(x) {
    if(typeof x != 'number') {
        return 0;
    }
    switch(pageLang){ //atm this shows the numbers equal to the game
        case 'ja':
        case 'en': return x.toLocaleString("en")
        default: return x.toLocaleString("fr")
    }
}

function localeStringToNumber(s){
    let e = s.replace(/[^0-9]/gi,'x').split('x')
    switch(e.length){
        case 0: return 0
        case 1: return +e[0]
        default: break
    }
    let f =e.pop()
    e = e.toString().replace(/[^0-9]/gi,'')
    switch(f.length){
        case 1: return parseFloat(e)+f/10
        case 2: return parseFloat(e)+f/100
        default: return parseFloat(e+f)
    }
}

let lang = "en";
const pageLang = $('html')[0].lang.substring(0,2);
if(texts[pageLang]) lang=pageLang;

const labels = texts[lang];
const label = (key) => (labels && labels[key]) || texts.en[key];

let locale = 'fr';
if (lang == 'en') {
    locale = 'en'
}

var DST;
calculateDST();

function calculateDST() {
    if(((new Date).getUTCMonth() >= 3 && (new Date).getUTCMonth() <= 8) || ((new Date).getUTCMonth() == 9 && (new Date).getUTCDate() < 25))
        DST = true;
    else if((new Date).getUTCMonth() >= 10 || (new Date).getUTCMonth() <= 1 || ((new Date).getUTCMonth() == 2 && (new Date).getUTCDate() < 25))
        DST = false;
    else if((new Date).getUTCMonth() == 2 && (new Date).getUTCDate() >= 25) {
        if((new Date).getUTCDate() + (7-(new Date).getUTCDay()) <= 31 && (new Date).getUTCDay() != 0)
            DST = false;
        else {
            if((new Date).getUTCHours() >= 1) DST = true;
            else DST = false;
        }
    }
    else if((new Date).getUTCMonth() == 9 && (new Date).getUTCDate() >= 25) {
        if((new Date).getUTCDate() + (7-(new Date).getUTCDay()) <= 31 && (new Date).getUTCDay() != 0)
            DST = true;
        else {
            if((new Date).getUTCHours() >= 1) DST = false;
            else DST = true;
        }
    }
}

const GIRLS_EXP_LEVELS = {
    starting : [10],
    common : [10],
    rare : [12],
    epic : [14],
    legendary : [16],
    mythic : [40]
}
calculateGirlXPTab();

function calculateGirlXPTab() {
    for (let i=1; i < (lvl_max_girl-1); i++) {
        GIRLS_EXP_LEVELS.starting[i] = GIRLS_EXP_LEVELS.starting[(i-1)] + Math.ceil(GIRLS_EXP_LEVELS.starting[0]*Math.pow(1.0075, i));
        GIRLS_EXP_LEVELS.common[i] = GIRLS_EXP_LEVELS.common[(i-1)] + Math.ceil(GIRLS_EXP_LEVELS.common[0]*Math.pow(1.0075, i));
        GIRLS_EXP_LEVELS.rare[i] = GIRLS_EXP_LEVELS.rare[(i-1)] + Math.ceil(GIRLS_EXP_LEVELS.rare[0]*Math.pow(1.0075, i));
        GIRLS_EXP_LEVELS.epic[i] = GIRLS_EXP_LEVELS.epic[(i-1)] + Math.ceil(GIRLS_EXP_LEVELS.epic[0]*Math.pow(1.0075, i));
        GIRLS_EXP_LEVELS.legendary[i] = GIRLS_EXP_LEVELS.legendary[(i-1)] + Math.ceil(GIRLS_EXP_LEVELS.legendary[0]*Math.pow(1.0075, i));
        GIRLS_EXP_LEVELS.mythic[i] = GIRLS_EXP_LEVELS.mythic[(i-1)] + Math.ceil(GIRLS_EXP_LEVELS.mythic[0]*Math.pow(1.0075, i));
    }
}

const AWAKENING_GEMS_COST = {
    starting: [0, 40, 60, 80, 100, 125, 150, 200, 275, 350, 500],
    common: [0, 40, 60, 80, 100, 125, 150, 200, 275, 350, 500],
    rare: [0, 80, 120, 160, 200, 250, 300, 400, 550, 700, 1000],
    epic: [0, 120, 180, 240, 300, 375, 450, 600, 825, 1050, 1500],
    legendary: [0, 160, 240, 320, 400, 500, 600, 800, 1100, 1400, 2000],
    mythic: [0, 200, 300, 400, 500, 625, 750, 1000, 1375, 1750, 2500]
};
const AWAKENING_REQUIREMENT = [20, 25, 30, 35, 40, 50, 60, 70, 85, 100];
const AWAKENING_LEVELS = [250, 300, 350, 400, 450, 500, 550, 600, 650, 700];

/**
 * ELEMENTS ASSUMPTIONS
 *
 * 1) Girl and Harem synergy bonuses for Attack, Defense, Ego and Harmony are already included in the shown stats
 * 2) Countering bonuses are not included in any shown stats
 *
 * ELEMENTS FACTS
 *
 * 1) Crit damage and chance bonuses are additive; Ego and damage bonuses are multiplicative
 * 2) Opponent harem synergies are only available to the player in the leagues
 */
const ELEMENTS = {
    chance: {
        darkness: 'light',
        light: 'psychic',
        psychic: 'darkness'
    },
    egoDamage: {
        fire: 'nature',
        nature: 'stone',
        stone: 'sun',
        sun: 'water',
        water: 'fire'
    }
}
const ELEMENTS_ICON_NAMES = {
    "darkness": "Dominatrix",
    "light": "Submissive",
    "psychic": "Voyeurs",
    "fire": "Eccentric",
    "nature": "Exhibitionist",
    "stone": "Physical",
    "sun": "Playful",
    "water": "Sensual",
}

const tier5_Skill_Id = [11, 12, 13, 14];

const timeout = 250;

const mediaMobile = '@media only screen and (max-width: 1025px)';
const mediaDesktop = '@media only screen and (min-width: 1026px)';

const DEFAULT_BOOSTERS = {normal: [], mythic:[]};
const MAX_BOOSTERS = {normal: 4, mythic: 5};

var trolls;
var tierGirlsID = [];

function editTrollsAndTiers() {
    if (window.HH_UNIVERSE == 'hentai' || window.HH_UNIVERSE == 'horny_s' || window.HH_UNIVERSE == 'nutaku' || window.HH_UNIVERSE == 'test_h' || window.HH_UNIVERSE == 'hh_eroges') {
        trolls = ['Dark Lord', 'Ninja Spy', 'Gruntt', 'Edwarda', 'Donatien', 'Silvanus', 'Bremen', 'Finalmecia', 'Fredy Sih Roko Senseï', 'Karole', 'Jackson&#8217;s Crew', 'Pandora Witch', 'Nike', 'Sake', 'WereBunny Police', 'Auga', 'Gross'];
        if (lang == 'fr') {
            trolls[1] = 'Espion Ninja';
            trolls[10] = 'Éq. de Jackson';
            trolls[11] = 'Sorcière Pandora';
            trolls[14] = 'Police des Lapines-Garous';
        }
        if (lang == 'es') {
            trolls[0] = 'Señor Oscuro';
            trolls[1] = 'Ninja espía';
            trolls[10] = 'Tripulación de Jackson';
            trolls[11] = 'Pandora Bruja';
            trolls[14] = 'Policía hombres-conejos';
        }
        if (lang == 'it') {
            trolls[0] = 'Signore Oscuro';
            trolls[1] = 'Spia Ninja';
            trolls[10] ='Ciurma di Jackson';
            trolls[11] ='Strega Pandora';
            trolls[14] = 'Polizia del Conigli Mannari';
        }
        if (lang == 'de') {
            trolls[0] = 'Dunkler Lord';
            trolls[1] = 'Ninjaspion';
            trolls[10] ='Jacksons Crew';
            trolls[11] ='Pandora Hexe';
            trolls[14] = 'Wer-Kaninchen Polizei';
        }

        tierGirlsID = [
            [['8', '9', '10'], ['7270263'], ['979916751']],
            [['14', '13', '12'], ['318292466'], ['936580004']],
            [['19', '16', '18'], ['610468472'], ['54950499']],
            [['29', '28', '26'], ['4749652'], ['345655744']],
            [['39', '40', '41'], ['267784162'], ['763020698']],
            [['64', '63', '31'], ['406004250'], ['864899873']],
            [['85', '86', '84'], ['267120960'], ['536361248']],
            [['114', '115', '116'], ['379441499'], ['447396000']],
            [['1247315', '4649579', '7968301'], ['46227677'], ['933487713']],
            [['1379661', '4479579', '1800186'], ['985085118'], ['339765042']],
            [['24316446', '219651566', '501847856'], ['383709663'], ['90685795']],
            [['225365882', '478693885', '231765083'], ['155415482'], ['769649470']],
            [['86962133', '243793871', '284483399'], [0], [0]],
            [['612527302', '167231135', '560979916', '184523411', '549524850', '784911160'], [0], [0]],
            [['164866290', '696124016', '841591253'], [0], [0]],
            [['344730128', '735302216', '851893423'], [0], [0]],
            [['547099506', '572827174', '653889168'], [0], [0]],
        ];
    }
    else if (window.HH_UNIVERSE == 'gay' || window.HH_UNIVERSE == 'gh_nutaku' || window.HH_UNIVERSE == 'gh_eroges') {
        trolls = ['Dark Lord', 'Ninja Spy', 'Gruntt', 'Edward', 'Donatien', 'Silvanus', 'Bremen', 'Edernas', 'Fredy Sih Roko Senseï', 'Maro', 'Jackson&#8217;s Crew', 'Icarus Warlock', 'Sol'];
        if (lang == 'fr') {
            trolls[1] = 'Espion Ninja';
            trolls[10] = 'Éq. de Jackson';
            trolls[11] = 'Sorcier Icarus';
        }
        if (lang == 'de') {
            trolls[0] = 'Dunkler Lord';
            trolls[1] = 'Ninjaspion';
            trolls[10] ='Jacksons Crew';
        }

        tierGirlsID = [
            [['8', '9', '10'], ['7270263'], ['979916751']],
            [['14', '13', '12'], ['318292466'], ['936580004']],
            [['19', '16', '18'], ['610468472'], ['54950499']],
            [['29', '28', '26'], ['4749652'], ['345655744']],
            [['39', '40', '41'], ['267784162'], ['763020698']],
            [['64', '63', '31'], ['406004250'], ['864899873']],
            [['85', '86', '84'], ['267120960'], ['536361248']],
            [['114', '115', '116'], ['379441499'], ['447396000']],
            [['1247315', '4649579', '7968301'], ['46227677'], ['933487713']],
            [['1379661', '4479579', '1800186'], ['985085118'], ['339765042']],
            [['24316446', '219651566', '501847856'], ['383709663'], ['90685795']],
            [['225365882', '478693885', '231765083'], ['155415482'], ['769649470']],
            [['86962133', '243793871', '284483399'], [0], [0]],
        ];
    }
    else if (window.HH_UNIVERSE == 'comix_c' || window.HH_UNIVERSE == 'nutaku_c') {
        trolls = ['BodyHack', 'Grey Golem', 'The Nymph', 'Athicus Ho\'ole', 'The Mimic', 'Cockatrice', 'Pomelo', 'Alexa Sl’thor', 'D\'Klong'];

        tierGirlsID = [
            [['830009523', '907801218', '943323021'], [0], [0]],
            [['271746999', '303805209', '701946373'], [0], [0]],
            [['743748788', '977228200', '943323021'], [0], [0]],
            [['140401381', '232860230', '514994766'], [0], [0]],
            [['623293037', '764791769', '801271903'], [0], [0]],
            [['921365371', '942523553', '973271744'], [0], [0]],
            [['364639341', '879781833', '895546748'], [0], [0]],
            [['148877065', '218927643', '340369336'], [0], [0]],
            [['258185125', '897951171', '971686222'], [0], [0]],
        ];
    }
    else if (window.HH_UNIVERSE == 'star_t' || window.HH_UNIVERSE == 'nutaku_t') {
        trolls = ['Headmistress Asa Akira', 'Sammy Jayne', 'Ivy Winters', 'Sophia Jade', 'Amia Miley', 'Alyssa Reece', 'Kelly Kline', 'Jamie Brooks', 'Jordan Kingsley', false, 'Sierra Sinn', 'Jasmine Jae', 'Bella Rose'];
        if (lang == 'fr') {
            trolls[0] = 'Directrice Asa Akira';
        }

        tierGirlsID = [
            [['261345306', '795788039', '973280579'], [0], [0]],
            [['482529771', '658322339', '833308213'], [0], [0]],
            [['117837840', '160370794', '306287449', '828011942'], [0], [0]],
            [['564593641', '719705773', '934421949'], [0], [0]],
            [['270611414', '464811282', '781232070'], [0], [0]],
            [['219241809', '380385497', '879198752'], [0], [0]],
            [['165066536', '734325005', '805020628'], [0], [0]],
            [['191661045', '369105612', '665836932'], [0], [0]],
            [['169356639', '383702874', '943667167'], [0], [0]],
            [[0], [0], [0]],
            [['169741198', '459885596', '507702178'], [0], [0]],
            [['258984943', '837109131', '888135956'], [0], [0]],
            [['270920965', '600910475', '799448349'], [0], [0]],
        ];
    }
    else if (window.HH_UNIVERSE == 'dotcom_startrans' || window.HH_UNIVERSE == 'nutaku_startrans') {
        trolls = ['Ariel Demure', 'Emma Rose', 'Natalie Stone', 'Janie Blade'];

        tierGirlsID = [
            [['171883542', '229180984', '771348244'], [0], [0]],
            [['484962893', '879574564', '910924260'], [0], [0]],
            [['334144727', '667194919', '911144911'], [0], [0]],
            [['473470854', '708191289', '945710078'], [0], [0]],
        ];
    }
    else if (window.HH_UNIVERSE == 'dotcom_stargay' || window.HH_UNIVERSE == 'nutaku_stargay') {
        trolls = ['Tristan Hunter', 'Jimmy Durano'];

        tierGirlsID = [
            [['374763633', '485499759', '780402171'], [0], [0]],
            [['290465722', '524315573', '970767946'], [0], [0]],
        ];
    }
}

function transformNutakuURL(url) {
    if (window.location.host.includes('nutaku') && !url.includes("sess=")) {
        return url.includes('?') ? `${url}&sess=${window.PLATFORM_SESS}` : `${url}?sess=${window.PLATFORM_SESS}`
    }
    return url
}


/* =========
	OPTIONS
   ========= */
function loadSetting(e){
    try{var temp = JSON.parse(localStorage.getItem('HHS.'+e))}
    catch(err){}

    if (temp == null) {
        switch (e) {
            case 'villain':
                return true;
            case 'tiers':
                return true;
            case 'xpMoney':
                return true;
            case 'market':
                return true;
            case 'marketRestockButton':
                return false;
            case 'filterArmorItems':
                return true;
            case 'harem':
                return true;
            case 'haremFilter':
                return true;
            case 'girlsItemsFilter':
                return true;
            case 'league':
                return true;
            case 'leagueBoard':
                return true;
            case 'simLeagueBoardFight':
                return true;
            case 'hideLeaguex3Button':
                return false;
            case 'simFight':
                return true;
            case 'teamsFilter':
                return true;
            case 'champions':
                return true;
            case 'links':
                return true;
            case 'seasonStats':
                return true;
            case 'pachinkoNames':
                return true;
            case 'missionsBackground':
                return true;
            case 'collectMoneyAnimation':
                return false;
            case 'activitiesTabChoice':
                return true;
            case 'customizedHomeScreen':
                return true;
            case 'hideClaimedRewards':
                return true;
            case 'desktopDisplay':
                return false;
            case 'hideClaimAllButtons':
                return false;
            case 'hideMultipleLeagueBattlesButton':
                return false;
            case 'removePachinkoPopup':
                return false;
            case 'contestsExpiryTimer':
                return true;
        }
    }
    return temp
}

loadFeatures();

function loadFeatures() {
    fixCSSIssues();

    setTimeout(function() {
        if (window.Hero == undefined) return;

        if (CurrentPage.includes('home')) options();

        editTrollsAndTiers();

        // Show which modules are enabled and if so, run them when appropriate
        if (loadSetting('villain')) {
            if (CurrentPage.includes('edit-team') || CurrentPage.includes('waifu')) getHaremGirlsData();
            if (CurrentPage.includes('harem')) getNonHaremGirlsData();
            moduleVillain();
        }
        if (loadSetting('xpMoney')) {
            moduleXP();
            moduleMoney();
        }
        if (loadSetting('market')) {
            if (CurrentPage.includes('shop')) moduleMarket();
        }
        if (loadSetting('marketRestockButton')) {
            if (CurrentPage.includes('shop')) moduleMarketRestockButton();
        }
        if (loadSetting('filterArmorItems')) {
            if (CurrentPage.includes('shop')) moduleFilterArmorItems();
            if (CurrentPage.includes('mythic-equipment-upgrade')) moduleMythicEquipmentUpgrade();
        }
        if (loadSetting('harem')) {
            if ((CurrentPage.includes('edit-team') || CurrentPage.includes('waifu')) && !loadSetting('villain')) getHaremGirlsData();
            if (CurrentPage.includes('harem')) {
                moduleHarem();
                haremGetFilteredGirls();
                if (!loadSetting('villain')) getNonHaremGirlsData();
            }
            if (CurrentPage.includes('/girl/')) haremGirlsShortcut();
        }
        if (loadSetting('haremFilter')) {
            if (CurrentPage.includes('harem')) {
                moduleHaremFilter();
                if (!loadSetting('harem')) haremGetFilteredGirls();
            }
            if (CurrentPage.includes('teams')) moduleTeamsCollector();
            if (CurrentPage.includes('/girl/') && !loadSetting('harem')) haremGirlsShortcut();
        }
        if (loadSetting('girlsItemsFilter')) {
            if (CurrentPage.includes('/girl/')) moduleFilterGirlsItems();
        }
        if (loadSetting('league')) {
            moduleLeague();
            if (CurrentPage.includes('leagues-pre-battle')) moduleLeagueOpponentsShortcut();
            if (CurrentPage.includes('teams') && !loadSetting('haremFilter')) moduleTeamsCollector();
        }
        if (loadSetting('hideLeaguex3Button')) {
            if (CurrentPage.includes('leagues-pre-battle')) moduleHideLeaguex3Button();
        }
        if (loadSetting('simFight')) {
            if (CurrentPage.includes('leagues-pre-battle')) moduleLeagueSim();
            if (CurrentPage.includes('season-arena')) moduleSeasonSim();
            if (CurrentPage.includes('troll-pre-battle') || CurrentPage.includes('pantheon-pre-battle')) moduleBattleSim();
        }
        if (loadSetting('teamsFilter')) {
            moduleTeamsFilter();
            if (CurrentPage.indexOf('labyrinth-pool-select') != -1) moduleLabyrinthFilter();
            if (CurrentPage.indexOf('edit-labyrinth-team') != -1) moduleLabyrinthTeamFilter()
        }
        if (loadSetting('champions')) {
            moduleChampions();
            if (CurrentPage.includes('clubs')) moduleClubChampionFeatures();
        }
        if (loadSetting('links')) {
            moduleLinks();
        }
        if (loadSetting('seasonStats')) {
            if (CurrentPage.includes('season-battle') || CurrentPage.includes('season.html') || CurrentPage.includes('season-arena')) moduleSeasonStats();
        }
        if (loadSetting('pachinkoNames')) {
            if ((CurrentPage.includes('edit-team') || CurrentPage.includes('waifu')) && !loadSetting('villain') && !loadSetting('harem')) getHaremGirlsData();
            if (CurrentPage.includes('harem') && !loadSetting('villain') && !loadSetting('harem')) getNonHaremGirlsData();
            modulePachinkoNames();
        }
        if (loadSetting('missionsBackground')) {
            moduleMissionsBackground();
        }
        if (loadSetting('collectMoneyAnimation')) {
            moduleCollectMoneyAnimation();
        }
        if (loadSetting('activitiesTabChoice') && CurrentPage == '/home.html') {
            moduleActivitiesTabChoice();
        }
        if (loadSetting('customizedHomeScreen') && CurrentPage == '/home.html') {
            moduleCustomizedHomeScreen();
        }
        if (loadSetting('hideClaimedRewards')) {
            moduleHideClaimedRewards();
        }
        if (loadSetting('desktopDisplay')) {
            moduleDesktopDisplay();
        }
        if (loadSetting('hideClaimAllButtons')) {
            moduleHideClaimAllButtons();
        }
        if (loadSetting('hideMultipleLeagueBattlesButton') && CurrentPage.includes('leagues')) {
            moduleHideMultipleLeagueBattlesButton();
        }
        if (loadSetting('removePachinkoPopup') && CurrentPage.includes('pachinko')) {
            moduleRemovePachinkoPopup();
        }
        if (loadSetting('contestsExpiryTimer') && CurrentPage.includes('activities')) {
            moduleContestsExpiryTimer();
        }

        //Features without options
        if (CurrentPage.includes('home')) moduleEventEndIndicator();
        stopOrgyBackgroundSwithcing();
        displayGirlsShards();
        if(CurrentPage.includes('battle')) skipBattleValues();
        if (CurrentPage.includes('activities')) {
            fixDailyGoalsBug();
            sortDailyMissions();
        }
        notifySultryMysteriesShopRefresh();
        fixGirlStatsTooltipPosition();
        if (CurrentPage == '/season.html') fixSeasonDisplay();
        fixProfilePopup();

    }, timeout);
}

function options() {
    // Options menu
    $('div#contains_all').append('<a href="#"><img src="https://i.postimg.cc/c1F37PYz/icon-options.png" id="hhsButton"></a>');
    $('div#contains_all').append('<div id="hhsOptions" class="hhsTooltip" style="display: none;">'
                                 + '<span class="close-settings-panel"></span>'
                                 + '<div class="script_setting" style="grid-row-end: span 2;">'
                                 + '<label class="switch"><input type="checkbox" hhs="villain"><span class="slider"></span></label>' + labels.optionsVillain + '<br />'
                                 + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label class="switch"><input type="checkbox" hhs="tiers"><span class="slider"></span></label>' + labels.optionsTiers + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="xpMoney"><span class="slider"></span></label>' + labels.optionsXPMoney + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="market"><span class="slider"></span></label>' + labels.optionsMarket + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="marketRestockButton"><span class="slider"></span></label>' + labels.optionsMarketRestockButton + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="filterArmorItems"><span class="slider"></span></label>' + labels.optionsFilterArmorItems + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="harem"><span class="slider"></span></label>' + labels.optionsHarem + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="haremFilter"><span class="slider"></span></label>' + labels.optionsHaremFilters + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="girlsItemsFilter"><span class="slider"></span></label>' + labels.optionsGirlsItemsFilter + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting" style="grid-row-end: span 3;">'
                                 + '<label class="switch"><input type="checkbox" hhs="league"><span class="slider"></span></label>' + labels.optionsLeague + '<br />'
                                 + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label class="switch"><input type="checkbox" hhs="leagueBoard"><span class="slider"></span></label>' + labels.optionsLeagueBoard + '<br />'
                                 + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label class="switch"><input type="checkbox" hhs="simLeagueBoardFight"><span class="slider"></span></label>' + labels.optionsSimLeagueBoardFight + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="hideMultipleLeagueBattlesButton"><span class="slider"></span></label>' + labels.optionsHideMultipleLeagueBattlesButton + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="hideLeaguex3Button"><span class="slider"></span></label>' + labels.optionsHideLeaguex3Button + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="simFight"><span class="slider"></span></label>' + labels.optionsSimFight + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="teamsFilter"><span class="slider"></span></label>' + labels.optionsTeamsFilter + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="champions"><span class="slider"></span></label>' + labels.optionsChampions + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="links"><span class="slider"></span></label>' + labels.optionsLinks + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="seasonStats"><span class="slider"></span></label>' + labels.optionsSeasonStats + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="pachinkoNames"><span class="slider"></span></label>' + labels.optionsPachinkoNames + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="missionsBackground"><span class="slider"></span></label>' + labels.optionsMissionsBackground + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="collectMoneyAnimation"><span class="slider"></span></label>' + labels.optionsCollectMoneyAnimation + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="activitiesTabChoice"><span class="slider"></span></label>' + labels.optionsActivitiesTabChoice + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="customizedHomeScreen"><span class="slider"></span></label>' + labels.optionsCustomizedHomeScreen + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="hideClaimedRewards"><span class="slider"></span></label>' + labels.optionsHideClaimedRewards + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="desktopDisplay"><span class="slider"></span></label>' + labels.optionsDesktopDisplay + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="hideClaimAllButtons"><span class="slider"></span></label>' + labels.optionsHideClaimAllButtons + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="removePachinkoPopup"><span class="slider"></span></label>' + labels.optionsRemovePachinkoPopup + '<br />'
                                 + '</div>'
                                 + '<div class="script_setting">'
                                 + '<label class="switch"><input type="checkbox" hhs="contestsExpiryTimer"><span class="slider"></span></label>' + labels.optionsContestsExpiryTimer
                                 + '</div>'
                                 + '</div>');

    // Show and hide options menu
    $('#hhsButton').click(function() {
        let x = document.getElementById('hhsOptions');
        if (x.style.display == 'none') x.style.display = 'grid';
        else x.style.display = 'none';
    });
    $('[hhs]').each(function(){
        $(this).attr('checked', loadSetting($(this).attr('hhs')))
    })
    $('[hhs]').click(function() {
        localStorage.setItem('HHS.'+$(this).attr('hhs'), $(this).prop('checked'))
    })
    $('#hhsOptions .close-settings-panel').click(() => {
        let x = document.getElementById('hhsOptions');
        x.style.display = 'none';
    });

    // Dependency of villain menu options
    $('[hhs=villain]').click(function() {
        if (!$(this).is(':checked')) {
            $('[hhs=tiers]').prop('checked', false);
            localStorage.setItem('HHS.tiers', false)
        }
    });
    $('[hhs=tiers]').click(function() {
        if ($(this).is(':checked')) {
            $('[hhs=villain]').prop('checked', true);
            localStorage.setItem('HHS.villain', true)
        }
    });

    // Dependency of league info options
    $('[hhs=league]').click(function() {
        if (!$(this).is(':checked')) {
            $('[hhs=leagueBoard]').prop('checked', false);
            localStorage.setItem('HHS.leagueBoard', false);

            $('[hhs=simLeagueBoardFight]').prop('checked', false);
            localStorage.setItem('HHS.simLeagueBoardFight', false);
        }
        else if ($(this).is(':checked')) {
            $('[hhs=leagueBoard]').prop('checked', true);
            localStorage.setItem('HHS.leagueBoard', true);

            $('[hhs=simLeagueBoardFight]').prop('checked', true);
            localStorage.setItem('HHS.simLeagueBoardFight', true);
        }
    });
    $('[hhs=leagueBoard]').click(function() {
        if ($(this).is(':checked')) {
            $('[hhs=league]').prop('checked', true);
            localStorage.setItem('HHS.league', true);
        }
    });
    $('[hhs=simLeagueBoardFight]').click(function() {
        if ($(this).is(':checked')) {
            $('[hhs=league]').prop('checked', true);
            localStorage.setItem('HHS.league', true);
        }
    });

    //CSS
    sheet.insertRule('#hhsButton {'
                     + 'height: 35px;'
                     + 'position: absolute;'
                     + 'z-index: 10;'
                     + 'filter: drop-shadow(0px 0px 5px white);}'
                    );

    if ($('.hh-plus-plus-config-button').length > 0) {
        sheet.insertRule(`${mediaDesktop} {`
                         + '#hhsButton {'
                         + 'right: 65px;'
                         + 'top: 70px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#hhsButton {'
                         + 'right: 250px;'
                         + 'top: 100px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                        + '.hh-plus-plus-config-button {'
                        + 'margin-top: -33px;}}'
                       );
    }
    else {
        sheet.insertRule(`${mediaDesktop} {`
                         + '#hhsButton {'
                         + 'right: 15px;'
                         + 'top: 55px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#hhsButton {'
                         + 'right: 15px;'
                         + 'top: 65px;}}'
                        );
    }

    sheet.insertRule(`${mediaMobile} {`
                     + '.hh-plus-plus-config-button {'
                     + 'transform: scale(0.7);'
                     + 'right: 4px;}}'
                    );

    sheet.insertRule('.hhsTooltip {'
                     + 'grid-template-columns: 1fr 1fr;'
                     + 'overflow: auto;'
                     + 'text-align: left; '
                     + 'z-index: 99; '
                     + 'padding: 3px 5px 3px 5px; '
                     + 'border: 2px solid #905312; '
                     + 'border-radius: 6px; '
                     + 'background-color: rgba(32,3,7,.9); '
                     + 'position: absolute;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.hhsTooltip {'
                     + 'width: 99%;'
                     + 'left: 10px;'
                     + 'top: 5px;'
                     + 'max-height: 99%;'
                     + 'font-size: 18px;'
                     + 'line-height: 36px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.hhsTooltip {'
                     + 'width: 98%;'
                     + 'left: 10px;'
                     + 'top: 68px;'
                     + 'max-height: 99%;'
                     + 'font-size: 14px;'
                     + 'line-height: 28px;}}'
                    );

    sheet.insertRule('.close-settings-panel {'
                     + 'position: absolute;'
                     + 'display: block;'
                     + 'background-size: cover;'
                     + 'background-image: url(https://hh2.hh-content.com/clubs/ic_xCross.png);'
                     + 'height: 37px;'
                     + 'width: 41px;'
                     + 'top: 6px;'
                     + 'right: 6px;'
                     + 'cursor: pointer;}'
                    );

    sheet.insertRule('.hhsTooltip .script_setting label input {'
                     + 'display: none;}'
                    );

    sheet.insertRule('.switch {'
                     + 'position: relative; '
                     + 'display: inline-block; '
                     + 'width: 34px; '
                     + 'height: 17px;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.switch {'
                     + 'top: -13px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.switch {'
                     + 'top: -6px;}}'
                    );

    sheet.insertRule('.slider {'
                     + 'position: absolute; '
                     + 'cursor: pointer; '
                     + 'top: 0; '
                     + 'left: 0; '
                     + 'right: 0; '
                     + 'bottom: 0; '
                     + 'background-color: #CCCCCC; '
                     + '-webkit-transition: .4s; '
                     + 'transition: .4s; '
                     + 'border-radius: 17px; '
                     + 'margin-right: 4px;}'
                    );

    sheet.insertRule('.slider:before {'
                     + 'position: absolute; '
                     + 'content: \'\'; '
                     + 'height: 13px; '
                     + 'width: 13px; '
                     + 'left: 2px; '
                     + 'bottom: 2px; '
                     + 'background-color: white; '
                     + '-webkit-transition: .4s; '
                     + 'transition: .4s; '
                     + 'border-radius: 50%;}'
                    );

    sheet.insertRule('input:checked + .slider {'
                     + 'background-color: #F11F64;}'
                    );

    sheet.insertRule('input:checked + .slider:before {'
                     + '-webkit-transform: translateX(13px); '
                     + '-ms-transform: translateX(13px); '
                     + 'transform: translateX(13px);}'
                    );

    sheet.insertRule('.script_setting {'
                     + 'padding-right: 5px;}'
                    );
}

/* ======================
	FIGHT A VILLAIN MENU
   ====================== */

function moduleVillain() {
    //Create localStorage if it doesn't exist yet
    if (!localStorage.getItem('HHS.eventTrolls')) {
        localStorage.setItem('HHS.eventTrolls', '[]');
    }
    if (!localStorage.getItem('HHS.mythicEventTrolls')) {
        localStorage.setItem('HHS.mythicEventTrolls', '[]');
    }
    if (!localStorage.getItem('HHS.tierGirlsOwned')) {
        localStorage.setItem('HHS.tierGirlsOwned', '[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]');
    }

    let eventTrolls = JSON.parse(localStorage.getItem('HHS.eventTrolls'));
    let mythicEventTrolls = JSON.parse(localStorage.getItem('HHS.mythicEventTrolls'));
    let tierGirlsOwned = JSON.parse(localStorage.getItem('HHS.tierGirlsOwned'));
    const girlDictionary = (!localStorage.getItem('HHS.HHPNMap')) ? new Map(): new Map(JSON.parse(localStorage.getItem('HHS.HHPNMap')));
    const girlShardsDictionary = (!localStorage.getItem('HHS.HHPNShardsMap')) ? new Map(): new Map(JSON.parse(localStorage.getItem('HHS.HHPNShardsMap')));
    let	includeTiers = false;
    let eventEndTime = localStorage.getItem('HHS.eventTime') || 0;
    let mythicEventEndTime = localStorage.getItem('HHS.mythicEventTime') || 0;

    if (loadSetting('tiers')) includeTiers = true;

    if (Math.floor(new Date().getTime()/1000) > eventEndTime) localStorage.removeItem('HHS.eventTrolls');

    if (Math.floor(new Date().getTime()/1000) > mythicEventEndTime) localStorage.removeItem('HHS.mythicEventTrolls');

    if (window.location.search.includes("tab=event")) {
        let eventRemainingTime = parseInt(window.event_data.seconds_until_event_end, 10);
        eventEndTime = Math.floor(new Date().getTime()/1000) + eventRemainingTime;
        localStorage.setItem('HHS.eventTime', eventEndTime);

        eventTrolls = [];

        let totalGirls = window.event_girls.length;
        for (let i=0; i<totalGirls; i++) {
            let girlId = window.event_girls[i].id_girl;
            let girlLocation = window.event_girls[i].source.anchor_source.url;
            let girlRarity = window.event_girls[i].rarity;
            let girlName = window.event_girls[i].name;
            let girlShards = window.event_girls[i].shards;

            if (girlLocation.includes('troll-pre-battle')) eventTrolls.push({id: girlId, troll: girlLocation.substring(35), rarity: girlRarity});

            if (girlShards < 100) {
                let girlData = {id_girl: girlId,
                                name: girlName,
                                shards: girlShards}
                girlShardsDictionary.set(girlId, girlData);
            }
            else girlShardsDictionary.delete(girlId);
        }
        localStorage.setItem('HHS.eventTrolls', JSON.stringify(eventTrolls));
        localStorage.setItem('HHS.HHPNShardsMap', JSON.stringify(Array.from(girlShardsDictionary.entries())));
    }

    if (window.location.search.includes("tab=mythic_event")) {
        let eventRemainingTime = parseInt(window.event_data.seconds_until_event_end, 10);
        mythicEventEndTime = Math.floor(new Date().getTime()/1000) + eventRemainingTime;
        localStorage.setItem('HHS.mythicEventTime', mythicEventEndTime);

        mythicEventTrolls = [];

        let totalGirls = window.event_girls.length;
        for (let i=0; i<totalGirls; i++) {
            let girlId = window.event_girls[i].id_girl;
            let girlLocation = window.event_girls[i].source.anchor_source.url;
            let girlRarity = window.event_girls[i].rarity;
            let girlName = window.event_girls[i].name;
            let girlShards = window.event_girls[i].shards;

            if (girlLocation.includes('troll-pre-battle')) mythicEventTrolls.push({id: girlId, troll: girlLocation.substring(35), rarity: girlRarity});

            if (girlShards < 100) {
                let girlData = {id_girl: girlId,
                                name: girlName,
                                shards: girlShards}
                girlShardsDictionary.set(girlId, girlData);
            }
            else girlShardsDictionary.delete(girlId);
        }
        localStorage.setItem('HHS.mythicEventTrolls', JSON.stringify(mythicEventTrolls));
        localStorage.setItem('HHS.HHPNShardsMap', JSON.stringify(Array.from(girlShardsDictionary.entries())));
    }

    if (includeTiers) {
        //Check if villain tier girls have been collected (to update when new villain is added)
        tierGirlsOwned = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []];

        for (let tIdx = 0; tIdx < tierGirlsID.length; tIdx++) {
            for (let pIdx = 0; pIdx < tierGirlsID[tIdx].length; pIdx++) {
                tierGirlsOwned[tIdx][pIdx] = true;
                for (let gIdx = 0; gIdx < tierGirlsID[tIdx][pIdx].length; gIdx++) {
                    let idGirl = parseInt(tierGirlsID[tIdx][pIdx][gIdx], 10);
                    if (idGirl == 0) tierGirlsOwned[tIdx][pIdx] = true;
                    else if (!girlDictionary.get(idGirl)) tierGirlsOwned[tIdx][pIdx] = false;
                }

            }
        }
        localStorage.setItem('HHS.tierGirlsOwned', JSON.stringify(tierGirlsOwned));
    }

    //Add the actual menu
    let trollGems;
    let trollRewards;

    //To update when new villain is added.
    trollGems = ['&nbsp;&nbsp;<span class="fire_gem"></span>&nbsp;<span class="sun_gem"></span>',
                 '&nbsp;&nbsp;<span class="darkness_gem"></span>&nbsp;<span class="light_gem"></span>',
                 '&nbsp;&nbsp;<span class="psychic_gem"></span>&nbsp;<span class="water_gem"></span>',
                 '&nbsp;&nbsp;<span class="nature_gem"></span>&nbsp;<span class="stone_gem"></span>',
                 '&nbsp;&nbsp;<span class="darkness_gem"></span>',
                 '&nbsp;&nbsp;<span class="light_gem"></span>',
                 '&nbsp;&nbsp;<span class="psychic_gem"></span>',
                 '&nbsp;&nbsp;<span class="water_gem"></span>',
                 '&nbsp;&nbsp;<span class="fire_gem"></span>',
                 '&nbsp;&nbsp;<span class="nature_gem"></span>',
                 '&nbsp;&nbsp;<span class="stone_gem"></span>',
                 '&nbsp;&nbsp;<span class="sun_gem"></span>',
                 '&nbsp;&nbsp;<span class="darkness_gem"></span>',
                 '&nbsp;&nbsp;<span class="light_gem"></span>',
                 '&nbsp;&nbsp;<span class="psychic_gem"></span>',
                 '&nbsp;&nbsp;<span class="water_gem"></span>',
                 '&nbsp;&nbsp;<span class="fire_gem"></span>',
                ];

    //To update when new villain is added.
    trollRewards = ['',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '&nbsp;&nbsp;<span class="gift_reward"></span>',
                    '&nbsp;&nbsp;<span class="book_reward"></span>',
                    '&nbsp;&nbsp;<span class="gift_reward"></span>',
                    '',
                    '',
                    '',
                    '',
                    '',
                   ]

    let currentWorld = window.Hero.infos.questing.id_world,
        trollName = '',
        trollNameTiers = '',
        trollGemRewards = '',
        trollOtherRewards = '',
        trollsMenu = '',
        //Associate  the world ID (first number) to its villain ID (second number): troll_ID: villain_ID
        trollsId = {2: 1, 3: 2, 4: 3, 5: 4, 6: 5, 7: 6, 8: 7, 9: 8, 10: 9, 11: 10, 12: 11, 13: 12, 14: 13, 15: 14, 16: 15, 17: 16, 18: 17}

    if (window.HH_UNIVERSE == 'star_t' || window.HH_UNIVERSE == 'nutaku_t') {
        trollsId = {2: 1, 3: 2, 4: 3, 5: 4, 6: 5, 7: 6, 8: 7, 9: 8, 10: 9, 14: 11, 16: 12, 18: 13}
    }

    if (window.HH_UNIVERSE == 'dotcom_startrans' || window.HH_UNIVERSE == 'nutaku_startrans') {
        trollsId = {2: 1, 3: 2, 5: 3, 6: 4}
    }

    if (window.HH_UNIVERSE == 'dotcom_stargay' || window.HH_UNIVERSE == 'nutaku_stargay') {
        trollsId = {2: 1, 6: 2}
    }

    for (let i = 0; i < trollsId[currentWorld]; i++) {
        if (!(i == 9 && (window.HH_UNIVERSE == 'star_t' || window.HH_UNIVERSE == 'nutaku_t'))) {
            if (typeof trolls[i] !== typeof undefined && trolls[i] !== false) {
                trollName = trolls[i];
                trollGemRewards = trollGems[i];
                trollOtherRewards = trollRewards[i];
                if (includeTiers) {
                    trollNameTiers = ' ';
                    if (!(tierGirlsOwned[i][0])) {
                        trollNameTiers = trollNameTiers + '&#185;';
                    }
                    if (!(tierGirlsOwned[i][1])) {
                        trollNameTiers = trollNameTiers + '&#178;';
                    }
                    if (!(tierGirlsOwned[i][2])) {
                        trollNameTiers = trollNameTiers + '&#179;';
                    }
                }
            }
            else trollName = labels.world + ' ' + (i + 2) + ' ' + labels.villain;
            let type = 'regular';
            for (let j = 0, len = eventTrolls.length; j < len; j++) {
                let shards = girlShardsDictionary.get(parseInt(eventTrolls[j].id, 10)) ? girlShardsDictionary.get(parseInt(eventTrolls[j].id, 10)).shards : 0;
                if (eventTrolls[j].troll == (i + 1) && shards != 100) {
                    type = 'eventTroll ' + eventTrolls[j].rarity;
                }
            }
            for (let j = 0; j < mythicEventTrolls.length; j++) {
                let shards = girlShardsDictionary.get(parseInt(mythicEventTrolls[j].id, 10)) ? girlShardsDictionary.get(parseInt(mythicEventTrolls[j].id, 10)).shards : 0;
                if (mythicEventTrolls[j].troll == (i + 1) && shards != 100) {
                    type = 'mythicEventTroll';
                }
            }
            trollsMenu += `<a class=${type} href="${transformNutakuURL('/troll-pre-battle.html?id_opponent=' + (i + 1))}"> ${trollName} ${trollNameTiers} </a> ${trollGemRewards} ${trollOtherRewards} &nbsp;&nbsp;&nbsp; <a class="troll_world_script" href="${transformNutakuURL('/world/' + (i + 2))}"></a>&nbsp;&nbsp;<br />`;
        }
    }

    this.$overlay = $('<div class="script-fight-a-villain-menu-overlay"></div>');
    $('body').append(this.$overlay);

    this.$overlay.click(() => {
        this.$container.removeClass('shown');
        this.$overlay.removeClass('shown');
    });

    $('#fight_energy_bar .bar-wrapper').click(() => {
        if (!this.$container) {
            this.$container = $('<div class="script-fight-a-villain-menu-container fixed_scaled"></div>');
            this.$container.append('<div class="TrollsMenu" id="TrollsID">' + trollsMenu + '</div>');
            $('body').append(this.$container);
        }
        this.$container.addClass('shown');
        this.$overlay.addClass('shown');
    });

    //CSS
    sheet.insertRule('#fight_energy_bar .bar-wrapper {'
                     + 'cursor: pointer;}'
                    );

    sheet.insertRule('.script-fight-a-villain-menu-overlay {'
                     + 'display: none;'
                     + 'background-color: #0808087a;'
                     + 'position: absolute;'
                     + 'top: 0;'
                     + 'left: 0;'
                     + 'width: 100%;'
                     + 'height: 100%;'
                     + 'z-index: 9;}'
                    );

    sheet.insertRule('.script-fight-a-villain-menu-overlay.shown {'
                     + 'display: block;}'
                    );

    sheet.insertRule('.script-fight-a-villain-menu-container {'
                     + 'display: none;'
                     + 'align-items: center;'
                     + 'justify-content: center;'
                     + 'color: #fff;'
                     + 'width: 1040px;'
                     + 'height: 585px;'
                     + 'z-index: 10;'
                     + 'font-size: 16px;'
                     + 'pointer-events: none;}'
                    );

    sheet.insertRule('.script-fight-a-villain-menu-container.shown {'
                     + 'display: flex;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.TrollsMenu {'
                     + 'position: absolute; '
                     + 'column-count: 2;'
                     + 'column-width: auto;'
                     + 'width: max-content;'
                     + 'top: 66px;'
                     + 'left: 440px;'
                     + 'border-radius: 8px 8px 8px 8px;'
                     + 'background-color: rgba(0,0,0,.8);'
                     + 'line-height: 28px;'
                     + 'box-shadow: 0 0 0 1px rgba(255,255,255,0.73);'
                     + 'font-size: 14px;'
                     + 'font-weight: 400;'
                     + 'letter-spacing: .22px;'
                     + 'color: #fff;'
                     + 'text-align: center;'
                     + 'pointer-events: all;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.TrollsMenu {'
                     + 'position: absolute;'
                     + 'column-count: 2;'
                     + 'column-width: auto;'
                     + 'width: max-content;'
                     + 'top: 102px;'
                     + 'left: 303px;'
                     + 'border-radius: 8px 8px 8px 8px;'
                     + 'background-color: rgba(0,0,0,.8);'
                     + 'line-height: 48px;'
                     + 'box-shadow: 0 0 0 1px rgba(255,255,255,0.73);'
                     + 'font-size: 18px !important;'
                     + 'font-weight: 400;'
                     + 'letter-spacing: .22px;'
                     + 'color: #fff; '
                     + 'text-align: center;'
                     + 'pointer-events: all;}}'
                    );

    sheet.insertRule('.TrollsMenu a {'
                     + 'font-family: \'Carter One\', \'Alegreya Sans\', cursive !important;'
                     + 'color: rgb(255, 255, 255); '
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('.eventTroll {'
                     + 'color: #f70 !important;}'
                    );

    sheet.insertRule('.eventTroll:hover {'
                     + 'color: #fa0 !important;}'
                    );

    sheet.insertRule('.eventTroll.common {'
                     + 'color: #8d8e9f !important;}'
                    );

    sheet.insertRule('.eventTroll.common:hover {'
                     + 'color: #b4b5c9 !important;}'
                    );

    sheet.insertRule('.eventTroll.rare {'
                     + 'color: #23b56b !important;}'
                    );

    sheet.insertRule('.eventTroll.rare:hover {'
                     + 'color: #2bdf84 !important;}'
                    );

    sheet.insertRule('.eventTroll.epic {'
                     + 'color: #ffb244 !important;}'
                    );

    sheet.insertRule('.eventTroll.epic:hover {'
                     + 'color: #ffc97b !important;}'
                    );

    sheet.insertRule('.eventTroll.legendary {'
                     + 'color: #9370db !important;}'
                    );

    sheet.insertRule('.eventTroll.legendary:hover {'
                     + 'color: #b19cd9 !important;}'
                    );

    sheet.insertRule('.mythicEventTroll {'
                     + 'color: #ec0039 !important;}'
                    );

    sheet.insertRule('.mythicEventTroll:hover {'
                     + 'color: #ff003e !important;}'
                    );

    sheet.insertRule('#TrollsID a {'
                     + 'color: rgb(255, 255, 255);'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('#TrollsID a:hover {'
                     + 'color: rgb(255, 247, 204);'
                     + 'text-decoration: underline;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#TrollsID .darkness_gem, #TrollsID .light_gem, #TrollsID .psychic_gem, #TrollsID .fire_gem, #TrollsID .nature_gem, #TrollsID .stone_gem, #TrollsID .sun_gem, #TrollsID .water_gem {'
                     + 'position: relative;'
                     + 'top: -8px;'
                     + 'height: 14px;'
                     + 'width: 14px;'
                     + 'display: inline-block;'
                     + 'background-size: 14px;'
                     + 'background-repeat: no-repeat;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#TrollsID .darkness_gem, #TrollsID .light_gem, #TrollsID .psychic_gem, #TrollsID .fire_gem, #TrollsID .nature_gem, #TrollsID .stone_gem, #TrollsID .sun_gem, #TrollsID .water_gem {'
                     + 'position: relative;'
                     + 'top: -15px;'
                     + 'height: 20px;'
                     + 'width: 20px;'
                     + 'display: inline-block;'
                     + 'background-size: 20px;'
                     + 'background-repeat: no-repeat;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.gift_reward, .book_reward {'
                     + 'position: relative;'
                     + 'top: -7px;'
                     + 'width: 16px;'
                     + 'height: 16px;'
                     + 'background-size: 16px;'
                     + 'background-repeat: no-repeat;'
                     + 'display: inline-block;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.gift_reward, .book_reward {'
                     + 'position: relative;'
                     + 'top: -15px;'
                     + 'width: 22px;'
                     + 'height: 22px;'
                     + 'background-size: 22px;'
                     + 'background-repeat: no-repeat;'
                     + 'display: inline-block;}}'
                    );

    sheet.insertRule('#TrollsID .darkness_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/darkness.png");}'
                    );

    sheet.insertRule('#TrollsID .light_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/light.png");}'
                    );

    sheet.insertRule('#TrollsID .psychic_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/psychic.png");}'
                    );

    sheet.insertRule('#TrollsID .fire_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/fire.png");}'
                    );

    sheet.insertRule('#TrollsID .nature_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/nature.png");}'
                    );

    sheet.insertRule('#TrollsID .stone_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/stone.png");}'
                    );

    sheet.insertRule('#TrollsID .sun_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/sun.png");}'
                    );

    sheet.insertRule('#TrollsID .water_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/water.png");}'
                    );

    sheet.insertRule('#TrollsID .gift_reward {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/items/K2.png");}'
                    );

    sheet.insertRule('#TrollsID .book_reward {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/items/XP3.png");}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#TrollsID .troll_world_script {'
                     + 'position: relative;'
                     + 'top: -6px;'
                     + 'height: 18px;'
                     + 'width: 18px;'
                     + 'display: inline-block;'
                     + 'background-size: 18px;'
                     + 'background-repeat: no-repeat;'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/quest/ico-quest.png");}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#TrollsID .troll_world_script {'
                     + 'position: relative;'
                     + 'top: -13px;'
                     + 'height: 28px;'
                     + 'width: 28px;'
                     + 'display: inline-block;'
                     + 'background-size: 28px;'
                     + 'background-repeat: no-repeat;'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/quest/ico-quest.png");}}'
                    );
}

/* ===========
	BETTER XP
   =========== */

function moduleXP() {
    function betterXP() {
        if (window.Hero.infos.level < lvl_max_player) {
            $('span[hero="xp"]').empty().append(labels.next + ': ');
            $('span[hero="xp_sep"]').empty().append(nThousand(window.Hero.infos.Xp.left));
            $('span[hero="xp_max"]').empty().append(' XP');
        }
        else {
            $('span[hero="xp"]').empty();
            $('span[hero="xp_sep"]').empty().append(nThousand(window.Hero.infos.Xp.cur));
            $('span[hero="xp_max"]').empty().append(' XP');
        }
    };

    betterXP();

    $('.button_glow').click(function() {
        setInterval(function() {
            betterXP();
        }, 3000)
    });
}

/* ==============
	BETTER MONEY
   ============== */

function moduleMoney() {
    function betterMoney() {
        if (window.Hero.currencies.soft_currency >= 1E6) {
            $('div[hero="soft_currency"]').empty().append(nRounding(window.Hero.currencies.soft_currency, 3, -1));
        }
    };

    betterMoney();

    $('.button_glow').click(function() {
        setInterval(function() {
            betterMoney();
        }, 3000)
    });

    $('#collect_all').click(function() {
        setInterval(function() {
            betterMoney();
        }, 3000)
    });

    $('.collect_money').click(function() {
        setInterval(function() {
            betterMoney();
        }, 3000)
    });
}

/* ====================
	MARKET INFORMATION
   ==================== */

function moduleMarket() {
    let loc2 = $('#my-hero-stats-upgrade-tab-container .upgrade-stats-container').children();
    loc2.each(function() {
        let stat = $(this).attr('class');
        if (stat == 'caracs-1-container' || stat == 'caracs-2-container' || stat == 'caracs-3-container') {
            stat = 'carac' + localeStringToNumber(stat);
            $(this).append('<span class="CustomStats"></span><div id="CustomStats' + stat + '" class="StatsTooltip"></div>');
        }
    });

    updateStats();

    function updateStats() {
        let loc2 = $('#my-hero-stats-upgrade-tab-container .upgrade-stats-container').children();
        let levelMoney = 0,
            levelPoints = window.Hero.infos.level * 30;
        levelMoney = calculateTotalPrice(levelPoints);
        loc2.each(function() {
            let stat = $(this).attr('class');
            $('.CustomStats').html('');
            if (stat == 'caracs-1-container' || stat == 'caracs-2-container' || stat == 'caracs-3-container') {
                stat = 'carac' + localeStringToNumber(stat);
                let boughtPoints = window.Hero.infos[stat],
                    remainingPoints = levelPoints - boughtPoints,
                    spentMoney = calculateTotalPrice(boughtPoints),
                    remainingMoney = levelMoney - spentMoney;

                let totalPoints = window.Hero.infos.caracs[stat];
                let iClass = window.Hero.infos.class - 1;
                let iStat = parseInt(stat.substr(5)) - 1;
                let matMul = [[9, 5, 7], [7, 9, 5], [5, 7, 9]];
                let skillPoints = matMul[iClass][iStat] * window.Hero.infos.level;

                let equipmentsData = $('#equiped.armor-container .armor .slot-container .slot-container').children(),
                    itemPoints = 0;
                equipmentsData.each(function() {
                    if ($(this).attr('class').indexOf('slot empty') == -1) {
                        let equipmentsStats = $(this).attr('data-d'),
                            statPosStart = equipmentsStats.indexOf(stat + '_equip') + 15,
                            statPosEnd = equipmentsStats.substr(statPosStart).indexOf(',');
                        itemPoints = itemPoints + parseInt(equipmentsStats.substr(statPosStart, statPosEnd - 1), 10);
                    }});

                let boostersData = $('#equiped.booster-container .booster .slot-container').children(),
                    ginsengPoints = 0,
                    ginsengLegendary = 0;
                boostersData.each(function() {
                    if ($(this).attr('class') != 'slot empty') {
                        if ($(this).attr('id_item') == '7') {
                            ginsengPoints = ginsengPoints + 100;
                        }
                        else if ($(this).attr('id_item') == '8') {
                            ginsengPoints = ginsengPoints + 350;
                        }
                        else if ($(this).attr('id_item') == '9') {
                            ginsengPoints = ginsengPoints + 1225;
                        }
                        else if ($(this).attr('id_item') == '316') {
                            ginsengLegendary = ginsengLegendary + 1;
                        }
                    }
                });
                ginsengPoints = ginsengPoints + Math.ceil((skillPoints + boughtPoints + itemPoints + ginsengPoints) * 0.06 * ginsengLegendary);

                let clubPoints = totalPoints - skillPoints - boughtPoints - itemPoints - ginsengPoints;

                $('#CustomStats' + stat).html(
                    '<b>' + labels.stat_points_need + ':</b> ' + nThousand(remainingPoints) + '<br />' +
                    '<b>' + labels.money_need + ':</b> ' + nThousand(remainingMoney) + '<br />' +
                    '<b>' + labels.money_spent + ':</b> ' + nThousand(spentMoney) + '<br /><br />' +
                    '<b>' + labels.points_from_level + ':</b> ' + nThousand(skillPoints) + '<br />' +
                    '<b>' + labels.bought_points + ':</b> ' + nThousand(boughtPoints) + '<br />' +
                    '<b>' + labels.equipment_points + ':</b> ' + nThousand(itemPoints) + '<br />' +
                    '<b>' + labels.ginseng_points + ':</b> ' + nThousand(ginsengPoints) + '<br />' +
                    '<b>' + labels.club_points + ':</b> ' + nThousand(clubPoints) + '<br />'
                );
            }
        });
    }

    function calculateTotalPrice(points) {
        let last_price = calculateStatPrice(points);
        let price = 0;
        if (points < 2000) {
            price = (7 + last_price) / 2 * points;
        }
        else if (points < 4000) {
            price = 4012000 + (4009 + last_price) / 2 * (points - 2000);
        }
        else if (points < 6000) {
            price = 20026000 + (12011 + last_price) / 2 * (points - 4000);
        }
        else if (points < 8000) {
            price = 56042000 + (24013 + last_price) / 2 * (points - 6000);
        }
        else if (points < 10000) {
            price = 120060000 + (40015 + last_price) / 2 * (points - 8000);
        }
        else if (points < 12000) {
            price = 220080000 + (60017 + last_price) / 2 * (points - 10000);
        }
        else if (points < 14000) {
            price = 364102000 + (84019 + last_price) / 2 * (points - 12000);
        }
        else if (points < 16000) {
            price = 560126000 + (112021 + last_price) / 2 * (points - 14000);
        }
        else if (points < 18000) {
            price = 816152000 + (144023 + last_price) / 2 * (points - 16000);
        }
        else if (points < 20000) {
            price = 1140180000 + (180025 + last_price) / 2 * (points - 18000);
        }
        else if (points < 22000) {
            price = 1540210000 + (220027 + last_price) / 2 * (points - 20000);
        }
        else if (points < 24000) {
            price = 2024242000 + (264029 + last_price) / 2 * (points - 22000);
        }
        else if (points < 26000) {
            price = 2600276000 + (312031 + last_price) / 2 * (points - 24000);
        }
        else if (points < 28000) {
            price = 3276312000 + (364033 + last_price) / 2 * (points - 26000);
        }
        else if (points < 30000) {
            price = 4060350000 + (420035 + last_price) / 2 * (points - 28000);
        }
        return price;
    }

    function calculateStatPrice(points) {
        let cost = 0;
        if (points < 2000) {
            cost = 5 + points * 2;
        }
        else if (points < 4000) {
            cost = 4005 + (points - 2000) * 4;
        }
        else if (points < 6000) {
            cost = 12005 + (points - 4000) * 6;
        }
        else if (points < 8000) {
            cost = 24005 + (points - 6000) * 8;
        }
        else if (points < 10000) {
            cost = 40005 + (points - 8000) * 10;
        }
        else if (points < 12000) {
            cost = 60005 + (points - 10000) * 12;
        }
        else if (points < 14000) {
            cost = 84005 + (points - 12000) * 14;
        }
        else if (points < 16000) {
            cost = 112005 + (points - 14000) * 16;
        }
        else if (points < 18000) {
            cost = 144005 + (points - 16000) * 18;
        }
        else if (points < 20000) {
            cost = 180005 + (points - 18000) * 20;
        }
        else if (points < 22000) {
            cost = 220005 + (points - 20000) * 22;
        }
        else if (points < 24000) {
            cost = 264005 + (points - 22000) * 24;
        }
        else if (points < 26000) {
            cost = 312005 + (points - 24000) * 26;
        }
        else if (points < 28000) {
            cost = 364005 + (points - 26000) * 28;
        }
        else if (points < 30000) {
            cost = 420005 + (points - 28000) * 30;
        }
        return cost;
    }

    let lsMarket = {};
    lsMarket.buyable = {};
    lsMarket.stocks = {};
    lsMarket.restock = {};

    let restocktime = 0;
    let time = $('#equipement-tab-container .restock-info-timer span').text();
    if (time.indexOf('h') > -1) {
        restocktime = parseInt(time.substring(0, time.indexOf('h')), 10) * 3600;
        time = time.substring(time.indexOf('h') + 1);
    }
    if (time.indexOf('m') > -1) {
        restocktime += parseInt(time.substring(0, time.indexOf('m')), 10) * 60;
        time = time.substring(time.indexOf('h') + 1);
    }
    if (time.indexOf('s') > -1) {
        restocktime += parseInt(time.substring(0, time.indexOf('s')), 10);
    }

    lsMarket.restock.herolvl = window.Hero.infos.level;
    lsMarket.restock.time = (new Date()).getTime() + restocktime * 1000;

    get_buyableStocks('potion');
    get_buyableStocks('gift');
    equipments_shop(0);
    boosters_shop(0);
    books_shop(0);
    gifts_shop(0);

    new MutationObserver(() => {
        equipments_shop(1);
    }).observe($('#player-inventory.armor')[0], {childList: true})

    let timer;
    $('#shops button').click(function() {
        let clickedButton = $(this).attr('rel'),
            opened_shop = $('#tabs-switcher').children('.active');
        clearTimeout(timer);
        timer = setTimeout(function() {
            if (opened_shop[0].attributes.type.value == 'armor') {
                equipments_shop(1);
            }
            else if (opened_shop[0].attributes.type.value == 'booster') {
                boosters_shop(1);
            }
            else if (opened_shop[0].attributes.type.value == 'potion') {
                if (clickedButton == 'buy' || clickedButton == 'buy_all' || clickedButton == 'shop_reload') get_buyableStocks('potion');
                books_shop(1);
            }
            else if (opened_shop[0].attributes.type.value == 'gift') {
                if (clickedButton == 'buy' || clickedButton == 'buy_all' || clickedButton == 'shop_reload') get_buyableStocks('gift');
                gifts_shop(1);
            }
        }, 2*timeout);
    });

    function get_buyableStocks(loc_class) {
        let itemsNb = 0,
            itemsXp = 0,
            itemsPriceYmens = 0,
            itemsPriceKobans = 0,
            loc = $('#merchant-inventory.' + loc_class);
        loc.find('.slot').each(function() {
            if ($(this).hasClass('empty')) return false;
            let item = $(this).data('d');
            itemsNb++;
            itemsXp += parseInt(item.item.value, 10);
            if (item.item.currency == "sc") {
                itemsPriceYmens += parseInt(item.price_buy, 10);
            }
            else {
                itemsPriceKobans += parseInt(item.price_buy, 10);
            }
        });
        lsMarket.buyable[loc_class] = {'Nb':itemsNb, 'Xp':itemsXp, 'ValueYmens':itemsPriceYmens, 'ValueKobans':itemsPriceKobans};
    }

    function equipments_shop(update) {
        tt_create(update, 'armor', 'EquipmentsTooltip', 'equipments', '');
    }
    function boosters_shop(update) {
        tt_create(update, 'booster', 'BoostersTooltip', 'boosters', '');
    }
    function books_shop(update) {
        tt_create(update, 'potion', 'BooksTooltip', 'books', 'Xp');
    }
    function gifts_shop(update) {
        tt_create(update, 'gift', 'GiftsTooltip', 'gifts', 'affection');
    }

    function tt_create(update, loc_class, tt_class, itemName, itemUnit) {
        let itemsNb = 0,
            itemsXp = (itemUnit == '') ? -1 : 0,
            itemsSell = 0,
            loc = $('#player-inventory.' + loc_class);

        loc.find('.slot').each(function() {
            if ($(this).hasClass('empty')) return false;
            let item = $(this).data('d'),
                Nb = parseInt(item.quantity, 10) || 1;
            itemsNb += Nb;
            itemsSell += Nb * parseInt(item.price_sell, 10);
            if (itemsXp != -1) itemsXp += Nb * parseInt(item.item.value, 10);
        });

        let tooltip = labels.you_own + ' <b>' + nThousand(itemsNb) + '</b> ' + labels[itemName] + '.<br />' +
            (itemsXp == -1 ? '' : labels.you_can_give + ' <b>' + nThousand(itemsXp) + '</b> ' + labels[itemUnit] + '.<br />') +
            labels.you_can_sell + ' <b>' + nThousand(itemsSell) + '</b> <span class="imgMoney"></span>.';

        lsMarket.stocks[loc_class] = (loc_class == 'potion' || loc_class == 'gift') ? {'Nb':itemsNb, 'Xp':itemsXp} : {'Nb':itemsNb};
        localStorage.setItem('HHS.lsMarket', JSON.stringify(lsMarket));

        if (update == 0) {
            loc.prepend('<span class="CustomTT"></span><div class="' + tt_class + '">' + tooltip + '</div>');
        }
        else {
            loc.children('.' + tt_class).html(tooltip);
        }
    }
    $('plus').on('click', function (event) {
        let stat = 'carac' + $(this).attr('for_carac');
        window.Hero.infos[stat] += window.statsMultiplier[window.statsMultiplierIndex].nb;
        timer = setTimeout(function() {
            updateStats();
        }, 400);
    });

    modulePreventMythicBoosterSelling();

    function modulePreventMythicBoosterSelling() {
        const observer = new MutationObserver(() => {
            const sellButton = $('#boosters-tab-container .right-container .bottom-container button[rel=sell]');
            if($('#player-inventory.booster .slot.mythic.selected').length) sellButton.prop('disabled', true);
        });
        observer.observe($('#player-inventory.booster')[0], {subtree: true, attributes: true, attributeFilter: ['class']});
    }

    focusEquipmentKeeper();

    function focusEquipmentKeeper() {
        let selectedEquip;
        let previousSelectedEquip;

        const observerHero = new MutationObserver(() => {
            setTimeout(function() {
                selectedEquip = $('#player-inventory-armor .selected')[0];
                if (selectedEquip) {
                    previousSelectedEquip = selectedEquip.parentNode.previousElementSibling;
                    if (previousSelectedEquip) {
                        if (previousSelectedEquip.className != "slot-container") {
                            previousSelectedEquip = selectedEquip.parentNode.nextElementSibling.children[0];
                        }
                        else {
                            previousSelectedEquip = selectedEquip.parentNode.previousElementSibling.children[0];
                        }
                    }
                    else {
                        previousSelectedEquip = selectedEquip.parentNode.nextElementSibling.children[0];
                    }
                }
            }, timeout)
        });
        observerHero.observe($('#player-inventory-armor')[0], {subtree: true, attributes: true, attributeFilter: ['class']});

        $('#my-hero-equipement-tab-container button[rel=use]').click(function() {
            setTimeout(function() {
                $($('#my-hero-equipement-tab-container #equiped .selected')).removeClass('selected');
                $(previousSelectedEquip).addClass('selected');
                setTimeout(function() {$('#my-hero-equipement-tab-container button[rel=use]').prop('disabled', false)}, 100);
            }, timeout);
        });
    }

    //CSS
    sheet.insertRule('#player-inventory-container .CustomTT {'
                     + 'position: absolute;'
                     + 'margin-top: -25px;'
                     + 'background-image: url("https://i.postimg.cc/qBDt6yHV/icon-question.png");'
                     + 'background-size: 20px;'
                     + 'width: 20px;'
                     + 'height: 20px;}'
                    );

    sheet.insertRule('#player-inventory-container .CustomTT:hover {'
                     + 'cursor: help;}'
                    );

    sheet.insertRule('#player-inventory-container .CustomTT:hover + div {'
                     + 'opacity: 1;'
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#player-inventory-container .EquipmentsTooltip, #player-inventory-container .BoostersTooltip, #player-inventory-container .BooksTooltip, #player-inventory-container .GiftsTooltip {'
                     + 'position: absolute;'
                     + 'z-index: 99;'
                     + 'width: 240px;'
                     + 'border: 1px solid rgb(162, 195, 215);'
                     + 'border-radius: 8px;'
                     + 'box-shadow: 0px 0px 4px 0px rgba(0,0,0,0.1);'
                     + 'padding: 3px 7px 4px 7px;'
                     + 'background-color: #F2F2F2;'
                     + 'font: normal 10px/17px Tahoma, Helvetica, Arial, sans-serif;'
                     + 'color: #057;'
                     + 'opacity: 0;'
                     + 'visibility: hidden;'
                     + 'transition: opacity 400ms, visibility 400ms;}'
                    );

    sheet.insertRule('#player-inventory-container .EquipmentsTooltip, #player-inventory-container .BoostersTooltip {'
                     + 'margin: -50px 0 0 30px;'
                     + 'height: 43px;}'
                    );

    sheet.insertRule('#player-inventory-container .BooksTooltip, #player-inventory-container .GiftsTooltip {'
                     + 'margin: -67px 0 0 30px;'
                     + 'height: 60px;}'
                    );

    sheet.insertRule('#player-inventory-container .EquipmentsTooltip b, #player-inventory-container .BoostersTooltip b, #player-inventory-container .BooksTooltip b, #player-inventory-container .GiftsTooltip b {'
                     + 'font-weight: bold;}'
                    );

    sheet.insertRule('#player-inventory-container .imgMoney {'
                     + 'background-size: 12px;'
                     + 'background-repeat: no-repeat;'
                     + 'width: 12px;'
                     + 'height: 14px;'
                     + 'vertical-align: text-bottom;'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/ic_topbar_soft_currency.png");'
                     + 'display: inline-block;}'
                    );

    sheet.insertRule('#my-hero-stats-upgrade-tab-container .upgrade-stats-container .CustomStats:hover {'
                     + 'cursor: help;}'
                    );

    sheet.insertRule('#my-hero-stats-upgrade-tab-container .upgrade-stats-container .CustomStats {'
                     + 'position: relative;'
                     + 'left: -550px;'
                     + 'margin-top: 0px;'
                     + 'background-image: url("https://i.postimg.cc/qBDt6yHV/icon-question.png");'
                     + 'background-size: 18px 18px;'
                     + 'background-position: center;'
                     + 'background-repeat: no-repeat;'
                     + 'width: 18px;'
                     + 'height: 100%;'
                     + 'visibility: none;}'
                    );

    sheet.insertRule('#my-hero-stats-upgrade-tab-container .upgrade-stats-container .CustomStats:hover + div {'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#my-hero-stats-upgrade-tab-container .upgrade-stats-container .StatsTooltip {'
                     + 'position: absolute;'
                     + 'z-index: 99;'
                     + 'margin: -30px 0 0 32px;'
                     + 'border: 1px solid rgb(162, 195, 215);'
                     + 'border-radius: 8px;'
                     + 'box-shadow: 0px 0px 4px 0px rgba(0,0,0,0.1);'
                     + 'padding: 2px 17px 2px 7px;'
                     + 'background-color: #F2F2F2;'
                     + 'font: normal 10px/17px Tahoma, Helvetica, Arial, sans-serif;'
                     + 'text-align: left;'
                     + 'white-space: nowrap;'
                     + 'opacity: 0;'
                     + 'visibility: hidden;'
                     + 'color: #057;'
                     + 'transition: opacity 400ms, visibility 400ms;}'
                    );

    sheet.insertRule('#my-hero-stats-upgrade-tab-container .upgrade-stats-container .StatsTooltip b {'
                     + 'font-weight: bold;}'
                    );

    sheet.insertRule('#equipement-tab-container button[rel=buy_all] {'
                     + 'display: none !important;}'
                    );
}

function moduleMarketRestockButton() {
    sheet.insertRule('#books-tab-container .left-container .bottom-container, #gifts-tab-container .left-container .bottom-container {'
                     + 'margin-right: 15px;}'
                    );

    sheet.insertRule('#shops #gifts-tab-container .top-container button[rel="shop_reload"], #shops #books-tab-container .top-container button[rel="shop_reload"] {'
                     + 'position: relative;'
                     + 'left: 114px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#shops #gifts-tab-container .top-container button[rel="shop_reload"], #shops #books-tab-container .top-container button[rel="shop_reload"] {'
                     + 'top: 392px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#shops #gifts-tab-container .top-container button[rel="shop_reload"], #shops #books-tab-container .top-container button[rel="shop_reload"] {'
                     + 'top: 380px;}}'
                    );

    sheet.insertRule('#shops [rel="buy"], #shops [rel="buy_all"], #shops [rel="sell"], #shops [rel="shop_reload"], #shops [rel="use"] {'
                     + 'max-width: 11rem !important;}'
                    );

    sheet.insertRule('.restock-timer > p {'
                     + 'min-width: 155px;}'
                    );
}


/* ========================
	FILTER EQUIPMENT ITEMS
   ======================== */
function moduleFilterArmorItems() {
    if (localStorage.getItem('HHS.market_paramFilterHero')) {
        if (!JSON.parse(localStorage.getItem('HHS.market_paramFilterHero')).resonance_class) {
            localStorage.removeItem('HHS.market_paramFilterHero');
            localStorage.removeItem('HHS.market_paramFilterEquip');
        }
    }

    $('#my-hero-equipement-tab-container #player-inventory-armor.armor').prepend($('#my-hero-equipement-tab-container #player-inventory-armor.armor .nicescroll-rails-vr'));
    $('#my-hero-equipement-tab-container #player-inventory-armor.armor').prepend($('#my-hero-equipement-tab-container #player-inventory-armor.armor .nicescroll-rails-hr'));

    $('#equipement-tab-container #player-inventory.armor').prepend($('#equipement-tab-container #player-inventory.armor .nicescroll-rails-vr'));
    $('#equipement-tab-container #player-inventory.armor').prepend($('#equipement-tab-container #player-inventory.armor .nicescroll-rails-hr'));

    $('#my-hero-tab-container .my-hero-content-tabs .my-hero-switch-tab[type="armor"]')[0].addEventListener("click", function() {
        $('#my-hero-equipement-tab-container #player-inventory-armor.armor').prepend($('#my-hero-equipement-tab-container #player-inventory-armor.armor .nicescroll-rails-vr'));
        $('#my-hero-equipement-tab-container #player-inventory-armor.armor').prepend($('#my-hero-equipement-tab-container #player-inventory-armor.armor .nicescroll-rails-hr'));
    });

    $('#tabs-switcher .market-menu-switch-tab[type="player-stats"]')[0].addEventListener("click", function() {
        $('#my-hero-equipement-tab-container #player-inventory-armor.armor').prepend($('#my-hero-equipement-tab-container #player-inventory-armor.armor .nicescroll-rails-vr'));
        $('#my-hero-equipement-tab-container #player-inventory-armor.armor').prepend($('#my-hero-equipement-tab-container #player-inventory-armor.armor .nicescroll-rails-hr'));
    });

    $('#tabs-switcher .market-menu-switch-tab[type="armor"]')[0].addEventListener("click", function() {
        $('#equipement-tab-container #player-inventory.armor').prepend($('#equipement-tab-container #player-inventory.armor .nicescroll-rails-vr'));
        $('#equipement-tab-container #player-inventory.armor').prepend($('#equipement-tab-container #player-inventory.armor .nicescroll-rails-hr'));
    });

    const getFavorites = () => JSON.parse(localStorage.getItem('HHS.EQUIP_FAVORITES')) || [];
    const setFavorites = (favorites) => localStorage.setItem('HHS.EQUIP_FAVORITES', JSON.stringify(favorites));
    const addToFavorites = (id) => {
        const favorites = getFavorites()
        if (favorites.includes(id)) {return}

        favorites.push(id)
        setFavorites(favorites)
    };
    const removeFromFavorites = (id) => {
        const favorites = getFavorites()
        const index = favorites.indexOf(id)
        if (index < 0) {return}

        favorites.splice(index, 1)
        setFavorites(favorites)
    };

    const getParamFilterHero = () => JSON.parse(localStorage.getItem('HHS.market_paramFilterHero')) || {subtype: FILTER_DEFAULT, rarity: FILTER_DEFAULT, stats: FILTER_DEFAULT, favorites: FILTER_DEFAULT, resonance_class: FILTER_DEFAULT, resonance_class_type: FILTER_DEFAULT, resonance_theme: FILTER_DEFAULT, resonance_theme_type: FILTER_DEFAULT};
    const setParamFilterHero = (paramFilterHero) => localStorage.setItem('HHS.market_paramFilterHero', JSON.stringify(paramFilterHero));
    const getParamFilterEquip = () => JSON.parse(localStorage.getItem('HHS.market_paramFilterEquip')) || {subtype: FILTER_DEFAULT, rarity: FILTER_DEFAULT, stats: FILTER_DEFAULT, favorites: FILTER_DEFAULT, resonance_class: FILTER_DEFAULT, resonance_class_type: FILTER_DEFAULT, resonance_theme: FILTER_DEFAULT, resonance_theme_type: FILTER_DEFAULT};
    const setParamFilterEquip = (paramFilterEquip) => localStorage.setItem('HHS.market_paramFilterEquip', JSON.stringify(paramFilterEquip));

    const FILTER_DEFAULT = 'all';
    const FILTER_DEFAULT_ICON = 'caracs/no_class.png';
    const FILTER_OPTIONS = new (class {
        get subtype () {return [
            {value: '1', icon: 'pictures/items/ET1.png'},
            {value: '2', icon: 'pictures/items/EH1.png'},
            {value: '3', icon: 'pictures/items/EB1.png'},
            {value: '4', icon: 'pictures/items/ES1.png'},
            {value: '5', icon: 'pictures/items/EF1.png'},
            {value: '6', icon: 'pictures/items/EA1.png'}
        ]}
        get rarity () {return [
            {value: 'common', bgColor: '#8d8e9f'},
            {value: 'rare', bgColor: '#23b56b'},
            {value: 'epic', bgColor: '#ffb244'},
            {value: 'legendary', bgImage: `url(${window.IMAGES_URL}/legendary.png)`},
            {value: 'mythic', bgColor: 'transparent radial-gradient(closest-side at 50% 50%,#f5a866 0,#ec0039 51%,#9e0e27 100%) 0 0 no-repeat padding-box'}
        ]}
        get stats () {return [
            {value: 'rainbow', icon: 'pictures/misc/items_icons/16.svg'},
            {value: 'hc', icon: 'pictures/misc/items_icons/1.png'},
            {value: 'ch', icon: 'pictures/misc/items_icons/2.png'},
            {value: 'kh', icon: 'pictures/misc/items_icons/3.png'},
            {value: 'end', icon: 'pictures/misc/items_icons/4.png'},
            {value: 'har', icon: 'pictures/misc/items_icons/5.png'}
        ]}
        get favorites () {return [
            {value: true, icon: 'design/ic_star_orange.svg'},
            {value: false, icon: 'design/ic_star_white.svg'}
        ]}
        get resonance_class () {return [
            {value: '1', icon: 'pictures/misc/items_icons/1.png'},
            {value: '2', icon: 'pictures/misc/items_icons/2.png'},
            {value: '3', icon: 'pictures/misc/items_icons/3.png'}
        ]}
        get resonance_class_type () {return [
            {value: 'damage', icon: 'caracs/damage.png'},
            {value: 'ego', icon: 'caracs/ego.png'}
        ]}
        get resonance_theme () {return [
            {value: 'multi', icon: 'pictures/girls_elements/Multicolored.png'},
            {value: 'fire', icon: 'pictures/girls_elements/Eccentric.png'},
            {value: 'nature', icon: 'pictures/girls_elements/Exhibitionist.png'},
            {value: 'stone', icon: 'pictures/girls_elements/Physical.png'},
            {value: 'sun', icon: 'pictures/girls_elements/Playful.png'},
            {value: 'water', icon: 'pictures/girls_elements/Sensual.png'},
            {value: 'darkness', icon: 'pictures/girls_elements/Dominatrix.png'},
            {value: 'light', icon: 'pictures/girls_elements/Submissive.png'},
            {value: 'psychic', icon: 'pictures/girls_elements/Voyeurs.png'}
        ]}
        get resonance_theme_type () {return [
            {value: 'defense', icon: 'caracs/deff_undefined.png'},
            {value: 'chance', icon: 'pictures/misc/items_icons/5.png'}
        ]}
    })();
    const FILTER_OPTIONS_GRIDS = {
        subtype: {
            flow: 'column',
            cols: '1fr 1fr 1fr',
            rows: '1fr 1fr'
        },
        rarity: {
            flow: 'row',
            cols: '1fr 1fr 1fr',
            rows: '1fr 1fr'
        },
        stats: {
            flow: 'row',
            cols: '1fr 1fr 1fr',
            rows: '1fr 1fr',
        },
        favorites: {
            flow: 'row',
            cols: '1fr auto',
            rows: '1fr'
        },
        resonance_class: {
            flow: 'row',
            cols: '1fr 1fr 1fr',
            rows: '1fr'
        },
        resonance_class_type: {
            flow: 'row',
            cols: '1fr 1fr',
            rows: '1fr'
        },
        resonance_theme: {
            flow: 'row',
            cols: '1fr 1fr 1fr',
            rows: '1fr 1fr 1fr'
        },
        resonance_theme_type: {
            flow: 'row',
            cols: '1fr 1fr',
            rows: '1fr'
        }
    };
    const STATS_MAP = {
        rainbow: [16],
        hc:[1, 6, 7, 8, 9],
        ch: [2, 6, 10, 11, 12],
        kh: [3, 7, 10, 13, 14],
        end: [4, 8, 11, 13, 15],
        har: [5, 9, 12, 14, 15],
    };

    const createGridSelectorItem = ({location, id, value, icon, bgColor, bgImage}) => (`<input type="radio" name=${location}-${id} id="${location}-${id}-${value}" value="${value}" class="${(currentFilter(location)[id] == '' + value) ? "filter_selected" : ""}" />`
                                                                                       + `<label for="${location}-${id}-${value}">`
                                                                                       + `${icon ? `<img src="${window.IMAGES_URL}/${icon}">` : ''}`
                                                                                       + `${bgColor || bgImage ? `<div style="${bgColor?`background:${bgColor};`:''}${bgImage?`background-image:${bgImage};background-size:contain;`:''}"></div>` : ''}`
                                                                                       + '</label>')

    const createGridSelector = ({location, id, options, gridConfig}) => (`<div class="grid-selector" rel="${location}-${id}">`
                                                                         + '<div class="clear-selector">'
                                                                         + `<input type="radio" name="${location}-${id}" id="${location}-${id}-${FILTER_DEFAULT}" class="${(currentFilter(location)[id] == FILTER_DEFAULT) ? "filter_selected" : ""}" value="${FILTER_DEFAULT}" />`
                                                                         + `<label for="${location}-${id}-${FILTER_DEFAULT}">`
                                                                         + `<img src="${window.IMAGES_URL}/${FILTER_DEFAULT_ICON}" />`
                                                                         + '</label>'
                                                                         + '</div>'
                                                                         + `<div class="selector-options" style="grid-auto-flow:${gridConfig.flow}; grid-template-rows:${gridConfig.rows}; grid-template-columns:${gridConfig.cols}">`
                                                                         + `${options.map(option => {
        const {value, icon, bgColor, bgImage} = option
        return createGridSelectorItem({location, id, value, icon, bgColor, bgImage})
    }).join('')}`
                                                                         + '</div>'
                                                                         + '</div>'
                                                                         + '<hr style="margin-top: 3px;margin-bottom: 3px; background: rgba(255, 255, 255, 0.533);">');

    const createFilterBox = (location) => {
        return $('<div style="position:relative">'
                 + `<div class="equip_filter_box ${location} form-wrapper" style="display: none;">`
                 + `${['subtype', 'rarity', 'stats', 'favorites'].map(key => createGridSelector({location : location, id: key, options: FILTER_OPTIONS[key], gridConfig: FILTER_OPTIONS_GRIDS[key]})).join('')}`
                 + `<button id="reset_button-${location}" class="blue_button_L">Reset</button>`
                 + '</div>'
                 + `<div class="equip_filter_box resonance ${location} form-wrapper" style="display: none;">`
                 + `<span>${window.GT.design.mythic_equipment_resonance_bonus}</span>`
                 + `${['resonance_class', 'resonance_class_type', 'resonance_theme', 'resonance_theme_type'].map(key => createGridSelector({location : location, id: key, options: FILTER_OPTIONS[key], gridConfig: FILTER_OPTIONS_GRIDS[key]})).join('')}`
                 + '</div>'
                 + '</div>')
    };

    const createFilterBtn = () => {
        return $('<label class="equip_filter"><input type="button" class="blue_button_L" value="" /></label>')
    };

    const makeEquipKey = ({level, carac1_equip, carac2_equip, carac3_equip, endurance_equip, chance_equip},{id_equip},{identifier, subtype}) => [identifier, subtype, id_equip, level, carac1_equip, carac2_equip, carac3_equip, endurance_equip, chance_equip].join('_');

    const makeEquipKeyMythic = ({level, carac1_equip, carac2_equip, carac3_equip, endurance_equip, chance_equip},{identifier, subtype},classIdentifier,classResonance,themeIdentifier,themeResonance) => [identifier, subtype, level, carac1_equip, carac2_equip, carac3_equip, endurance_equip, chance_equip, classIdentifier, classResonance, themeIdentifier, themeResonance].join('_');

    const currentFilter = (location) => (location == 'hero') ? this.currentFilterHero : this.currentFilterEquip;
    this.currentFilterHero = getParamFilterHero();
    this.currentFilterEquip = getParamFilterEquip();

    function applyFilter($target, location) {
        const favorites = getFavorites()
        const $visibleEquips = $target.find('.slot:not(.empty)')

        let visibleCount = 0

        $visibleEquips.each((i,el) => {
            const $el = $(el)
            const equipData = $el.data('d')
            const {name_add, rarity} = equipData.item
            const {subtype} = equipData.skin

            const classIdentifier = (rarity == 'mythic') ? equipData.resonance_bonuses.class.identifier : 0
            const classResonance = (rarity == 'mythic') ? equipData.resonance_bonuses.class.resonance : 0
            const themeIdentifier = (rarity == 'mythic') ? (equipData.resonance_bonuses.theme.identifier || 'multi') : 0
            const themeResonance = (rarity == 'mythic') ? equipData.resonance_bonuses.theme.resonance : 0

            const equipKey = (rarity != 'mythic') ? makeEquipKey(equipData, equipData.item, equipData.skin) : makeEquipKeyMythic(equipData, equipData.skin, classIdentifier, classResonance, themeIdentifier, themeResonance)

            const isFavorite = favorites.includes(equipKey)

            let $favoriteToggle = $el.find('.favorite-toggle')
            if (!$favoriteToggle.length) {
                $favoriteToggle = this.$favoriteToggle.clone().attr('data-equip-key', equipKey)
                $el.prepend($favoriteToggle)
            } else {
                $favoriteToggle.off('click')
            }
            $favoriteToggle.click(this.favoriteToggleCallback)
            $favoriteToggle.attr('data-is-favorite', isFavorite)

            const subtypeMatches = (location == 'hero') ? (this.currentFilterHero.subtype == FILTER_DEFAULT || this.currentFilterHero.subtype == subtype) : (this.currentFilterEquip.subtype == FILTER_DEFAULT || this.currentFilterEquip.subtype == subtype)
            const rarityMatches = (location == 'hero') ? (this.currentFilterHero.rarity == FILTER_DEFAULT || this.currentFilterHero.rarity == rarity) : (this.currentFilterEquip.rarity == FILTER_DEFAULT || this.currentFilterEquip.rarity == rarity)
            const statsMatches = (location == 'hero') ? (this.currentFilterHero.stats == FILTER_DEFAULT || STATS_MAP[this.currentFilterHero.stats].includes(name_add)) : (this.currentFilterEquip.stats == FILTER_DEFAULT || STATS_MAP[this.currentFilterEquip.stats].includes(name_add))
            const favoritesMatches = (location == 'hero') ? (this.currentFilterHero.favorites == FILTER_DEFAULT || JSON.parse(this.currentFilterHero.favorites) == isFavorite) : (this.currentFilterEquip.favorites == FILTER_DEFAULT || JSON.parse(this.currentFilterEquip.favorites) == isFavorite)
            const classIdentifierMatches = (location == 'hero') ? (this.currentFilterHero.resonance_class == FILTER_DEFAULT || this.currentFilterHero.resonance_class == classIdentifier) : (this.currentFilterEquip.resonance_class == FILTER_DEFAULT || this.currentFilterEquip.resonance_class == classIdentifier)
            const classResonanceMatches = (location == 'hero') ? (this.currentFilterHero.resonance_class_type == FILTER_DEFAULT || this.currentFilterHero.resonance_class_type == classResonance) : (this.currentFilterEquip.resonance_class_type == FILTER_DEFAULT || this.currentFilterEquip.resonance_class_type == classResonance)
            const themeIdentifierMatches = (location == 'hero') ? (this.currentFilterHero.resonance_theme == FILTER_DEFAULT || this.currentFilterHero.resonance_theme == themeIdentifier) : (this.currentFilterEquip.resonance_theme == FILTER_DEFAULT || this.currentFilterEquip.resonance_theme == themeIdentifier)
            const themeResonanceMatches = (location == 'hero') ? (this.currentFilterHero.resonance_theme_type == FILTER_DEFAULT || this.currentFilterHero.resonance_theme_type == themeResonance) : (this.currentFilterEquip.resonance_theme_type == FILTER_DEFAULT || this.currentFilterEquip.resonance_theme_type == themeResonance)

            if ([subtypeMatches, rarityMatches, statsMatches, favoritesMatches, classIdentifierMatches, classResonanceMatches, themeIdentifierMatches, themeResonanceMatches].every(a=>a)) {
                $(el).removeClass('filtered_out')
                $(el)[0].parentNode.classList.remove('filtered_out')
                visibleCount++
            } else {
                $(el).addClass('filtered_out')
                $(el)[0].parentNode.classList.add('filtered_out')
            }
        })

        const $container = $target
        if (visibleCount < 12) {
            const $visibleSlots = $container.find('.slot:visible()')
            // pad with empty slots
            let toPad = 12 - $visibleSlots.length
            while (toPad > 0) {
                $container.find('.slot').last().after('<div class="slot empty"></div>')
                toPad--
            }
        }
        $container.children('.armor').getNiceScroll().resize()
    }

    function checkSelection($target) {
        let $selected = $target.find('.selected');
        const sellButton = $('#equipement-tab-container .right-container .bottom-container button[rel=sell]');
        const equipButton = $('#my-hero-equipement-tab-container .my-inventory-equipement-container .my-inventory .bottom-container button[rel=use]');

        if ($selected.length){
            if ($selected.is(':visible')) {
                // check for favourite
                const isFavorite = JSON.parse($selected.find('.favorite-toggle').attr('data-is-favorite'))
                if (isFavorite) {
                    sellButton.prop('disabled', true)
                }
            } else {
                // change selection
                const $container = $target;
                const index = $selected.index()
                let $newSelection
                let newSelection

                // first, try after
                $newSelection = $container.find(`.slot:gt(${index}):not(.empty):visible()`)
                if ($newSelection.length) {
                    newSelection = $newSelection[0]
                }

                if (!newSelection) {
                    // try before instead
                    $newSelection = $container.find(`.slot:lt(${index}):not(.empty):visible()`)

                    if ($newSelection.length) {
                        newSelection = $newSelection[$newSelection.length - 1]
                    }
                }

                if (newSelection) {
                    $(newSelection).click()
                } else {
                    // Nothing left visible, disable buttons
                    sellButton.prop('disabled', true);
                    equipButton.prop('disabled', true);
                }
            }
        }
    }

    $(document).on('market:equips-updated', () => {
        applyFilter($('#my-hero-equipement-tab-container #player-inventory-container'), 'hero');
        applyFilter($('#equipement-tab-container #player-inventory-container'), 'equip');
        checkSelection($('#my-hero-equipement-tab-container #player-inventory-container'));
        checkSelection($('#equipement-tab-container #player-inventory-container'))
    });

    const attachFilterBox = ($target, location) => {
        const $btn = createFilterBtn()
        const $box = createFilterBox(location)
        const $togglable = $box.find('.equip_filter_box')

        $target.append($btn).append($box)

        $btn.click(() => $togglable.toggle())
        $(`#reset_button-${location}`).click(() => resetFilter($target, location));
        $box.find('input').each((i, input) => {
            $(input).click((e) => {
                const {value, name} = e.target;
                $(`div[rel=${name}] .filter_selected`).removeClass('filter_selected');
                $(`#${name}-${value}`).addClass('filter_selected');
                let newName = name.split('-')[1]
                if (location == 'hero') {
                    this.currentFilterHero[newName] = value;
                    setParamFilterHero(this.currentFilterHero);
                }
                else {
                    this.currentFilterEquip[newName] = value;
                    setParamFilterEquip(this.currentFilterEquip);
                }
                applyFilter($target, location)
                checkSelection($target);
            })
        })
    }

    function resetFilter($target, location) {
        let formerSubtype = currentFilter(location).subtype;
        let formerRarity = currentFilter(location).rarity;
        let formerStats = currentFilter(location).stats;
        let formerFavorites = currentFilter(location).favorites;
        let formerClass = currentFilter(location).resonance_class;
        let formerClassType = currentFilter(location).resonance_class_type;
        let formerTheme = currentFilter(location).resonance_theme;
        let formerThemeType = currentFilter(location).resonance_theme_type;

        currentFilter(location).subtype = FILTER_DEFAULT;
        currentFilter(location).rarity = FILTER_DEFAULT;
        currentFilter(location).stats = FILTER_DEFAULT;
        currentFilter(location).favorites = FILTER_DEFAULT;
        currentFilter(location).resonance_class = FILTER_DEFAULT;
        currentFilter(location).resonance_class_type = FILTER_DEFAULT;
        currentFilter(location).resonance_theme = FILTER_DEFAULT;
        currentFilter(location).resonance_theme_type = FILTER_DEFAULT;

        $(`#${location}-subtype-` + formerSubtype).removeClass('filter_selected');
        $(`#${location}-subtype-` + FILTER_DEFAULT).addClass('filter_selected');
        $(`#${location}-rarity-` + formerRarity).removeClass('filter_selected');
        $(`#${location}-rarity-` + FILTER_DEFAULT).addClass('filter_selected');
        $(`#${location}-stats-` + formerStats).removeClass('filter_selected');
        $(`#${location}-stats-` + FILTER_DEFAULT).addClass('filter_selected');
        $(`#${location}-favorites-` + formerFavorites).removeClass('filter_selected');
        $(`#${location}-favorites-` + FILTER_DEFAULT).addClass('filter_selected');
        $(`#${location}-resonance_class-` + formerClass).removeClass('filter_selected');
        $(`#${location}-resonance_class-` + FILTER_DEFAULT).addClass('filter_selected');
        $(`#${location}-resonance_class_type-` + formerClassType).removeClass('filter_selected');
        $(`#${location}-resonance_class_type-` + FILTER_DEFAULT).addClass('filter_selected');
        $(`#${location}-resonance_theme-` + formerTheme).removeClass('filter_selected');
        $(`#${location}-resonance_theme-` + FILTER_DEFAULT).addClass('filter_selected');
        $(`#${location}-resonance_theme_type-` + formerThemeType).removeClass('filter_selected');
        $(`#${location}-resonance_theme_type-` + FILTER_DEFAULT).addClass('filter_selected');

        if (location == 'hero') setParamFilterHero(this.currentFilterHero);
        else setParamFilterEquip(this.currentFilterEquip);
        applyFilter($target, location);
        checkSelection($target);
    }

    this.$favoriteToggle = $('<div class="favorite-toggle"></div>')
    this.favoriteToggleCallback = (e) => {
        const $favoriteToggle = $(e.target)
        const equipKey = `${$favoriteToggle.data('equip-key')}`
        const isFavorite = JSON.parse($favoriteToggle.attr('data-is-favorite'))

        if (isFavorite) {
            removeFromFavorites(equipKey)
        } else {
            addToFavorites(equipKey)
        }
        applyFilter($('#my-hero-equipement-tab-container #player-inventory-container'), 'hero')
        applyFilter($('#equipement-tab-container #player-inventory-container'), 'equip')
    }

    attachFilterBox($('#my-hero-equipement-tab-container #player-inventory-container'), 'hero')
    attachFilterBox($('#equipement-tab-container #player-inventory-container'), 'equip')
    applyFilter($('#my-hero-equipement-tab-container #player-inventory-container'), 'hero')
    applyFilter($('#equipement-tab-container #player-inventory-container'), 'equip')

    const favouriteSafetyObserver1 = new MutationObserver(() => checkSelection($('#my-hero-equipement-tab-container #player-inventory-container')))
    const favouriteSafetyObserver2 = new MutationObserver(() => checkSelection($('#equipement-tab-container #player-inventory-container')))
    favouriteSafetyObserver1.observe($('#my-hero-equipement-tab-container #player-inventory-container')[0], {subtree: true, attributes: true, attributeFilter: ['class']})
    favouriteSafetyObserver2.observe($('#equipement-tab-container #player-inventory-container')[0], {subtree: true, attributes: true, attributeFilter: ['class']})

    //CSS
    sheet.insertRule('label.equip_filter {'
                     + 'width: 32px;'
                     + 'position: absolute;'
                     + 'background: transparent;}'
                    );

    sheet.insertRule('#my-hero-equipement-tab-container #player-inventory-container label.equip_filter {'
                     + 'left: 227px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#my-hero-equipement-tab-container #player-inventory-container label.equip_filter {'
                     + 'top: 87px;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#my-hero-equipement-tab-container #player-inventory-container label.equip_filter {'
                     + 'top: 62px;}'
                    );

    sheet.insertRule('#equipement-tab-container #player-inventory-container label.equip_filter {'
                     + 'top: 30px !important;}'
                    );

    if (localStorage.getItem('HHPlusPlusConfig')) {
        if (JSON.parse(localStorage.getItem('HHPlusPlusConfig')).zoo_MarketTweaks) {
            sheet.insertRule('#my-hero-equipement-tab-container #player-inventory-container label.equip_filter {'
                             + 'left: 302px !important;}'
                            );

            sheet.insertRule('#my-hero-equipement-tab-container #player-inventory-container .equip_filter_box {'
                             + 'top: -448px !important;'
                             + 'left: -57px !important;}'
                            );

            sheet.insertRule('#my-hero-equipement-tab-container #player-inventory-container .equip_filter_box.resonance {'
                             + 'top: -448px !important;'
                             + 'left: -162px !important;}'
                            );

            sheet.insertRule('#equipement-tab-container #player-inventory-container .equip_filter_box {'
                             + 'left: -557px !important;'
                             + 'top: 10px !important;}'
                            );

            sheet.insertRule('#equipement-tab-container #player-inventory-container .equip_filter_box.resonance {'
                             + 'left: -662px !important;'
                             + 'top: 10px !important;}'
                            );

            sheet.insertRule('#equipement-tab-container .right-container .bottom-container button[rel="sell"] {'
                             + 'margin-left: 155px;}'
                            );
        }
    }

    sheet.insertRule('.equip_filter input {'
                     + 'height: 32px;'
                     + 'width: 32px;'
                     + 'display: block;'
                     + 'padding: 0px;}'
                    );

    sheet.insertRule('label.equip_filter::before {'
                     + 'content: " ";'
                     + 'display: block;'
                     + 'position: absolute;'
                     + 'height: 100%;'
                     + 'width: 100%;'
                     + 'background-position: center;'
                     + 'background-size: 24px;'
                     + 'background-repeat: no-repeat;'
                     + 'background-image: url("' + window.IMAGES_URL + '/design_v2/search_open.png");'
                     + 'pointer-events: none;}'
                    );

    sheet.insertRule('.equip_filter_box {'
                     + 'position: absolute;'
                     + 'width: 105px !important;'
                     + 'height: -moz-fit-content;'
                     + 'height: fit-content;'
                     + 'z-index: 3;'
                     + 'border-radius: 8px 10px 10px 8px;'
                     + 'background-color: rgb(30, 38, 30);'
                     + 'box-shadow: rgba(255, 255, 255, 0.73) 0px 0px;'
                     + 'padding: 5px;'
                     + 'border: 1px solid rgb(255, 162, 62);}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#my-hero-equipement-tab-container #player-inventory-container .equip_filter_box {'
                     + 'left: -118px !important;'
                     + 'top: -377px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#my-hero-equipement-tab-container #player-inventory-container .equip_filter_box.resonance {'
                     + 'text-align: center;'
                     + 'left: -222px !important;'
                     + 'top: -377px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#equipement-tab-container #player-inventory-container .equip_filter_box {'
                     + 'left: -578px !important;'
                     + 'top: 15px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#equipement-tab-container #player-inventory-container .equip_filter_box.resonance {'
                     + 'text-align: center;'
                     + 'left: -683px !important;'
                     + 'top: 15px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#my-hero-equipement-tab-container #player-inventory-container .equip_filter_box {'
                     + 'left: -118px !important;'
                     + 'top: -397px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#my-hero-equipement-tab-container #player-inventory-container .equip_filter_box.resonance {'
                     + 'text-align: center;'
                     + 'left: -222px !important;'
                     + 'top: -397px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#equipement-tab-container #player-inventory-container .equip_filter_box {'
                     + 'left: -578px !important;'
                     + 'top: 0px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#equipement-tab-container #player-inventory-container .equip_filter_box.resonance {'
                     + 'text-align: center;'
                     + 'left: -683px !important;'
                     + 'top: 0px !important;}}'
                    );

    sheet.insertRule('.equip_filter_box label {'
                     + 'background: transparent;'
                     + 'width: auto;'
                     + 'margin: 0px;}'
                    );

    sheet.insertRule('.grid-selector {'
                     + 'width: 100%;'
                     + 'display: flex;'
                     + 'align-items: center;'
                     + 'justify-content: center;'
                     + 'flex-direction: column;}'
                    );

    sheet.insertRule('.grid-selector:last-child {'
                     + 'margin-bottom: 0px;}'
                    );

    sheet.insertRule('.grid-selector input {'
                     + 'display: none;}'
                    );

    sheet.insertRule('.grid-selector .selector-options {'
                     + 'width: -moz-fit-content;'
                     + 'width: fit-content;'
                     + 'display: grid;'
                     + 'grid-gap: 2px;}'
                    );

    sheet.insertRule('.grid-selector .selector-options img {'
                     + 'height: 28px;'
                     + 'width: 28px;'
                     + 'margin: 2px;}'
                    );

    sheet.insertRule('.grid-selector .selector-options div {'
                     + 'height: 28px;'
                     + 'width: 28px;'
                     + 'margin: 2px;'
                     + 'border-radius: 5px;}'
                    );

    sheet.insertRule('.grid-selector .clear-selector {'
                     + 'margin-bottom: 5px;'
                     + 'width: fit-content;}'
                    );

    sheet.insertRule('.grid-selector .clear-selector img {'
                     + 'height: 32px;'
                     + 'width: 32px;}'
                    );

    sheet.insertRule('.equip_filter_box .grid-selector input.filter_selected + label, .equip_filter_box .grid-selector input:hover + label {'
                     + 'background-color: #fff8 !important;}'
                    );

    sheet.insertRule('.slot .favorite-toggle {'
                     + 'position: absolute;'
                     + 'display: none;'
                     + 'height: 32px;'
                     + 'width: 32px;'
                     + 'top: 0px;'
                     + 'right: 0px;'
                     + 'background-size: 22px;'
                     + 'background-repeat: no-repeat;'
                     + 'background-position: center;'
                     + 'z-index: 1;'
                     + 'border-top-right-radius: 5px;'
                     + 'border-bottom-left-radius: 5px;}'
                    );

    sheet.insertRule('.slot:hover .favorite-toggle[data-is-favorite="false"], .slot .favorite-toggle[data-is-favorite="true"] {'
                     + 'display: block;}'
                    );

    sheet.insertRule('.slot .favorite-toggle[data-is-favorite="false"] {'
                     + 'background-image: url("' + window.IMAGES_URL + '/design/ic_star_white.svg");'
                     + 'opacity: 0.7;}'
                    );

    sheet.insertRule('.slot .favorite-toggle[data-is-favorite="true"] {'
                     + 'background-color: rgba(30, 38, 30, 0.7);'
                     + 'background-image: url("' + window.IMAGES_URL + '/design/ic_star_orange.svg");}'
                    );

    sheet.insertRule('.filtered_out {'
                     + 'display: none !important;}'
                    );

    sheet.insertRule('#player-inventory-armor .slot.empty, #player-inventory .slot.empty, #merchant-inventory .slot.empty {'
                     + 'display: none !important;}'
                    );
}


/* ==========================
	MYTHIC EQUIPMENT UPGRADE
   ========================== */

function moduleMythicEquipmentUpgrade() {
    const fixFavoritesID = () => {
        if(!localStorage.getItem('HHS.EQUIP_FAVORITES')) return [];

        let favoritesID = JSON.parse(localStorage.getItem('HHS.EQUIP_FAVORITES'));
        let newFavoritesID = [];
        favoritesID.forEach(id => {
            if (id.indexOf('-') != -1) {
                let indexBegin = id.indexOf('-') - 3;
                let indexEnd = id.lastIndexOf('-') + 3;
                newFavoritesID.push(id.substring(0,indexBegin).concat(id.substring(indexEnd)));
            }
            else newFavoritesID.push(id);
        })

        return newFavoritesID;
    }

    const getFavorites = () => JSON.parse(localStorage.getItem('HHS.EQUIP_FAVORITES')) || [];

    const makeEquipKey = ({level, carac1_equip, carac2_equip, carac3_equip, endurance_equip, chance_equip},{identifier, subtype}) => [identifier, subtype, level, carac1_equip, carac2_equip, carac3_equip, endurance_equip, chance_equip].join('_');

    const makeEquipKeyMythic = ({level, carac1_equip, carac2_equip, carac3_equip, endurance_equip, chance_equip},{identifier, subtype},classIdentifier,classResonance,themeIdentifier,themeResonance) => [identifier, subtype, level, carac1_equip, carac2_equip, carac3_equip, endurance_equip, chance_equip, classIdentifier, classResonance, themeIdentifier, themeResonance].join('_');


    function protectFavoriteItems() {
        const favorites = fixFavoritesID();
        const $visibleEquips = $('.mythic-equipment-panel .mythic-equipment-container .inventory-section .inventory-container .items-container').find('.slot');

        if($('.item-container.protected.selected').length > 0) {
            $('button#level-up').prop('disabled', true);
        }

        for (let i=0; i<$visibleEquips.length; i++) {
            const $el = $visibleEquips[i];
            const equipData = JSON.parse($el.dataset.d)
            const {name_add, rarity} = equipData.item
            const {subtype} = equipData.skin

            const classIdentifier = (rarity == 'mythic') ? equipData.resonance_bonuses.class.identifier : 0
            const classResonance = (rarity == 'mythic') ? equipData.resonance_bonuses.class.resonance : 0
            const themeIdentifier = (rarity == 'mythic') ? (equipData.resonance_bonuses.theme.identifier || 'multi') : 0
            const themeResonance = (rarity == 'mythic') ? equipData.resonance_bonuses.theme.resonance : 0

            const equipKey = (rarity != 'mythic') ? makeEquipKey(equipData, equipData.skin) : makeEquipKeyMythic(equipData, equipData.skin, classIdentifier, classResonance, themeIdentifier, themeResonance)

            const isFavorite = favorites.includes(equipKey)

            if (isFavorite) {
                $($el.parentNode).removeClass('not-selected');
                $($el.parentNode).addClass('protected');

                let $favoriteToggle = $($el).find('.favorite-toggle')
                if (!$favoriteToggle.length) {
                    $($el).append('<div class="favorite-toggle"></div>');
                }
            }
        }

        //CSS
        sheet.insertRule('.item-container.protected .slot .favorite-toggle {'
                         + 'position: absolute;'
                         + 'display: block;'
                         + 'height: 32px;'
                         + 'width: 32px;'
                         + 'top: 0px;'
                         + 'right: 0px;'
                         + 'background-image: url("' + window.IMAGES_URL + '/design/ic_star_orange.svg");'
                         + 'background-size: 22px;'
                         + 'background-repeat: no-repeat;'
                         + 'background-position: center;'
                         + 'background-color: rgba(30, 38, 30, 0.7);'
                         + 'z-index: 1;'
                         + 'border-top-right-radius: 5px;'
                         + 'border-bottom-left-radius: 5px;}'
                        );
    }

    protectFavoriteItems();
    const favouriteSafetyObserver = new MutationObserver(() => protectFavoriteItems());
    favouriteSafetyObserver.observe($('.mythic-equipment-panel .mythic-equipment-container .inventory-section .inventory-container .items-container')[0], {childList: true, subtree: true, attributes: true, attributeFilter: ['class']})
}


/* ===================
	HAREM INFORMATION
   =================== */

function moduleHarem() {
    const haremGirls = JSON.parse(localStorage.getItem('HHS.HHPNMap'));

    let stats = [];
    let haremRight = $('#harem_right');

    stats.girls = 0;
    stats.level_max = 0;
    stats.hourlyMoney = 0;
    stats.allCollect = 0;
    stats.unlockedScenes = 0;
    stats.allScenes = 0;
    stats.rarities = {starting: 0, common: 0, rare: 0, epic: 0, legendary: 0, mythic: 0};
    stats.elements = {darkness: 0, light: 0, psychic: 0, fire: 0, nature: 0, stone: 0, sun: 0, water: 0};
    stats.caracs = {1: 0, 2: 0, 3: 0};
    stats.stars = {affection: 0, money: 0, kobans: 0};
    stats.xp = 0;
    stats.LMxp = 0;
    stats.affection = 0;
    stats.money = 0;
    stats.kobans = 0;
    stats.grades = {starting: {3: 0, 5: 0}, common: {1: 0, 3: 0, 5: 0}, rare: {3: 0, 5: 0}, epic: {3: 0, 5: 0}, legendary: {3: 0, 5: 0}, mythic: {6: 0}};
    stats.gemsRequirements = {darkness: 0, light: 0, psychic: 0, fire: 0, nature: 0, stone: 0, sun: 0, water: 0};
    stats.awakeningStages = {250: 0, 300: 0, 350: 0, 400: 0, 450: 0, 500: 0, 550: 0, 600: 0, 650: 0, 700: 0}

    let EvoReq = [];

    let starting = [];
    starting.push({affection: 90, money: 36000, kobans: 36, taffection: 90, tmoney: 36000, tkobans: 36});
    starting.push({affection: 225, money: 90000, kobans: 60, taffection: 315, tmoney: 126000, tkobans: 96});
    starting.push({affection: 563, money: 225000, kobans: 114, taffection: 878, tmoney: 351000, tkobans: 210});
    starting.push({affection: 1125, money: 450000, kobans: 180, taffection: 2003, tmoney: 801000, tkobans: 390});
    starting.push({affection: 2250, money: 900000, kobans: 300, taffection: 4253, tmoney: 1701000, tkobans: 690});
    EvoReq.starting = starting;

    let commonGirls = [];
    commonGirls.push({affection: 180, money: 72000, kobans: 72, taffection: 180, tmoney: 72000, tkobans: 72});
    commonGirls.push({affection: 450, money: 180000, kobans: 120, taffection: 630, tmoney: 252000, tkobans: 192});
    commonGirls.push({affection: 1125, money: 450000, kobans: 228, taffection: 1755, tmoney: 702000, tkobans: 420});
    commonGirls.push({affection: 2250, money: 900000, kobans: 360, taffection: 4005, tmoney: 1602000, tkobans: 780});
    commonGirls.push({affection: 4500, money: 1800000, kobans: 600, taffection: 8505, tmoney: 3402000, tkobans: 1380});
    EvoReq.common = commonGirls;

    let rareGirls = [];
    rareGirls.push({affection: 540, money: 216000, kobans: 216, taffection: 540, tmoney: 216000, tkobans: 216});
    rareGirls.push({affection: 1350, money: 540000, kobans: 360, taffection: 1890, tmoney: 756000, tkobans: 576});
    rareGirls.push({affection: 3375, money: 1350000, kobans: 678, taffection: 5265, tmoney: 2106000, tkobans: 1254});
    rareGirls.push({affection: 6750, money: 2700000, kobans: 1080, taffection: 12015, tmoney: 4806000, tkobans: 2334});
    rareGirls.push({affection: 13500, money: 5400000, kobans: 1800, taffection: 25515, tmoney: 10206000, tkobans: 4134});
    EvoReq.rare = rareGirls;

    let epicGirls = [];
    epicGirls.push({affection: 1260, money: 504000, kobans: 504, taffection: 1260, tmoney: 504000, tkobans: 504});
    epicGirls.push({affection: 3150, money: 1260000, kobans: 840, taffection: 4410, tmoney: 1764000, tkobans: 1344});
    epicGirls.push({affection: 7875, money: 3150000, kobans: 1578, taffection: 12285, tmoney: 4914000, tkobans: 2922});
    epicGirls.push({affection: 15750, money: 6300000, kobans: 2520, taffection: 28035, tmoney: 11214000, tkobans: 5442});
    epicGirls.push({affection: 31500, money: 12600000, kobans: 4200, taffection: 59535, tmoney: 23814000, tkobans: 9642});
    EvoReq.epic = epicGirls;

    let legendGirls = [];
    legendGirls.push({affection: 1800, money: 720000, kobans: 720, taffection: 1800, tmoney: 720000, tkobans: 720});
    legendGirls.push({affection: 4500, money: 1800000, kobans: 1200, taffection: 6300, tmoney: 2520000, tkobans: 1920});
    legendGirls.push({affection: 11250, money: 4500000, kobans: 2250, taffection: 17550, tmoney: 7020000, tkobans: 4170});
    legendGirls.push({affection: 22500, money: 9000000, kobans: 3600, taffection: 40050, tmoney: 16020000, tkobans: 7770});
    legendGirls.push({affection: 45000, money: 18000000, kobans: 6000, taffection: 85050, tmoney: 34020000, tkobans: 13770});
    EvoReq.legendary = legendGirls;

    let mythicGirls = [];
    mythicGirls.push({affection: 4500, money: 1800000, kobans: 1800, taffection: 4500, tmoney: 1800000, tkobans: 1800});
    mythicGirls.push({affection: 11250, money: 4500000, kobans: 3000, taffection: 15750, tmoney: 6300000, tkobans: 4800});
    mythicGirls.push({affection: 28125, money: 11300000, kobans: 5628, taffection: 43875, tmoney: 17600000, tkobans: 10428});
    mythicGirls.push({affection: 56250 , money: 22500000, kobans: 9000, taffection: 100125, tmoney: 40100000, tkobans: 19428});
    mythicGirls.push({affection: 112500, money: 45000000, kobans: 15000, taffection: 212625, tmoney: 85100000, tkobans: 34428});
    mythicGirls.push({affection: 225000, money: 90000000, kobans: 18000, taffection: 437625, tmoney: 175100000, tkobans: 52428});
    EvoReq.mythic = mythicGirls;

    try {
        haremGirls.forEach((data) => {
            let girl = data[1];
    
                stats.allCollect += girl.salary;
                stats.rarities[girl.rarity]++;
                stats.elements[girl.element]++;
                stats.caracs[girl.class]++;
                stats.girls++;
                stats.level_max += (250 + girl.awakening_level * 50);
                stats.hourlyMoney += Math.round(girl.salary_per_hour);
                stats.unlockedScenes += girl.graded;
                stats.allScenes += parseInt(girl.nb_grades, 10);
                let nbgrades = parseInt(girl.nb_grades, 10);
                if (girl.graded != nbgrades) {
                    stats.affection += EvoReq[girl.rarity][nbgrades - 1].taffection - girl.Affection.cur;
                    let currentLevelMoney = 0,
                        currentLevelKobans = 0;
                    if (girl.graded != 0) {
                        currentLevelMoney = EvoReq[girl.rarity][girl.graded - 1].tmoney;
                        currentLevelKobans = EvoReq[girl.rarity][girl.graded - 1].tkobans;
                    }
                    stats.money += EvoReq[girl.rarity][nbgrades - 1].tmoney - currentLevelMoney;
                    if (window.hh_nutaku) {
                        stats.kobans += Math.ceil((EvoReq[girl.rarity][nbgrades - 1].tkobans - currentLevelKobans) / 6);
                    }
                    else {
                        stats.kobans += EvoReq[girl.rarity][nbgrades - 1].tkobans - currentLevelKobans;
                    }
                }
    
                let expToMax = (GIRLS_EXP_LEVELS[girl.rarity][(250 + girl.awakening_level * 50) - 2] - girl.Xp.cur);
                if (expToMax < 0) expToMax = 0;
                stats.xp += expToMax;
    
                if(nbgrades >= 5 && (girl.rarity == 'legendary' || girl.rarity == 'mythic')) {
                    let expToLvlMax = (GIRLS_EXP_LEVELS[girl.rarity][lvl_max_girl - 2] - girl.Xp.cur);
                    if (expToLvlMax < 0) expToLvlMax = 0;
                    stats.LMxp += expToLvlMax;
                }
    
                stats.grades[girl.rarity][girl.nb_grades]++;
    
                //Girls number per awakening stage
                let girlLevel = parseInt(girl.level, 10);
                for (let i = 0; i < AWAKENING_LEVELS.length; i++) {
                    if (girlLevel >= AWAKENING_LEVELS[i]) {
                        stats.awakeningStages[AWAKENING_LEVELS[i]]++;
                    }
                }
    
                //Gems needed only for 5* and mythic girls
                if (girl.awakening_level < (AWAKENING_GEMS_COST[girl.rarity].length-1) && nbgrades >= 5 && (girl.rarity == 'legendary' || girl.rarity == 'mythic')) {
                    for (let i = (girl.awakening_level+1); i < AWAKENING_GEMS_COST[girl.rarity].length; i++) {
                        stats.gemsRequirements[girl.element] += AWAKENING_GEMS_COST[girl.rarity][i];
                    }
                }
        })
    } catch(e) {console.log("Visit the team edition page to get harem girls data")}
    

    /*let awakening_lvl_max;
    for (let i=0; i < AWAKENING_LEVELS.length; i++) {
        if (stats.awakeningStages[AWAKENING_LEVELS[i]] >= AWAKENING_REQUIREMENT[i]) {
            awakening_lvl_max = AWAKENING_LEVELS[i];
        }
    }*/

    let MarketStocks;
    try {
        let lsMarket = JSON.parse(localStorage.getItem('HHS.lsMarket')),
            d = new Date(lsMarket.restock.time),
            RestockInfo;

        if (new Date() > lsMarket.restock.time || window.Hero.infos.level > lsMarket.restock.herolvl) {

            RestockInfo = '> The <a href="' + transformNutakuURL("../shop.html") + '">Market</a> restocked since your last visit.';
        }
        else {
            let	marketBookTxt = lsMarket.buyable.potion.Nb + ' ' + (lsMarket.buyable.potion.Nb > 1 ? labels.books : labels.book) + ' (' + nThousand(lsMarket.buyable.potion.Xp) + ' ' + labels.Xp + ')',
                marketGiftTxt = lsMarket.buyable.gift.Nb + ' ' + (lsMarket.buyable.gift.Nb > 1 ? labels.gifts : labels.gift) + ' (' + nThousand(lsMarket.buyable.gift.Xp) + ' ' + labels.affection + ')';
            RestockInfo = '- ' + marketBookTxt + ' = ' + nThousand(lsMarket.buyable.potion.ValueYmens) + ' <span class="imgMoney icon-small"></span> ' + labels.and + ' ' + nThousand(lsMarket.buyable.potion.ValueKobans) + ' <span class="imgKobans icon-small"></span>'
                + '<br />- ' + marketGiftTxt + ' = ' + nThousand(lsMarket.buyable.gift.ValueYmens) + ' <span class="imgMoney icon-small"></span> ' + labels.and + ' ' + nThousand(lsMarket.buyable.gift.ValueKobans) + ' <span class="imgKobans icon-small"></span>'
                + '<br /><font style="color: gray;">' + labels.restock + ': ' + d.toLocaleString() + ' (' + labels.or_level + ' ' + (window.Hero.infos.level+1) + ')</font>';
        }

        MarketStocks =
            '<ul class="grid-harem-infos market-stocks">' +
            '<li><span tooltip="' + labels.Equipments + '"><span class="equipments-icon icon-big"></span><span>' + nThousand(lsMarket.stocks.armor.Nb) + '</span></span></li>' +
            '<li><span tooltip="' + labels.Boosters + '"><span class="boosters-icon icon-big"></span><span>' + nThousand(lsMarket.stocks.booster.Nb) + '</span></span></li>' +
            '<li><span tooltip="' + labels.Books + '"><span class="books-icon icon-big"></span><span>' + nThousand(lsMarket.stocks.potion.Nb) + '<br />(' + nThousand(lsMarket.stocks.potion.Xp) + ' ' + window.GT.design.XP + ') </span></span></li>' +
            '<li><span tooltip="' + labels.Gifts + '"><span class="gifts-icon icon-big"></span><span>' + nThousand(lsMarket.stocks.gift.Nb) + '<br />(' + nThousand(lsMarket.stocks.gift.Xp) + ' ' + window.GT.design.Aff + ') </span></span></li></ul>'

            + '<span class="subTitle">' + labels.currently_buyable + ':</span>'
            + RestockInfo;
    } catch(e) {
        MarketStocks = (window.lsAvailable == 'yes') ? '> ' + labels.visit_the : '> ' + labels.not_compatible;
    }

    let StatsString = '<div class="StatsContent">' +
        '<div>' +
        '<span class="Title">' + labels.harem_stats + ':</span>' +
        '<span class="subTitle" style="margin-top: -10px;">' + nThousand(stats.girls) + ' ' + labels.haremettes + '</span>' +

        '<ul class="grid-harem-infos girls-class">' +
        '<li><span tooltip="' + window.GT.design.caracs.split('\n')[0] + '"><span carac="1"></span><span>' + stats.caracs[1] + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.caracs.split('\n')[1] + '"><span carac="2"></span><span>' + stats.caracs[2] + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.caracs.split('\n')[2] + '"><span carac="3"></span><span>' + stats.caracs[3] + '</span></span></li>' +
        '</ul>' +

        '<ul class="grid-harem-infos girls-rarities">' +
        '<ul class="grid-harem-infos girls-rarity">' +
        '<li class="common-rarity"><span class="rarity-tooltip" tooltip="' + window.GT.design.girls_rarity_common + '"><span class="initial">C</span><span>' + (stats.rarities.starting + stats.rarities.common) + '</span></span></li>' +
        '<li style="text-align: center;">' + labels.including + ': </li>' +
        '<li class="common-rarity"><span class="stars"><span class="initial">1<span class="imgStar icon-small"></span></span><span>' + stats.grades.common['1'] + '</span></span></li>' +
        '<li class="common-rarity"><span class="stars"><span class="initial">3<span class="imgStar icon-small"></span></span><span>' + stats.grades.common['3'] + '</span></span></li>' +
        '<li class="common-rarity"><span class="stars"><span class="initial">5<span class="imgStar icon-small"></span></span><span>' + stats.grades.common['5'] + '</span></span></li>' +
        '</ul>' +

        '<ul class="grid-harem-infos girls-rarity">' +
        '<li class="rare-rarity"><span class="rarity-tooltip" tooltip="' + window.GT.design.girls_rarity_rare + '"><span class="initial">R</span><span>' + stats.rarities.rare + '</span></span></li>' +
        '<li style="text-align: center;">' + labels.including + ': </li>' +
        '<li></li>' +
        '<li class="rare-rarity"><span class="stars"><span class="initial">3<span class="imgStar icon-small"></span></span><span>' + stats.grades.rare['3'] + '</span></span></li>' +
        '<li class="rare-rarity"><span class="stars"><span class="initial">5<span class="imgStar icon-small"></span></span><span>' + stats.grades.rare['5'] + '</span></span></li>' +
        '</ul>' +

        '<ul class="grid-harem-infos girls-rarity">' +
        '<li class="epic-rarity"><span class="rarity-tooltip" tooltip="' + window.GT.design.girls_rarity_epic + '"><span class="initial">E</span><span>' + stats.rarities.epic + '</span></span></li>' +
        '<li style="text-align: center;">' + labels.including + ': </li>' +
        '<li></li>' +
        '<li class="epic-rarity"><span class="stars"><span class="initial">3<span class="imgStar icon-small"></span></span><span>' + stats.grades.epic['3'] + '</span></span></li>' +
        '<li class="epic-rarity"><span class="stars"><span class="initial">5<span class="imgStar icon-small"></span></span><span>' + stats.grades.epic['5'] + '</span></span></li>' +
        '</ul>' +

        '<ul class="grid-harem-infos girls-rarity">' +
        '<li class="legendary-rarity"><span class="rarity-tooltip" tooltip="' + window.GT.design.girls_rarity_legendary + '"><span class="initial">L</span><span>' + stats.rarities.legendary + '</span></span></li>' +
        '<li style="text-align: center;">' + labels.including + ': </li>' +
        '<li></li>' +
        '<li class="legendary-rarity"><span class="stars"><span class="initial">3<span class="imgStar icon-small"></span></span><span>' + stats.grades.legendary['3'] + '</span></span></li>' +
        '<li class="legendary-rarity"><span class="stars"><span class="initial">5<span class="imgStar icon-small"></span></span><span>' + stats.grades.legendary['5'] + '</span></span></li>' +
        '</ul>' +

        '<ul class="grid-harem-infos girls-rarity">' +
        '<li class="mythic-rarity"><span class="rarity-tooltip" tooltip="' + window.GT.design.girls_rarity_mythic + '"><span class="initial">M</span><span>' + stats.rarities.mythic + '</span></span></li>' +
        '</ul>' +
        '</ul>' +

        '<ul class="grid-harem-infos girls-elements">' +
        '<li><span tooltip="' + window.GT.design.darkness_flavor_element + '"><span class="element darkness_elem icon"></span><span>' + stats.elements.darkness + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.light_flavor_element + '"><span class="element light_elem icon"></span><span>' + stats.elements.light + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.psychic_flavor_element + '"><span class="element psychic_elem icon"></span><span>' + stats.elements.psychic + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.fire_flavor_element + '"><span class="element fire_elem icon"></span><span>' + stats.elements.fire + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.nature_flavor_element + '"><span class="element nature_elem icon"></span><span>' + stats.elements.nature + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.stone_flavor_element + '"><span class="element stone_elem icon"></span><span>' + stats.elements.stone + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.sun_flavor_element + '"><span class="element sun_elem icon"></span><span>' + stats.elements.sun + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.water_flavor_element + '"><span class="element water_elem icon"></span><span>' + stats.elements.water + '</span></span></li>' +
        '</ul>' +

        '<ul class="grid-harem-infos girls-xp">' +
        '<li><span><span class="initial">' + window.GT.design.Lvl + '</span><span>' + nThousand(localeStringToNumber(document.getElementsByClassName('focus_text')[0].innerHTML)) + ' / ' + nThousand(stats.level_max) + ' <br />(' + nThousand(stats.level_max - localeStringToNumber(document.getElementsByClassName('focus_text')[0].innerHTML)) + ')</span></span></li>' +
        '<li><span tooltip="' + labels.required_to_get_tier_max_level + '"><span class="initial">' + window.GT.design.XP + '</span><span>' + nThousand(stats.xp) + ' ' + window.GT.design.XP + ' (' + nThousand(stats.xp * 200) + ' <span class="imgMoney icon-small"></span>)</span></span></li>' +
        '<li><span tooltip="' + labels.required_to_get_max_level + '"><span class="initial">' + window.GT.design.XP + '</span><span>' + nThousand(stats.LMxp) + ' ' + window.GT.design.XP + ' (' + nThousand(stats.LMxp * 200) + ' <span class="imgMoney icon-small"></span>)</span></span></li>' +
        '</ul>' +

        '<ul class="grid-harem-infos girls-aff">' +
        '<li><span><span class="imgStar icon"></span><span>' + stats.unlockedScenes + ' / ' + stats.allScenes + ' <br />(' + nThousand(stats.allScenes - stats.unlockedScenes) + ' <span class="emptyStar icon-small"></span>)</span></span></li>' +
        '<li><span tooltip="' + labels.required_to_unlock + '"><span class="initial">' + window.GT.design.Aff + '</span><span>' + addPriceRow2('', stats.affection, stats.money) + '</span></span></li>' +
        '</ul>' +

        '</div>' +

        '<div>' +

        '<span class="subTitle">' + window.GT.design.awakening + ':</span>' +
        '<ul class="grid-harem-infos girls-awakening">' +
        '<li><span><span class="awakening-lvl">' + window.GT.design.Lvl + ' ' + AWAKENING_LEVELS[0] + '</span><span>' + stats.awakeningStages[AWAKENING_LEVELS[0]] + ' / ' + AWAKENING_REQUIREMENT[0] + '</span></span></li>' +
        '<li><span><span class="awakening-lvl">' + window.GT.design.Lvl + ' ' + AWAKENING_LEVELS[1] + '</span><span>' + stats.awakeningStages[AWAKENING_LEVELS[1]] + ' / ' + AWAKENING_REQUIREMENT[1] + '</span></span></li>' +
        '<li><span><span class="awakening-lvl">' + window.GT.design.Lvl + ' ' + AWAKENING_LEVELS[2] + '</span><span>' + stats.awakeningStages[AWAKENING_LEVELS[2]] + ' / ' + AWAKENING_REQUIREMENT[2] + '</span></span></li>' +
        '<li><span><span class="awakening-lvl">' + window.GT.design.Lvl + ' ' + AWAKENING_LEVELS[3] + '</span><span>' + stats.awakeningStages[AWAKENING_LEVELS[3]] + ' / ' + AWAKENING_REQUIREMENT[3] + '</span></span></li>' +
        '<li><span><span class="awakening-lvl">' + window.GT.design.Lvl + ' ' + AWAKENING_LEVELS[4] + '</span><span>' + stats.awakeningStages[AWAKENING_LEVELS[4]] + ' / ' + AWAKENING_REQUIREMENT[4] + '</span></span></li>' +
        '<li><span><span class="awakening-lvl">' + window.GT.design.Lvl + ' ' + AWAKENING_LEVELS[5] + '</span><span>' + stats.awakeningStages[AWAKENING_LEVELS[5]] + ' / ' + AWAKENING_REQUIREMENT[5] + '</span></span></li>' +
        '<li><span><span class="awakening-lvl">' + window.GT.design.Lvl + ' ' + AWAKENING_LEVELS[6] + '</span><span>' + stats.awakeningStages[AWAKENING_LEVELS[6]] + ' / ' + AWAKENING_REQUIREMENT[6] + '</span></span></li>' +
        '<li><span><span class="awakening-lvl">' + window.GT.design.Lvl + ' ' + AWAKENING_LEVELS[7] + '</span><span>' + stats.awakeningStages[AWAKENING_LEVELS[7]] + ' / ' + AWAKENING_REQUIREMENT[7] + '</span></span></li>' +
        '<li><span><span class="awakening-lvl">' + window.GT.design.Lvl + ' ' + AWAKENING_LEVELS[8] + '</span><span>' + stats.awakeningStages[AWAKENING_LEVELS[8]] + ' / ' + AWAKENING_REQUIREMENT[8] + '</span></span></li>' +
        '<li><span><span class="awakening-lvl">' + window.GT.design.Lvl + ' ' + AWAKENING_LEVELS[9] + '</span><span>' + stats.awakeningStages[AWAKENING_LEVELS[9]] + ' / ' + AWAKENING_REQUIREMENT[9] + '</span></span></li>' +
        '</ul>' +

        '<span class="subTitle">' + window.GT.design.haremdex_income + ':</span>' +
        '<ul class="grid-harem-infos girls-income">' +
        '<li><span><span class="imgMoney icon"></span><span>' + nThousand(stats.hourlyMoney) + ' <span class="imgMoney icon-small"></span> /' + window.GT.time.h + '</span></span></li>' +
        '<li><span tooltip="' + labels.when_all_collectable + '"><span class="initial">' + window.GT.design.Max + '</span><span>' + nThousand(stats.allCollect) + ' <span class="imgMoney icon-small"></span></span></span></li>' +
        '</ul>' +

        '<span class="subTitle">' + labels.my_stocks + ':</span>' +
        '<ul class="grid-harem-infos gems-stock">' +
        '<li><span tooltip="' + window.GT.design.darkness_gem + '"><span class="gems darkness_gem icon"></span><span>' + nThousand(parseInt(window.player_gems_amount.darkness.amount)) + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.light_gem + '"><span class="gems light_gem icon"></span><span>' + nThousand(parseInt(window.player_gems_amount.light.amount)) + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.psychic_gem + '"><span class="gems psychic_gem icon"></span><span>' + nThousand(parseInt(window.player_gems_amount.psychic.amount)) + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.fire_gem + '"><span class="gems fire_gem icon"></span><span>' + nThousand(parseInt(window.player_gems_amount.fire.amount)) + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.nature_gem + '"><span class="gems nature_gem icon"></span><span>' + nThousand(parseInt(window.player_gems_amount.nature.amount)) + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.stone_gem + '"><span class="gems stone_gem icon"></span><span>' + nThousand(parseInt(window.player_gems_amount.stone.amount)) + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.sun_gem + '"><span class="gems sun_gem icon"></span><span>' + nThousand(parseInt(window.player_gems_amount.sun.amount)) + '</span></span></li>' +
        '<li><span tooltip="' + window.GT.design.water_gem + '"><span class="gems water_gem icon"></span><span>' + nThousand(parseInt(window.player_gems_amount.water.amount)) + '</span></span></li>' +
        '</ul>' +

        MarketStocks +
        '</div>' +
        '</div>';


    $('#harem_left').append('<div id="CustomBar">'
                            + '<img f="stats" src="https://i.postimg.cc/8cYj8QmP/icon-info.png">'
                            + '</div>');

    this.$overlayHarem = $('<div class="script-harem-info-overlay"></div>');
    $('body').append(this.$overlayHarem);

    this.$overlayHarem.click(() => {
        this.$containerHarem.removeClass('shown');
        this.$overlayHarem.removeClass('shown');
    });

    $('#CustomBar').click(() => {
        if (!this.$containerHarem) {
            this.$containerHarem = $('<div class="script-harem-info-container fixed_scaled"></div>');
            this.$containerHarem.append('<div id="TabsContainer">' + StatsString + '</div>');
            $('body').append(this.$containerHarem);
        }
        this.$containerHarem.addClass('shown');
        this.$overlayHarem.addClass('shown');
    });

    function addPriceRow2(rowName, affection, money) {
        return '<b>' + rowName + '</b> ' +
            nThousand(affection) + ' ' + window.GT.design.Aff + ' (' + nThousand(affection * 417) + ' <span class="imgMoney icon-small"></span>)<br />' +
            labels.and + ' ' + nThousand(money) + ' <span class="imgMoney icon-small"></span>';
    }

    function addPriceRowGirl(rowName, affection, money, kobans) {
        return '<b>' + rowName + ':</b> ' +
            nThousand(affection) + ' ' + labels.affection + (affection > 1 && lang == 'fr' ? 's' : '') + ' (' + nThousand(affection * 417) + ' <span class="imgMoney"></span>) ' + labels.and + ' ' +
            nThousand(money) + ' <span class="imgMoney"></span> ' + labels.or + ' ' +
            nThousand(kobans) + ' <span class="imgKobans"></span><br />';
    }

    $('.girls_list').click(function() {
        setTimeout(() => {updateInfo()}, 3*timeout);
    });

    $('#filtering_girls').click(function() {
        setTimeout(() => {updateInfo()}, 5*timeout);
    });

    setTimeout(() => {updateInfo()}, 5*timeout);

    function updateInfo() {
        haremRight.children('[girl]').each(function() {
            let girlID = $(this).attr('girl');
            let girl = window.girlsDataList[girlID];
            //for Wiki FR
            let girlName = girl.name.replaceAll("’", "-").replaceAll("/", "-");

            if (window.HH_UNIVERSE != 'comix_c' && window.HH_UNIVERSE != 'nutaku_c' && window.HH_UNIVERSE != 'star_t' && window.HH_UNIVERSE != 'nutaku_t' && window.HH_UNIVERSE != "dotcom_startrans" && window.HH_UNIVERSE != 'nutaku_startrans' && window.HH_UNIVERSE != "dotcom_stargay" && window.HH_UNIVERSE != "nutaku_stargay") {
                if ($(this).find('.middle_part .WikiLink h3').length == 0) {
                    if (!(girl.shards == 100)) {
                        if (window.HH_UNIVERSE == 'gay' || window.HH_UNIVERSE == 'gh_nutaku' || window.HH_UNIVERSE == 'gh_eroges') {
                            $(this).find('.middle_part.missing_girl .dialog-box').after('<div class="WikiLinkDialogbox"><a href="https://harem-battle.club/wiki/Gay-Harem/GH:' + girlName + '" target="_blank"> ' + girl.name + labels.wiki + ' </a></div>');
                        }
                        else if (lang == 'en') {
                            $(this).find('.middle_part.missing_girl .dialog-box').after('<div class="WikiLinkDialogbox"><a href="https://harem-battle.club/wiki/Harem-Heroes/HH:' + girlName + '" target="_blank"> ' + girl.name + labels.wiki + ' </a></div>');
                        }
                        else {
                            $(this).find('.middle_part.missing_girl .dialog-box').after('<div class="WikiLinkDialogbox"><a href="http://hentaiheroes.go.yj.fr/?id=' + girlID + '" target="_blank"> ' + labels.wiki + girl.name + ' </a></div>');
                        }
                    }
                    if ((girl.shards == 100) && ($('#harem_right .WikiLink').length == 0)) {
                        if (window.HH_UNIVERSE == 'gay' || window.HH_UNIVERSE == 'gh_nutaku' || window.HH_UNIVERSE == 'gh_eroges') {
                            $(this).find('.middle_part h3').after('<div class="WikiLink"><a href="https://harem-battle.club/wiki/Gay-Harem/GH:' + girlName + '" target="_blank"> ' + girl.name + labels.wiki + ' </a></div>');
                        }
                        else if (lang == 'en') {
                            $(this).find('.middle_part h3').after('<div class="WikiLink"><a href="https://harem-battle.club/wiki/Harem-Heroes/HH:' + girlName + '" target="_blank"> ' + girl.name + labels.wiki + ' </a></div>');
                        }
                        else {
                            $(this).find('.middle_part h3').after('<div class="WikiLink"><a href="http://hentaiheroes.go.yj.fr/?id=' + girlID + '" target="_blank"> ' + labels.wiki + girl.name + ' </a></div>');
                        }
                    }
                }
                else {
                    let newHref = '';
                    if (window.HH_UNIVERSE == 'gay' || window.HH_UNIVERSE == 'gh_nutaku' || window.HH_UNIVERSE == 'gh_eroges') {
                        newHref = 'https://harem-battle.club/wiki/Gay-Harem/GH:' + girlName;
                    }
                    else if (lang == 'fr') {
                        newHref = 'http://hentaiheroes.go.yj.fr/?id=' + girlID;
                    }
                    else {
                        newHref = 'https://harem-battle.club/wiki/Harem-Heroes/HH:' + girlName;
                    }
                    $(this).find('.middle_part .WikiLink a').attr('href', newHref);
                }
            }
            let i = 0,
                FirstLockedScene = 1,
                AffectionTT = labels.evolution_costs + ':<br />',
                ScenesLink = '',
                girl_quests = $(this).find('.girl_quests');

            girl_quests.find('g').each(function() {
                i++;
                let aff = 0,
                    money = 0,
                    kobans = 0;
                let currentLevelMoney = 0,
                    currentLevelKobans = 0;
                if (girl.graded != 0) {
                    currentLevelMoney = EvoReq[girl.rarity][girl.graded - 1].tmoney;
                    currentLevelKobans = EvoReq[girl.rarity][girl.graded - 1].tkobans;
                }
                if (girl.graded >= i) {
                }
                else if ((girl.graded + 1) == i && girl.Affection.level == i) {
                    money = EvoReq[girl.rarity][i - 1].tmoney - currentLevelMoney;
                    if (window.hh_nutaku) {
                        kobans = Math.ceil((EvoReq[girl.rarity][i - 1].tkobans - currentLevelKobans) / 6);
                    }
                    else {
                        kobans = EvoReq[girl.rarity][i - 1].tkobans - currentLevelKobans;
                    }
                }
                else {
                    aff = EvoReq[girl.rarity][i - 1].taffection - girl.Affection.cur;
                    money = EvoReq[girl.rarity][i - 1].tmoney - currentLevelMoney;
                    if (window.hh_nutaku) {
                        kobans = Math.ceil((EvoReq[girl.rarity][i - 1].tkobans - currentLevelKobans) / 6);
                    }
                    else {
                        kobans = EvoReq[girl.rarity][i - 1].tkobans - currentLevelKobans;
                    }
                }
                AffectionTT += addPriceRowGirl(i + '</b><span class="imgStar"></span>', aff, money, kobans);
                ScenesLink += (ScenesLink == '') ? 'hh_scenes=' : ',';
                if ($(this).hasClass('grey') || $(this).hasClass('green')) {
                    if (FirstLockedScene == 0) {
                        ScenesLink += '0';
                    }
                    else {
                        FirstLockedScene = 0;
                        let isUpgradable = girl_quests.parent().children('.green_text_button');
                        ScenesLink += (isUpgradable.length) ? '0.' + isUpgradable.attr('href').substr(7) : '0';
                    }
                }
                else {
                    let attrHref = $(this).parent().attr('href');
                    if (typeof attrHref != 'undefined') {
                        ScenesLink += attrHref.substr(7);
                    }
                }
            });

            girl_quests.children('a').each(function() {
                let attr = $(this).attr('href');
                if (typeof attr !== typeof undefined && attr !== false) {
                    $(this).attr('href', attr + '?' + ScenesLink);
                }
            });
            ScenesLink = '';

            girl_quests.parent().children('h4').prepend('<span class="CustomTT"></span><div class="AffectionTooltip">' + AffectionTT + '</div>');

        });
    }

    moduleGemStock();

    function moduleGemStock() {
        const elements = Object.keys(ELEMENTS_ICON_NAMES)

        const displayGemStock = () => {
            const $gemStock = $('<div class="gemStock" tooltip=""></div>')
            const stockTable = '<div style="max-width: 290px;">' + labels.Gems_in_stock + '<BR>(' + labels.missing_gems + ')</div>'
            + '<table class="gemStockTable" style="justify-content: center; display: flex;"><tbody>'
            + `${elements.map(element => `
                                      <tr>
                                      <td><img src="${window.IMAGES_URL}/pictures/design/gems/${element}.png"></td>
                                      <td>${nThousand(+window.player_gems_amount[element].amount)} (${nThousand(stats.gemsRequirements[element]-(+window.player_gems_amount[element].amount))})</td>
                                      </tr>`).join('')}`
            + '</tody></table>'.replace(/(\n| {4})/g, '');
            $gemStock.attr('tooltip', stockTable);
            $('.haremdex-wrapper').append($gemStock);
        }

        const injectCSS = () => {
            sheet.insertRule('.gemStock {'
                             + 'display: block !important;'
                             + 'position: absolute !important;'
                             + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/all.png");'
                             + 'background-size: contain;'
                             + 'height: 30px !important;'
                             + 'width: 30px !important;'
                             + 'z-index: 30 !important;}'
                            );

            sheet.insertRule(`${mediaDesktop} {`
                             + '.gemStock {'
                             + 'right: 293px;'
                             + 'top: 18px;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '.gemStock {'
                             + 'left: 665px;'
                             + 'top: 22px;}}'
                            );

            sheet.insertRule('.gemStockTable img {'
                             + 'height: 25px;'
                             + 'width: 25px;}'
                            );
        }

        injectCSS();
        displayGemStock();
    }

    //CSS
    sheet.insertRule('.script-harem-info-overlay {'
                     + 'display: none;'
                     + 'background-color: #0808087a;'
                     + 'position: absolute;'
                     + 'top: 0;'
                     + 'left: 0;'
                     + 'width: 100%;'
                     + 'height: 100%;'
                     + 'z-index: 9;}'
                    );

    sheet.insertRule('.script-harem-info-overlay.shown {'
                     + 'display: block;}'
                    );

    sheet.insertRule('.script-harem-info-container {'
                     + 'display: none;'
                     + 'align-items: center;'
                     + 'justify-content: center;'
                     + 'color: #fff;'
                     + 'width: 1040px;'
                     + 'height: 585px;'
                     + 'z-index: 10;'
                     + 'font-size: 16px;'
                     + 'pointer-events: none;}'
                    );

    sheet.insertRule('.script-harem-info-container.shown {'
                     + 'display: flex;}'
                    );

    sheet.insertRule('#TabsContainer {'
                     + 'z-index: 99;'
                     + 'position: absolute;'
                     + 'left: 9px;'
                     + 'top: 85px;'
                     + 'width: 1016px;'
                     + 'border: 1px solid rgb(156, 182, 213);'
                     + 'box-shadow: 1px -1px 1px 0px rgba(0,0,0,0.3);'
                     + 'font: normal 12px/16px Tahoma, Helvetica, Arial, sans-serif;'
                     + 'color: lightgray; '
                     + 'background-color: rgba(8, 8, 8);'
                     + 'pointer-events: all;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#TabsContainer {'
                     + 'top: 60px !important;'
                     + 'font-size: 14px !important;'
                     + 'line-height: 22px !important;'
                     + 'font-weight: bold !important;}}'
                    );

    sheet.insertRule('.StatsContent {'
                     + 'display: grid;'
                     + 'gap: 20px;'
                     + 'grid-template-columns: 0.8fr 1fr;}'
                    );

    sheet.insertRule('#TabsContainer .initial {'
                     + 'font-weight: bold;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#TabsContainer .icon {'
                     + 'display: inline-block;'
                     + 'width: 20px;'
                     + 'height: 20px;'
                     + 'background-size: 20px;'
                     + 'background-repeat: no-repeat;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#TabsContainer .icon {'
                     + 'display: inline-block;'
                     + 'width: 24px;'
                     + 'height: 24px;'
                     + 'background-size: 24px;'
                     + 'background-repeat: no-repeat;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#TabsContainer .icon-small {'
                     + 'display: inline-block;'
                     + 'width: 14px;'
                     + 'height: 14px;'
                     + 'background-size:14px;'
                     + 'background-repeat: no-repeat;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#TabsContainer .icon-small {'
                     + 'display: inline-block;'
                     + 'width: 18px;'
                     + 'height: 18px;'
                     + 'background-size:18px;'
                     + 'background-repeat: no-repeat;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#TabsContainer .icon-big {'
                     + 'display: inline-block;'
                     + 'width: 30px;'
                     + 'height: 30px;'
                     + 'background-size: 30px;'
                     + 'background-repeat: no-repeat;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#TabsContainer .icon-big {'
                     + 'display: inline-block;'
                     + 'width: 40px;'
                     + 'height: 40px;'
                     + 'background-size: 40px;'
                     + 'background-repeat: no-repeat;}}'
                    );

    sheet.insertRule('#TabsContainer .imgMoney {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/ic_topbar_soft_currency.png");}'
                    );

    sheet.insertRule('#TabsContainer .imgKobans {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/ic_topbar_hard_currency.png");}'
                    );

    sheet.insertRule('#TabsContainer > div {'
                     + 'padding: 1px 10px 8px 10px;}'
                    );

    sheet.insertRule('#TabsContainer .Title {'
                     + 'margin-left: -5px;'
                     + 'font: bold 16px/22px Tahoma, Helvetica, Arial, sans-serif;'
                     + 'text-decoration: underline;'
                     + 'color: #B14;}'
                    );

    sheet.insertRule('#TabsContainer .subTitle {'
                     + 'padding-top: 6px;'
                     + 'font: bold 14px/22px Tahoma, Helvetica, Arial, sans-serif;'
                     + 'text-decoration: underline;'
                     + 'display: block;}'
                    );

    sheet.insertRule('.grid-harem-infos {'
                     + 'display: grid;'
                     + 'list-style: none;'
                     + 'grid-gap: 6px;'
                     + 'padding-left: 0px;'
                     + 'break-inside: avoid-column;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.grid-harem-infos {'
                     + 'row-gap: 12px !important;}}'
                    );

    sheet.insertRule('.grid-harem-infos li {'
                     + 'display: inline-grid;'
                     + 'min-height: 20px;'
                     + 'border-radius: 5px;'
                     + 'padding-right: 7px;'
                     + 'margin-left: 10px;}'
                    );

    sheet.insertRule('.grid-harem-infos li>span {'
                     + 'display: flex;'
                     + 'justify-content:'
                     + 'space-between;'
                     + 'text-align: center;'
                     + 'align-items: center;}'
                    );

    sheet.insertRule('.girls-class {'
                     + 'grid-template-columns: 1fr 1fr 1fr;}'
                    );

    sheet.insertRule('.girls-class li, .girls-elements li, .girls-xp li, .girls-aff li, .girls-awakening li, .girls-income li, .gems-stock li, .market-stocks li {'
                     + 'background: #cccccc42;}'
                    );

    sheet.insertRule('.girls-class li>span, .girls-elements li>span, .girls-xp li>span, .girls-aff li>span, .girls-awakening .awakening-lvl, .girls-income li>span, .gems-stock li>span, .market-stocks li>span  {'
                     + 'margin-left: -10px;}'
                    );

    sheet.insertRule('.girls-class span[carac]::before {'
                     + 'width: 20px !important;'
                     + 'height: 20px !important;}'
                    );

    sheet.insertRule('.girls-rarity {'
                     + 'align-items: center;'
                     + 'grid-template-columns: 1fr 0.6fr 1fr 1fr 1fr;}'
                    );

    sheet.insertRule('.imgStar {'
                     + 'background-image: url("' + window.IMAGES_URL + '/design_v2/affstar_S.png");}'
                    );

    sheet.insertRule('.girls-rarity li span.stars {'
                     + 'margin-left: -9px;}'
                    );

    sheet.insertRule('.girls-rarity li span.rarity-tooltip {'
                     + 'display: flex;'
                     + 'justify-content: space-between;'
                     + 'align-items: center;'
                     + 'margin-left: 5px;}'
                    );

    sheet.insertRule('.common-rarity {'
                     + 'background: #8d8e9f;}'
                    );

    sheet.insertRule('.rare-rarity {'
                     + 'background: #23b56b;}'
                    );

    sheet.insertRule('.epic-rarity {'
                     + 'background: darkgoldenrod;}'
                    );

    sheet.insertRule('.legendary-rarity {'
                     + 'background-image: url("' + window.IMAGES_URL + '/legendary.png");}'
                    );

    sheet.insertRule('.mythic-rarity {'
                     + 'background: transparent radial-gradient(closest-side at 50% 50%,#f5a866 0,#ec0039 51%,#9e0e27 100%) 0 0 no-repeat padding-box;}'
                    );

    sheet.insertRule('.girls-elements {'
                     + 'margin-block-start: 26px;'
                     + 'grid-template-columns: 1fr 1fr 1fr 1fr;}'
                    );

    sheet.insertRule('.girls-xp {'
                     + 'margin-block-start: 25px;'
                     + 'grid-template-columns: 1fr 1fr 1fr;}'
                    );

    sheet.insertRule('.girls-aff {'
                     + 'grid-template-columns: 1fr 2fr;}'
                    );

    sheet.insertRule('.girls-aff .emptyStar {'
                     + 'display: inline-block;'
                     + 'width: 16px;'
                     + 'height: 16px;'
                     + 'background-size: 16px;'
                     + 'background-repeat: no-repeat;'
                     + 'background-image: url("' + window.IMAGES_URL + '/design_v2/affstar_empty.png");}'
                    );

    sheet.insertRule('.girls-awakening {'
                     + 'grid-template-columns: 1fr 1fr 1fr 1fr 1fr;}'
                    );

    sheet.insertRule('.girls-awakening .awakening-lvl {'
                     + 'width: 30px;}'
                    );

    sheet.insertRule('.girls-income {'
                     + 'grid-template-columns: 0.33fr 0.33fr;}'
                    );

    sheet.insertRule('.gems-stock {'
                     + 'grid-template-columns: 1fr 1fr 1fr 1fr;}'
                    );

    sheet.insertRule('.market-stocks {'
                     + 'grid-template-columns: 0.7fr 0.7fr 1fr 1fr;}'
                    );

    sheet.insertRule('#TabsContainer .darkness_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/darkness.png");}'
                    );

    sheet.insertRule('#TabsContainer .light_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/light.png");}'
                    );

    sheet.insertRule('#TabsContainer .psychic_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/psychic.png");}'
                    );

    sheet.insertRule('#TabsContainer .fire_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/fire.png");}'
                    );

    sheet.insertRule('#TabsContainer .nature_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/nature.png");}'
                    );

    sheet.insertRule('#TabsContainer .stone_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/stone.png");}'
                    );

    sheet.insertRule('#TabsContainer .sun_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/sun.png");}'
                    );

    sheet.insertRule('#TabsContainer .water_gem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/water.png");}'
                    );

    sheet.insertRule('#TabsContainer .darkness_elem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/girls_elements/Dominatrix.png");}'
                    );

    sheet.insertRule('#TabsContainer .light_elem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/girls_elements/Submissive.png");}'
                    );

    sheet.insertRule('#TabsContainer .psychic_elem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/girls_elements/Voyeurs.png");}'
                    );

    sheet.insertRule('#TabsContainer .fire_elem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/girls_elements/Eccentric.png");}'
                    );

    sheet.insertRule('#TabsContainer .nature_elem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/girls_elements/Exhibitionist.png");}'
                    );

    sheet.insertRule('#TabsContainer .stone_elem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/girls_elements/Physical.png");}'
                    );

    sheet.insertRule('#TabsContainer .sun_elem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/girls_elements/Playful.png");}'
                    );

    sheet.insertRule('#TabsContainer .water_elem {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/girls_elements/Sensual.png");}'
                    );

    sheet.insertRule('#TabsContainer .equipments-icon {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/pachinko/ic_equipment.png");}'
                    );

    sheet.insertRule('#TabsContainer .boosters-icon {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/pachinko/ic_booster.png");}'
                    );

    sheet.insertRule('#TabsContainer .books-icon {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/pachinko/ic_book.png");}'
                    );

    sheet.insertRule('#TabsContainer .gifts-icon {'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/pachinko/ic_gift.png");}'
                    );

    sheet.insertRule('#harem_left .HaremetteNb {'
                     + 'float: right; '
                     + 'line-height: 14px; '
                     + 'font-size: 12px;}'
                    );

    sheet.insertRule('#CustomBar {'
                     + 'z-index: 99;'
                     + 'width: 35px;'
                     + 'padding: 3px 10px 0 3px;'
                     + 'font: bold 10px Tahoma, Helvetica, Arial, sans-serif;'
                     + 'position: absolute;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#CustomBar {'
                     + 'left: 90px;'
                     + 'top: 50px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#CustomBar {'
                     + 'left: 60px;'
                     + 'top: 40px;}}'
                    );

    sheet.insertRule('#CustomBar img {'
                     + 'width: 20px; '
                     + 'height: 20px; '
                     + 'margin-right: 3px; '
                     + 'margin-bottom: 3px; '
                     + 'opacity: 0.5;}'
                    );

    sheet.insertRule('#CustomBar img:hover {'
                     + 'opacity: 1; '
                     + 'cursor: pointer;}'
                    );

    sheet.insertRule('#CustomBar .TopBottomLinks {'
                     + 'float: right; '
                     + 'margin-top: 2px;}'
                    );

    sheet.insertRule('#CustomBar a {'
                     + 'color: #008;'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('#TabsContainer a {'
                     + 'color: lightcoral;'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('#harem_whole .WikiLink a {'
                     + 'color: #87CEFA;'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('#CustomBar a:hover, #TabsContainer a:hover, #harem_right .WikiLink a:hover {'
                     + 'color: #B14;'
                     + 'text-decoration: underline;}'
                    );

    sheet.insertRule('#harem_whole .CustomTT {'
                     + 'float: right; '
                     + 'margin-left: -25px; '
                     + 'margin-top: -5px; '
                     + 'background-image: url("https://i.postimg.cc/qBDt6yHV/icon-question.png"); '
                     + 'background-size: 18px 18px; '
                     + 'width: 18px; '
                     + 'height: 18px; '
                     + 'visibility: none;}'
                    );

    sheet.insertRule('#harem_whole .CustomTT:hover {'
                     + 'cursor: help;}'
                    );

    sheet.insertRule('#harem_whole .CustomTT:hover + div {'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#harem_whole .AffectionTooltip {'
                     + 'position: absolute; '
                     + 'z-index: 99; '
                     + 'margin: 20px 0 0 0; '
                     + 'display: block; overflow: auto; '
                     + 'border: 1px solid rgb(162, 195, 215); '
                     + 'border-radius: 8px; '
                     + 'box-shadow: 0px 0px 4px 0px rgba(0,0,0,0.1); '
                     + 'padding: 3px 7px 4px 7px; '
                     + 'background-color: #F2F2F2; '
                     + 'color: #1E90FF; '
                     + 'font: normal 9px/17px Tahoma, Helvetica, Arial, sans-serif; '
                     + 'text-align: left; '
                     + 'text-shadow: none; '
                     + 'opacity: 0; '
                     + 'visibility: hidden; '
                     + 'transition: opacity 400ms, visibility 400ms;}'
                    );

    sheet.insertRule('#harem_whole .AffectionTooltip b {'
                     + 'font-weight: bold;}'
                    );

    sheet.insertRule('#harem_whole .WikiLink {'
                     + 'font-size: 12px;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#harem_whole .WikiLink {'
                     + 'z-index:99;'
                     + 'position: relative;'
                     + 'top: 15px;}}'
                    );

    sheet.insertRule('#harem_whole .WikiLinkDialogbox a {'
                     + 'font-size: 14px;'
                     + 'position: absolute;'
                     + 'margin-top: 100px;'
                     + 'margin-left: -117px;'
                     + 'width: 235px;'
                     + 'text-decoration: none; '
                     + 'color: #24a0ff !important;}'
                    );

    sheet.insertRule('#harem_whole .WikiLinkDialogbox a:hover {'
                     + 'text-decoration: underline;}'
                    );
}


/* ===============
	HAREM FILTER
   =============== */

function moduleHaremFilter() {
    createAndAttach();

    function createAndAttach() {
        const $teamsButton = createTeamsButton();
        $('#filtering_girls .reset-filters-container').prepend($teamsButton);

        const $teamsBox = createTeamsBox();
        $('#harem_whole').append($teamsBox);

        const bdsmTeams = JSON.parse(localStorage.getItem('HHS.TeamsDictionary'))

        $teamsButton.click(()=>$teamsBox.find('.team-selection').toggle())
        $teamsBox.find('.team-slot-container').click(function () {
            $teamsBox.find('.team-selection').css('display', 'none');
        })
        $teamsBox.find('.close-team-selection').click(() => $teamsBox.find('.team-selection').css('display', 'none'))

        if (bdsmTeams) {
            const {teamsDict} = bdsmTeams;
            Array.from($('.team-slot-container')).forEach((team) => {
                team.addEventListener('click', () => {
                    const girlDictionary = (!localStorage.getItem('HHS.HHPNMap')) ? new Map(): new Map(JSON.parse(localStorage.getItem('HHS.HHPNMap')));
                    let avatarList = [];
            
                    let girlsTeam = teamsDict[$(team).attr('data-id-team')].girls;
                    localStorage.setItem('HHS.filteredGirlsList', JSON.stringify(girlsTeam));
            
                    girlsTeam.forEach((girlId) => {
                        let avatar = 0;
                        if (girlDictionary.get(girlId)) avatar = girlDictionary.get(girlId).avatar;
                        avatarList.push(window.IMAGES_URL + "/pictures/girls/" + girlId + "/ava" + avatar  + "-1200x.webp")
                    })
                    localStorage.setItem('HHS.filteredAvatarList', JSON.stringify(avatarList));
                })
            })
        }
        
    }

    function createTeamsButton() {
        return $(`<button id="teams-filter" class="blue_button_L">${labels.teams}</button>`);
    }

    function createTeamsBox() {
        const bdsmTeams = JSON.parse(localStorage.getItem('HHS.TeamsDictionary'))
        if (!bdsmTeams) {
            return $(`
        <div style="position:relative">
            <div class="team-selection" style="display: none;">
                <span class="close-team-selection"></span>
                ${labels.visit_teams}
            </div>
        </div>`)
        }
        const {teamIds, teamsDict} = bdsmTeams
        return $(`
        <div style="position:relative">
            <div class="team-selection" style="display: none;">
                <span class="close-team-selection"></span>
                <div class="teams-grid-container rarity-background">
                    ${teamIds.map(teamId => teamsDict[teamId]).map(team => `
                        <a class="team-slot-container ${team.iconRarity}" data-id-team="${team.teamId}" data-girl-ids='${JSON.stringify(team.girls)}' href="${transformNutakuURL(`/girl/${team.girls[0]}`)}">
                            <img src="${window.IMAGES_URL}/pictures/girls/${team.iconId}/ico${team.iconLevel}.png" />
                            ${team.themeElements ? `
                                <div class="theme-icons">
                                    ${team.themeElements.map(element=>`<img class="theme-icon" src="${window.IMAGES_URL}/pictures/girls_elements/${element}.png"/>`).join('')}
                                </div>
                            ` : ''}
                        </a>
                    `).join('')}
                </div>
            </div>
        </div>
        `)
    }

    //CSS
    sheet.insertRule('#filtering_girls > .form-wrapper .reset-filters-container {'
                     + 'justify-content: space-around;}'
                    );

    sheet.insertRule('.team-selection {'
                     + 'position: absolute;'
                     + 'left: 46px;'
                     + 'top: 50px;'
                     + 'width: 400px;'
                     + 'height: fit-content;'
                     + 'border-radius: 8px 10px 10px 8px;'
                     + 'background-color: #1e261e;'
                     + 'box-shadow: rgba(255, 255, 255, 0.73) 0px 0px;'
                     + 'padding: 5px;'
                     + 'border: 1px solid #ffa23e;'
                     + 'z-index: 10;'
                     + 'padding-bottom: 16px;}'
                    );

    sheet.insertRule(`.teams-grid-container {
                     display: grid;
                     grid-template-columns: auto auto auto auto;
                     grid-row-gap: 1rem;
                     padding: 0.4rem 0.9rem 0.4rem 0.9rem;
                     margin-right: -1rem;
                    & .team-slot-container > img {
                     border-radius: 0.4rem;}}`
                    );

    sheet.insertRule('.teams-grid-container {'
                     + 'display: grid;'
                     + 'grid-template-columns: auto auto auto auto;'
                     + 'grid-row-gap: 1rem;'
                     + 'padding: 0.4rem 0.9rem 0.4rem 0.9rem;'
                     + 'margin-right: -1rem;}'
                    );

    sheet.insertRule('.teams-grid-container .team-slot-container > img {'
                     + 'border-radius: 0.4rem;}'
                    );

    sheet.insertRule('.close-team-selection, .close-filter {'
                     + 'position: absolute;'
                     + 'display: block;'
                     + 'background-size: cover;'
                     + 'background-image: url("' + window.IMAGES_URL + '/clubs/ic_xCross.png");'
                     + 'height: 32px;'
                     + 'width: 35px;'
                     + 'top: -16px;'
                     + 'right: -17px;'
                     + 'cursor: pointer;}'
                    );

    sheet.insertRule('[rel="select-team"] {'
                     + 'width: 100%;'
                     + 'height: 36px;'
                     + 'padding-top: 5px;}'
                    );

    sheet.insertRule('.theme-icons {'
                     + 'position: absolute;'
                     + 'bottom: -10px;}'
                    );

    sheet.insertRule('.theme-icon {'
                     + 'width: 26px;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#filtering_girls .form-wrapper .form-control .checkbox-group {'
                     + 'margin: 1px 0 5px 0 !important;}}'
                    );

    sheet.insertRule('#filtering_girls > .form-wrapper .reset-filters-container {'
                     + 'z-index: 10;'
                     + 'height: max-content;}'
                    );
}

//Add previous/next arrows on girl screen to navigate easily between the harem filtered girls
function haremGetFilteredGirls() {
    setTimeout(function() {
        let filteredGirlsList = [];
        let filteredAvatarList = [];
        let girlsDictionary = [];

        if (!$('#harem_left .harem-top-controls .nb_girls').length)
            $('#harem_left .harem-top-controls').after('<div class="nb_girls">' + window.GT.design.Girls + ' : '
                                                         + '<span id="girls_nb" style="color: #fff">' + nThousand(Object.keys(window.girlsDataList).length) + '</span></div>');
        
        if (Object.keys(window.girlsDataList).length > 0) {
            girlsDictionary = Object.keys(girlsDataList).map(function(cle) {return girlsDataList[cle];})
            girlsDictionary.forEach((girl) => {if (girl.shards >= 100) {
                filteredGirlsList.push(girl.id_girl);
                filteredAvatarList.push(window.IMAGES_URL + "/pictures/girls/" + girl.id_girl + "/ava" + girlsDataList[girl.id_girl].ico.charAt(girlsDataList[girl.id_girl].ico.indexOf("ico")+3)  + "-1200x.webp");
            }});
        }
        localStorage.setItem('HHS.filteredGirlsList', JSON.stringify(filteredGirlsList));
        localStorage.setItem('HHS.filteredAvatarList', JSON.stringify(filteredAvatarList));

        new MutationObserver(() => {
            let filteredGirlsList = [];
            let filteredAvatarList = [];
            let girlsDictionary = [];
            $('#girls_nb')[0].textContent = nThousand($('#harem_left .girls_list .harem-girl').length);
            if ($('#harem_left .girls_list .harem-girl').length > 0) {
                for (let i = 0; i < $('#harem_left .girls_list .harem-girl').length; i++) {
                    let girl_id = parseInt($($('#harem_left .girls_list .harem-girl')[i]).attr('girl'), 10)
                    girlsDictionary.push(girlsDataList[girl_id]);
                }
                girlsDictionary.forEach((girl) => {if (girl.shards >= 100) {
                    filteredGirlsList.push(girl.id_girl);
                    filteredAvatarList.push(window.IMAGES_URL + "/pictures/girls/" + girl.id_girl + "/ava" + girlsDataList[girl.id_girl].ico.charAt(girlsDataList[girl.id_girl].ico.indexOf("ico")+3)  + "-1200x.webp");
                }});
            }
            localStorage.setItem('HHS.filteredGirlsList', JSON.stringify(filteredGirlsList));
            localStorage.setItem('HHS.filteredAvatarList', JSON.stringify(filteredAvatarList));
        }).observe($('#harem_left .girls_list')[0], {childList: true})

        //CSS
        sheet.insertRule(`${mediaDesktop} {`
                         + '#harem_left .nb_girls {'
                         + 'font-weight: 400;'
                         + 'color: #ffb827;'
                         + 'letter-spacing: .22px;'
                         + 'text-align: center;'
                         + 'text-shadow: 1px 1px 0 #000,-1px 1px 0 #000,-1px -1px 0 #000,1px -1px 0 #000;'
                         + 'font-size: 14px;}}'
                        );

        sheet.insertRule(`${mediaDesktop} {`
                         + '#harem_left .buttons_container {'
                         + 'height: 4rem !important;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#harem_left .nb_girls {'
                         + 'font-weight: 400;'
                         + 'color: #ffb827;'
                         + 'letter-spacing: .22px;'
                         + 'text-align: center;'
                         + 'text-shadow: 1px 1px 0 #000,-1px 1px 0 #000,-1px -1px 0 #000,1px -1px 0 #000;'
                         + 'font-size: 18px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#harem_left .general_girls_console {'
                         + 'margin-bottom: -5px !important;}}'
                        );
    }, 2*timeout);
}

function haremGirlsShortcut() {
    setTimeout(function() {
        $('#experience .girl-section .girl-lower-info .girl-resource-section .bar-section .top-text p:first').after('<span id="displayGirlXP" style="position: absolute; top: -3px; left: 124px; width: 100px; text-shadow: 0 0 15px rgba(153,68,0,.35); background: linear-gradient(to top,#ff9000 0,#ffec18 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">' + nThousand(parseInt(window.girl.xp, 10)) + ' XP</span>');

        if(pageLang == 'fr' && $('p.until-next-grade').length > 0) {
            $('p.until-next-grade')[0].childNodes[0].textContent = "Jusqu'à l'étoile ";
            $('p.until-max-grade')[0].childNodes[0].textContent = "Jusqu'à l'étoile ";
        }
        if(pageLang == 'fr' && $('p.girl_exp_left').length > 0) {
            $('p.girl_exp_left')[0].childNodes[0].textContent = "Jusqu'au lvl. ";
            $('p.girl-awakening-exp-left')[0].childNodes[0].textContent = "Jusqu'au lvl. ";
        }

        $('#gifts_tab').click(function() {
            if(pageLang == 'fr' && $('p.until-next-grade').length > 0) {
                $('p.until-next-grade')[0].childNodes[0].textContent = "Jusqu'à l'étoile ";
                $('p.until-max-grade')[0].childNodes[0].textContent = "Jusqu'à l'étoile ";
            }
        });
        $('#books_tab').click(function() {
            if (!$('#experience #displayGirlXP').length) {
                $('#experience .girl-section .girl-lower-info .girl-resource-section .bar-section .top-text p:first').after('<span id="displayGirlXP" style="position: absolute; top: -3px; left: 124px; width: 100px; text-shadow: 0 0 15px rgba(153,68,0,.35); background: linear-gradient(to top,#ff9000 0,#ffec18 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">' + nThousand(parseInt(window.girl.xp, 10)) + ' XP</span>')
            }
            if(pageLang == 'fr' && $('p.girl_exp_left').length > 0) {
                $('p.girl_exp_left')[0].childNodes[0].textContent = "Jusqu'au lvl. ";
                $('p.girl-awakening-exp-left')[0].childNodes[0].textContent = "Jusqu'au lvl. ";
            }
        });
    }, 1000);

    const idCurrentGirl = parseInt(window.girl.id_girl, 10);
    const filteredGirlsList = JSON.parse(localStorage.getItem('HHS.filteredGirlsList'));
    const filteredAvatarList = JSON.parse(localStorage.getItem('HHS.filteredAvatarList'));
    const nbGirls = filteredGirlsList.length
    const currentIndex = filteredGirlsList.indexOf(idCurrentGirl);
    const previousIndex = (nbGirls + currentIndex - 1) % nbGirls;
    const nextIndex = (nbGirls + currentIndex + 1) % nbGirls;
    const idPreviousGirl = filteredGirlsList[previousIndex];
    const idNextGirl = filteredGirlsList[nextIndex];

    $('#experience .girl-section').append('<a href="' + transformNutakuURL('/girl/' + idPreviousGirl + '?resource=experience') + '" id="previous_girl" class="quicknav prev"><img src="' + filteredAvatarList[previousIndex] + '"></a>');
    $('#experience .girl-section').append('<a href="' + transformNutakuURL('/girl/' + idNextGirl + '?resource=experience') + '" id="next_girl" class="quicknav next"><img src="' + filteredAvatarList[nextIndex] + '"></a>');

    $('#affection .girl-section').append('<a href="' + transformNutakuURL('/girl/' + idPreviousGirl + '?resource=affection') + '" id="previous_girl" class="quicknav prev"><img src="' + filteredAvatarList[previousIndex] + '"></a>');
    $('#affection .girl-section').append('<a href="' + transformNutakuURL('/girl/' + idNextGirl + '?resource=affection') + '" id="next_girl" class="quicknav next"><img src="' + filteredAvatarList[nextIndex] + '"></a>');

    $('#equipment .girl-section').append('<a href="' + transformNutakuURL('/girl/' + idPreviousGirl + '?resource=equipment') + '" id="previous_girl" class="quicknav prev"><img src="' + filteredAvatarList[previousIndex] + '"></a>');
    $('#equipment .girl-section').append('<a href="' + transformNutakuURL('/girl/' + idNextGirl + '?resource=equipment') + '" id="next_girl" class="quicknav next"><img src="' + filteredAvatarList[nextIndex] + '"></a>');

    $('#skills .girl-skills-overlay').append('<a href="' + transformNutakuURL('/girl/' + idPreviousGirl + '?resource=skills') + '" id="previous_girl" class="quicknav-skills prev"><img src="' + filteredAvatarList[previousIndex] + '"></a>');
    $('#skills .girl-skills-overlay').append('<a href="' + transformNutakuURL('/girl/' + idNextGirl + '?resource=skills') + '" id="next_girl" class="quicknav-skills next"><img src="' + filteredAvatarList[nextIndex] + '"></a>');

    if ($('#experience .girl-section .girl-lower-info .girl-resource-section .girl_exp_left .xp-next-level').length > 0) {
        new MutationObserver(() => {
            $('#displayGirlXP').text(nThousand(parseInt(window.girl.Xp.cur, 10)) + ' XP')
        }).observe($('#experience .girl-section .girl-lower-info .girl-resource-section .girl_exp_left .xp-next-level')[0], {childList: true})
    }

    $($('.girl-section .girl-avatar .item-column')[0]).css('position', 'relative');
    $($('.girl-section .girl-avatar .item-column')[0]).css('left', '25px');
    $($('.girl-section .girl-avatar .item-column')[1]).css('position', 'relative');
    $($('.girl-section .girl-avatar .item-column')[1]).css('left', '-35px');
    $('.girl-section .girl-avatar .girl-avatar-wrapper').css('position', 'relative');
    $('.girl-section .girl-avatar .girl-avatar-wrapper').css('left', '-5px');
    $('.girl-section .girl-avatar .girl-avatar-wrapper').css('top', '-20px');

    new MutationObserver(() => {
        setTimeout(function() {
            $('#experience .girl-section .girl-lower-info .girl-resource-section .bar-section .top-text p:first').after('<span id="displayGirlXP" style="position: absolute; top: -3px; left: 124px; width: 100px; text-shadow: 0 0 15px rgba(153,68,0,.35); background: linear-gradient(to top,#ff9000 0,#ffec18 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">' + nThousand(parseInt(window.girl.xp, 10)) + ' XP</span>');
        }, 4*timeout);

        if ($('#experience .girl-section .girl-lower-info .girl-resource-section .girl_exp_left .xp-next-level').length > 0) {
            new MutationObserver(() => {
                $('#displayGirlXP').text(nThousand(parseInt(window.girl.Xp.cur, 10)) + ' XP')
            }).observe($('#experience .girl-section .girl-lower-info .girl-resource-section .girl_exp_left .xp-next-level')[0], {childList: true});
        }
    }).observe($('#girl-leveler-tabs')[0], {subtree: true, attributes: true, attributeFilter: ['class']});


    //CSS
    sheet.insertRule('.quicknav {'
                        + 'position: absolute;'
                        + 'width: 100px;'
                        + 'bottom: 156px;}'
                    );

    sheet.insertRule('.quicknav-skills {'
                        + 'position: absolute;'
                        + 'width: 100px;}'
                    );

    sheet.insertRule('.quicknav.prev {'
                        + 'left: 5px;}'
                    );

    sheet.insertRule('.quicknav-skills.prev {'
                        + 'margin-left: 20px;}'
                    );

    sheet.insertRule('.quicknav.next {'
                        + 'left: 405px;}'
                    );

    sheet.insertRule('.quicknav-skills.next {'
                        + 'margin-left: 360px;}'
                    );

    sheet.insertRule('.quicknav img, .quicknav-skills img {'
                        + 'opacity: 0.8;'
                        + 'width: 100%;}'
                    );

    sheet.insertRule('.quicknav img:hover, .quicknav-skills img:hover {'
                        + 'opacity: 1;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                        + '.overlayed-title {'
                        + 'position: relative;'
                        + 'top: 10px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                        + '.overlayed-title {'
                        + 'position: relative;'
                        + 'top: 5px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                        + '#girl-leveler-tabs {'
                        + 'top: 5px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                        + '#experience .girl-lower-info, #affection .girl-lower-info {'
                        + 'margin-top: 5px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                        + '#equipment .girl-lower-info {'
                        + 'margin-top: -14px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                        + '#experience .girl-lower-info, #affection .girl-lower-info {'
                        + 'margin-top: -5px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                        + '#equipment .girl-lower-info {'
                        + 'margin-top: -26px;}}'
                    );

    sheet.insertRule('#equipment .girl-section .girl-avatar .item-column:nth-child(1) {'
                        + 'position: relative !important;'
                        + 'left: 25px !important;}'
                    );

    sheet.insertRule('#equipment .girl-section .girl-avatar .item-column:nth-child(3) {'
                        + 'position: relative !important;'
                        + 'left: -35px !important;}'
                    );

    sheet.insertRule('#equipment .girl-section .girl-avatar .girl-avatar-wrapper {'
                    + 'position: relative !important;'
                    + 'top: -20px !important;'
                    + 'left: -5px !important;}'
                    );
}

function moduleTeamsCollector() {
    const ID_FROM_URL_REGEX = /(?<id>[0-9]+)\/ico(?<level>[0-9])(-[0-9]+x)?\.[a-z]+(\?v=[0-9]+)?$/i
    const ELEMENT_FROM_URL_REGEX = /(?<element>[A-Z][a-z]+)\.[a-z]+(\?v=[0-9]+)?$/i

    const extractIdFromUrl = (url) => {
        const matches = url.match(ID_FROM_URL_REGEX)
        if (!matches || !matches.groups) {
            return {}
        }

        const {groups: {id, level}} = matches
        return {id, level}
    }
    const extractElementFromUrl = (url) => {
        const matches = url.match(ELEMENT_FROM_URL_REGEX)
        if (!matches || !matches.groups) {
            return
        }

        const {groups: {element}} = matches
        return element
    }

    const teamsDict = {}
    const teamIds = []

    $('.team-slot-container[data-is-empty!="1"][data-is-locked!="1"]').each((i, slot) => {
        const teamId = $(slot).data('id-team')
        const icon = $(slot).find('img').attr('girl-ico-src')
        const {id: iconId, level: iconLevel} = extractIdFromUrl(icon)

        const themeIcons = $(slot).find('.team-slot-themes-container img').map((i,el)=>$(el).attr('src')).toArray()
        const themeElements = themeIcons.map(extractElementFromUrl)

        const classes = $(slot).attr('class').replace(/\s+/g, ' ').split(' ')
        const iconRarity = ['mythic', 'legendary', 'epic', 'rare', 'common', 'starting'].find(rarity => classes.includes(rarity))

        teamsDict[teamId] = {
            teamId,
            iconId,
            iconLevel,
            iconRarity,
            themeElements,
        }
        teamIds.push(teamId)
    })

    const teamsData = window.teams_data;
    let i=1;
    while(!teamsData[i].locked && teamsData[i].id_team != null) {
        const id_team = teamsData[i].id_team;
        const girls = [];
        for(let j=0; j<teamsData[i].girls_ids.length; j++) {
            const girlId = parseInt(teamsData[i].girls_ids[j], 10);
            girls.push(girlId)
        }
        teamsDict[id_team].girls = girls;

        i++;
    }

    const teams = {
        teamsDict,
        teamIds
    }
    localStorage.setItem('HHS.TeamsDictionary', JSON.stringify(teams));
}

function moduleFilterGirlsItems() {
    const getParamFilterGirlsItems = () => localStorage.getItem('HHS.paramFilterGirlsItems') ? JSON.parse(localStorage.getItem('HHS.paramFilterGirlsItems')) : {rarity: FILTER_DEFAULT, resonance_class: FILTER_DEFAULT, resonance_theme: FILTER_DEFAULT, resonance_figure: FILTER_DEFAULT};
    const setParamFilterGirlsItems = (paramFilterGirlsItems) => localStorage.setItem('HHS.paramFilterGirlsItems', JSON.stringify(paramFilterGirlsItems));

    const FILTER_DEFAULT = 'all';
    const FILTER_DEFAULT_ICON = 'caracs/no_class.png';
    const FILTER_OPTIONS = new (class {
        get rarity () {return [
            {value: 'common', bgColor: '#8d8e9f'},
            {value: 'rare', bgColor: '#23b56b'},
            {value: 'epic', bgColor: '#ffb244'},
            {value: 'legendary', bgImage: `url(${window.IMAGES_URL}/legendary.png)`},
            {value: 'mythic', bgColor: 'transparent radial-gradient(closest-side at 50% 50%,#f5a866 0,#ec0039 51%,#9e0e27 100%) 0 0 no-repeat padding-box'}
        ]}
        get resonance_class () {return [
            {value: '1', icon: 'pictures/misc/items_icons/1.png'},
            {value: '2', icon: 'pictures/misc/items_icons/2.png'},
            {value: '3', icon: 'pictures/misc/items_icons/3.png'}
        ]}
        get resonance_theme () {return [
            {value: 'darkness', icon: 'pictures/girls_elements/Dominatrix.png'},
            {value: 'light', icon: 'pictures/girls_elements/Submissive.png'},
            {value: 'psychic', icon: 'pictures/girls_elements/Voyeurs.png'},
            {value: 'fire', icon: 'pictures/girls_elements/Eccentric.png'},
            {value: 'nature', icon: 'pictures/girls_elements/Exhibitionist.png'},
            {value: 'stone', icon: 'pictures/girls_elements/Physical.png'},
            {value: 'sun', icon: 'pictures/girls_elements/Playful.png'},
            {value: 'water', icon: 'pictures/girls_elements/Sensual.png'}
        ]}
        get resonance_figure () {return [
            {value: '1', icon: '/pictures/design/battle_positions/1.png'},
            {value: '2', icon: '/pictures/design/battle_positions/2.png'},
            {value: '3', icon: '/pictures/design/battle_positions/3.png'},
            {value: '4', icon: '/pictures/design/battle_positions/4.png'},
            {value: '5', icon: '/pictures/design/battle_positions/5.png'},
            {value: '6', icon: '/pictures/design/battle_positions/6.png'},
            {value: '7', icon: '/pictures/design/battle_positions/7.png'},
            {value: '8', icon: '/pictures/design/battle_positions/8.png'},
            {value: '9', icon: '/pictures/design/battle_positions/9.png'},
            {value: '10', icon: '/pictures/design/battle_positions/10.png'},
            {value: '11', icon: '/pictures/design/battle_positions/11.png'},
            {value: '12', icon: '/pictures/design/battle_positions/12.png'}
        ]}
    })();
    const FILTER_OPTIONS_GRIDS = {
        rarity: {
            flow: 'row',
            cols: '1fr 1fr 1fr',
            rows: '1fr 1fr'
        },
        resonance_class: {
            flow: 'row',
            cols: '1fr 1fr 1fr',
            rows: '1fr'
        },
        resonance_theme: {
            flow: 'row',
            cols: '1fr 1fr 1fr 1fr',
            rows: '1fr 1fr'
        },
        resonance_figure: {
            flow: 'row',
            cols: '1fr 1fr 1fr 1fr',
            rows: '1fr 1fr 1fr'
        }
    };

    const createGridSelectorItem = ({id, value, icon, bgColor, bgImage}) => (`<input type="radio" name=${id} id="${id}-${value}" value="${value}" class="${(currentFilter[id] == '' + value) ? "filter_selected" : ""}" />`
                                                                             + `<label for="${id}-${value}">`
                                                                             + `${icon ? `<img src="${window.IMAGES_URL}/${icon}">` : ''}`
                                                                             + `${bgColor || bgImage ? `<div style="${bgColor?`background:${bgColor};`:''}${bgImage?`background-image:${bgImage};background-size:contain;`:''}"></div>` : ''}`
                                                                             + '</label>')

    const createGridSelector = ({id, options, gridConfig}) => (`<div class="grid-selector" rel="${id}">`
                                                               + '<div class="clear-selector">'
                                                               + `<input type="radio" name="${id}" id="${id}-${FILTER_DEFAULT}" value="${FILTER_DEFAULT}"  class="${(currentFilter[id] == FILTER_DEFAULT) ? "filter_selected" : ""}" />`
                                                               + `<label for="${id}-${FILTER_DEFAULT}">`
                                                               + `<img src="${window.IMAGES_URL}/${FILTER_DEFAULT_ICON}" />`
                                                               + '</label>'
                                                               + '</div>'
                                                               + `<div class="selector-options" style="grid-auto-flow:${gridConfig.flow}; grid-template-rows:${gridConfig.rows}; grid-template-columns:${gridConfig.cols}">`
                                                               + `${options.map(option => {
        const {value, icon, bgColor, bgImage} = option
        return createGridSelectorItem({id, value, icon, bgColor, bgImage})
    }).join('')}`
                                                               + '</div>'
                                                               + '</div>'
                                                               + '<hr style="margin-top: 3px;margin-bottom: 3px; background: rgba(255, 255, 255, 0.533);">');

    const createFilterBox = () => {
        return $('<div style="position:relative">'
                 + `<div class="girl_equip_filter_box form-wrapper" style="display: none;">`
                 + `${['rarity', 'resonance_class', 'resonance_theme', 'resonance_figure'].map(key => createGridSelector({id: key, options: FILTER_OPTIONS[key], gridConfig: FILTER_OPTIONS_GRIDS[key]})).join('')}`
                 + '<div class="grid-selector">'
                 + '<button id="auto_select_button" class="blue_button_L" style="font-size: 14px;">' + window.GT.design.mythic_equipment_auto_select + '</button>'
                 + '<button id="reset_button" class="blue_button_L" style="margin-top: 5px; font-size: 14px;">Reset</button>'
                 + '</div>'
                 + '</div>'
                 + '</div>')
    };

    const createFilterBtn = () => {
        return $('<label class="girl_equip_filter"><input type="button" class="blue_button_L" value="" /></label>');
    };

    let currentFilter = [];
    currentFilter = getParamFilterGirlsItems();

    function displayResonanceBonus($el, classIdentifier, element, figure) {
        if ($el.find('.slot_resonance_bonus').length == 0) {
            $el.append('<div class="slot_resonance_bonus"></div>');
            if(classIdentifier != 0) {
                $el.find('.slot_resonance_bonus').append(`<span class="resonance_bonus class" carac="class${classIdentifier}"></span>`);
                if (classIdentifier == window.girl.class) $el.find('.resonance_bonus.class').addClass('matched');

                if(element != 0 && element != null) {
                    $el.find('.slot_resonance_bonus').append(`<span class="resonance_bonus element">
                                                            <img src="${window.IMAGES_URL}/pictures/girls_elements/${ELEMENTS_ICON_NAMES[element]}.png">
                                                            </span>`);
                    if (element == window.girl.element) $el.find('.resonance_bonus.element').addClass('matched');

                    if(figure != 0 && figure != null) {
                        $el.find('.slot_resonance_bonus').append(`<span class="resonance_bonus figure">
                                                                <img src="${window.IMAGES_URL}/pictures/design/battle_positions/${figure}.png">
                                                                </span>`);
                        if (figure == window.girl.figure) $el.find('.resonance_bonus.figure').addClass('matched');
                    }
                }
            }
        }
    }

    function applyFilter() {
        const $visibleEquips = $('#equipment .inventory').find('.inventory-slot.filled-slot .slot:not(.empty)');
        const $usedEquips = $('.item-column').find('.slot.filled-slot');

        let visibleCount = 0;

        $visibleEquips.each((i, el) => {
            const $el = $(el);
            const equipData = $el.data('d');
            const {rarity} = equipData;
            const {element, figure} = equipData.variation ? equipData.variation : 0;
            const classIdentifier = equipData.variation ? equipData.variation.class : 0;

            displayResonanceBonus($el, classIdentifier, element, figure);

            const rarityMatches = currentFilter.rarity == FILTER_DEFAULT || currentFilter.rarity == rarity
            const classIdentifierMatches = currentFilter.resonance_class == FILTER_DEFAULT || currentFilter.resonance_class == classIdentifier
            const elementMatches = currentFilter.resonance_theme == FILTER_DEFAULT || currentFilter.resonance_theme == element
            const figureMatches = currentFilter.resonance_figure == FILTER_DEFAULT || currentFilter.resonance_figure == figure

            if ([rarityMatches, classIdentifierMatches, elementMatches, figureMatches].every(a=>a)) {
                $el.removeClass('filtered_out')
                $el[0].parentNode.classList.remove('filtered_out')
                visibleCount++
            } else {
                $el.addClass('filtered_out')
                $el[0].parentNode.classList.add('filtered_out')
            }
        })

        $usedEquips.each((i, el) => {
            const $el = $(el);
            const equipData = $el.data('d');
            const {element, figure} = equipData.variation ? equipData.variation : 0;
            const classIdentifier = equipData.variation ? equipData.variation.class : 0;

            displayResonanceBonus($el, classIdentifier, element, figure);
        })

        if (visibleCount < 15) {
            const $visibleSlots = $('#equipment .inventory').find('.slot:visible()')
            // pad with empty slots
            let toPad = 15 - $visibleSlots.length
            while (toPad > 0) {
                $('#equipment .inventory').find('.slot').last().after('<div class="slot empty"></div>')
                toPad--
            }
        }
        $('#equipment .inventory').getNiceScroll().resize()
    }

    const attachFilterBox = () => {
        const $btn = createFilterBtn();
        const $box = createFilterBox();
        const $togglable = $box.find('.girl_equip_filter_box');

        $('#equipment .wrapper').append($btn).append($box);

        $btn.click(() => $togglable.toggle());
        $('#auto_select_button').click(() => autoSelectFilter());
        $('#reset_button').click(() => resetFilter());
        $box.find('input').each((i, input) => {
            $(input).click((e) => {
                const {value, name} = e.target;
                $(`div[rel=${name}] .filter_selected`).removeClass('filter_selected');
                $(`#${name}-${value}`).addClass('filter_selected');
                let newName = name.split('-')[0];
                currentFilter[newName] = value;
                setParamFilterGirlsItems(currentFilter);
                applyFilter();
            })
        })
    }

    function autoSelectFilter() {
        let girlClass = window.girl.class;
        let girlElement = window.girl.element;
        let girlPosition = window.girl.figure;

        let formerClass = currentFilter.resonance_class;
        let formerElement = currentFilter.resonance_theme;
        let formerPosition = currentFilter.resonance_figure;

        currentFilter.resonance_class = girlClass;
        currentFilter.resonance_theme = girlElement;
        currentFilter.resonance_figure = girlPosition;

        $('#resonance_class-' + formerClass).removeClass('filter_selected');
        $('#resonance_class-' + girlClass).addClass('filter_selected');
        $('#resonance_theme-' + formerElement).removeClass('filter_selected');
        $('#resonance_theme-' + girlElement).addClass('filter_selected');
        $('#resonance_figure-' + formerPosition).removeClass('filter_selected');
        $('#resonance_figure-' + girlPosition).addClass('filter_selected');

        setParamFilterGirlsItems(currentFilter);
        applyFilter();
    }

    function resetFilter() {
        let formerRarity = currentFilter.rarity;
        let formerClass = currentFilter.resonance_class;
        let formerElement = currentFilter.resonance_theme;
        let formerPosition = currentFilter.resonance_figure;

        currentFilter.rarity = FILTER_DEFAULT;
        currentFilter.resonance_class = FILTER_DEFAULT;
        currentFilter.resonance_theme = FILTER_DEFAULT;
        currentFilter.resonance_figure = FILTER_DEFAULT;

        $('#rarity-' + formerRarity).removeClass('filter_selected');
        $('#rarity-' + FILTER_DEFAULT).addClass('filter_selected');
        $('#resonance_class-' + formerClass).removeClass('filter_selected');
        $('#resonance_class-' + FILTER_DEFAULT).addClass('filter_selected');
        $('#resonance_theme-' + formerElement).removeClass('filter_selected');
        $('#resonance_theme-' + FILTER_DEFAULT).addClass('filter_selected');
        $('#resonance_figure-' + formerPosition).removeClass('filter_selected');
        $('#resonance_figure-' + FILTER_DEFAULT).addClass('filter_selected');

        setParamFilterGirlsItems(currentFilter);
        applyFilter();
    }

    attachFilterBox();
    applyFilter();

    new MutationObserver(() => {
        if ($('#equipment_tab.underline-tab').length) {
            new MutationObserver(() => {
                applyFilter();
            }).observe($('#equipment .selectric .label')[0], {childList: true});

            new MutationObserver(() => {
                applyFilter();
            }).observe($('#equipment .inventory')[0], {childList: true});
        }
    }).observe($('#girl-leveler-tabs')[0], {subtree: true, attributes: true, attributeFilter: ['class']});

    new MutationObserver(() => {
        applyFilter();
    }).observe($('#equipment .inventory')[0], {childList: true});

    if($('#equipment_tab.underline-tab').length) {
        new MutationObserver(() => {
            applyFilter();
        }).observe($('#equipment .selectric .label')[0], {childList: true});
    }


    //CSS
    sheet.insertRule('label.girl_equip_filter {'
                     + 'width: 32px;'
                     + 'position: absolute;'
                     + 'background: transparent;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#equipment .wrapper label.girl_equip_filter {'
                     + 'left: 890px !important;'
                     + 'top: 92px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#equipment .wrapper label.girl_equip_filter {'
                     + 'left: 890px !important;'
                     + 'top: 72px !important;}}'
                    );

    sheet.insertRule('#equipment .total-from-items .wrapper .form-control {'
                     + 'margin-right: 90px !important;}'
                    );

    sheet.insertRule('.girl_equip_filter input {'
                     + 'height: 32px;'
                     + 'width: 32px;'
                     + 'display: block;'
                     + 'padding: 0px;}'
                    );

    sheet.insertRule('label.girl_equip_filter::before {'
                     + 'content: " ";'
                     + 'display: block;'
                     + 'position: absolute;'
                     + 'height: 100%;'
                     + 'width: 100%;'
                     + 'background-position: center;'
                     + 'background-size: 24px;'
                     + 'background-repeat: no-repeat;'
                     + 'background-image: url("' + window.IMAGES_URL + '/design_v2/search_open.png");'
                     + 'pointer-events: none;}'
                    );

    sheet.insertRule('.girl_equip_filter_box {'
                     + 'position: absolute;'
                     + 'width: auto;'
                     + 'height: fit-content;'
                     + 'z-index: 4;'
                     + 'border-radius: 8px 10px 10px 8px;'
                     + 'background-color: rgb(30, 38, 30);'
                     + 'box-shadow: rgba(255, 255, 255, 0.73) 0px 0px;'
                     + 'padding: 5px;'
                     + 'border: 1px solid rgb(255, 162, 62);}'
                    );

    sheet.insertRule('#equipment .wrapper .girl_equip_filter_box {'
                     + 'left: -818px !important;'
                     + 'top: -75px !important;}'
                    );

    sheet.insertRule('.girl_equip_filter_box label {'
                     + 'background: transparent;'
                     + 'width: auto;'
                     + 'margin: 0px;}'
                    );

    sheet.insertRule('.grid-selector {'
                     + 'width: 100%;'
                     + 'display: flex;'
                     + 'align-items: center;'
                     + 'justify-content: center;'
                     + 'flex-direction: column;}'
                    );

    sheet.insertRule('.grid-selector:last-child {'
                     + 'margin-bottom: 0px;}'
                    );

    sheet.insertRule('.grid-selector input {'
                     + 'display: none;}'
                    );

    sheet.insertRule('.grid-selector .selector-options {'
                     + 'width: -moz-fit-content;'
                     + 'width: fit-content;'
                     + 'display: grid;'
                     + 'grid-gap: 2px;}'
                    );

    sheet.insertRule('.grid-selector .selector-options img {'
                     + 'height: 26px;'
                     + 'width: 26px;'
                     + 'margin: 2px;}'
                    );

    sheet.insertRule('.grid-selector .selector-options div {'
                     + 'height: 26px;'
                     + 'width: 26px;'
                     + 'margin: 2px;'
                     + 'border-radius: 5px;}'
                    );

    sheet.insertRule('.grid-selector .clear-selector {'
                     + 'width: fit-content;'
                     + 'margin-bottom: 2px;}'
                    );

    sheet.insertRule('.grid-selector .clear-selector img {'
                     + 'height: 28px;'
                     + 'width: 28px;}'
                    );

    sheet.insertRule('.girl_equip_filter_box .grid-selector input.filter_selected + label, .girl_equip_filter_box .grid-selector input:hover + label {'
                     + 'background-color: #fff8 !important;}'
                    );

    sheet.insertRule('.filtered_out {'
                     + 'display: none !important;}'
                    );

    sheet.insertRule('.slot_resonance_bonus span[carac]::before {'
                     + 'position: absolute;'
                     + 'top: -10px;'
                     + 'left: 0px;'
                     + 'width: 16px !important;'
                     + 'height: 16px !important;}'
                    );

    sheet.insertRule('.slot_resonance_bonus .resonance_bonus.element img, .slot_resonance_bonus .resonance_bonus.figure img {'
                     + 'display: inline-block;'
                     + 'position: absolute;'
                     + 'top: -10px;'
                     + 'background-size: 20px;'
                     + 'background-repeat: no-repeat;}'
                    );

    sheet.insertRule('.slot_resonance_bonus .resonance_bonus.element img {'
                     + 'width: 16px;'
                     + 'height: 16px;'
                     + 'left: 24px;}'
                    );

    sheet.insertRule('.slot_resonance_bonus .resonance_bonus.figure img {'
                     + 'width: 20px;'
                     + 'height: 20px;'
                     + 'left: 48px;}'
                    );

    sheet.insertRule('.item-column .slot_resonance_bonus span[carac]::before, .item-column .slot_resonance_bonus .resonance_bonus.element img, .item-column .slot_resonance_bonus .resonance_bonus.figure img {'
                     + 'top: 2px !important;}'
                    );

    sheet.insertRule('.item-column .slot_resonance_bonus .resonance_bonus.element img {'
                     + 'left: 22px !important;}'
                    );

    sheet.insertRule('.item-column .slot_resonance_bonus .resonance_bonus.figure img {'
                     + 'left: 42px !important;}'
                    );

    sheet.insertRule('.matched img, .matched::before {'
                     + 'filter: drop-shadow(0px 0px 3px #00ff00) drop-shadow(0px 0px 3px #00ff00) drop-shadow(0px 0px 3px #00ff00);}'
                    );
}


/* ====================
	LEAGUE INFORMATION
   ==================== */

function moduleLeague() {
    if (CurrentPage.includes('leagues')) {
        if ($('#leagues .league_content .league_table .data-list').length == 0) return;

        $('#leagues-tabs').append('<div class="leagues_middle_header_script"></div>');

        let playersTotal;
        let challengesLeft;
        let challengesPossibleMinutes;
        let challengesPossible;
        let challengesDone = 0;
        let challengesWon = 0;
        let challengesLost = 0;
        let HeroPosition;
        let HeroPoints;
        let maxDemotePoints;
        let maxDemoteDiff;
        let maxDemoteDisplay;
        let textDemote;
        let maxStagnatePoints;
        let maxStagnateDiff;
        let maxStagnateDisplay;
        let textStagnate;
        let minTop4Points;
        let minTop4Diff;
        let minTop4Display;
        let textTop4;
        let minTop15Points;
        let textTop15;
        let minTop15Display;
        let minTop30Points;
        let minTop30Diff;
        let minTop30Display;
        let textTop30;
        let avgScore;
        let scoreExpected;
        let top4Points;
        let top5Points;
        let top15Points;
        let top16Points;
        let top30Points;
        let top31Points;
        let topDemotePoints;
        let topNonDemotePoints;

        let	includeBoard = false;

        if (loadSetting('leagueBoard')) {
            includeBoard = true;
        }

        challengesPossibleMinutes = parseInt(Math.floor(window.season_end_at/60), 10);
        challengesPossible = (window.Hero.energies.challenge.amount != window.Hero.energies.challenge.max_regen_amount)? Math.floor((challengesPossibleMinutes + (35 - window.Hero.energies.challenge.next_refresh_ts / 60))/35) + parseInt(window.Hero.energies.challenge.amount, 10) : Math.floor(challengesPossibleMinutes/35) + parseInt(window.Hero.energies.challenge.amount, 10);

        playersTotal = window.opponents_list.length;

        for(let i=0; i<playersTotal; i++) {
            let $playerData = $($('#leagues .league_content .league_table .data-list .body-row')[i]);
            let fightsDone = 0;
            let fightsWon = 0;
            let fightsLost = 0;

            let fightsData = $playerData.find('div[column = "match_history_sorting"]')[0].children;
            for (let i=0; i<fightsData.length; i++) {
                switch (fightsData[i].className) {
                    case "result ":
                        break;
                    case "result won":
                        fightsDone++;
                        fightsWon++;
                        break;
                    case "result lost":
                        fightsDone++;
                        fightsLost++;
                        break;
                }
            }

            let playerPosition = localeStringToNumber($playerData.find('div[column = "place"]')[0].innerText);
            let playerPoints = localeStringToNumber($playerData.find('div[column = "player_league_points"]')[0].innerText);

            if (fightsData.length == 0) {
                HeroPosition = playerPosition;
                HeroPoints = playerPoints;
            }

            switch (playerPosition) {
                case 4:
                    top4Points = playerPoints;
                    break;
                case 5:
                    top5Points = playerPoints;
                    break;
                case 15:
                    top15Points = playerPoints;
                    break;
                case 16:
                    top16Points = playerPoints;
                    break;
                case 30:
                    top30Points = playerPoints;
                    break;
                case 31:
                    top31Points = playerPoints;
                    break;
                case (playersTotal-14):
                    topDemotePoints = playerPoints;
                    break;
                case (playersTotal-15):
                    topNonDemotePoints = playerPoints;
                    break;
            }

            challengesDone += fightsDone;
            challengesWon += fightsWon;
            challengesLost += fightsLost;
        }

        challengesLeft = 3*(playersTotal-1)-challengesDone;

        avgScore = (challengesDone != 0) ? HeroPoints/challengesDone : 0;
        scoreExpected = Math.floor(avgScore*3*(playersTotal-1));

        let leagueScore = {
            points: HeroPoints,
            avg: Math.round(avgScore*100)/100
        }
        let oldScore = JSON.parse(localStorage.getItem('HHS.leagueScore')) || {points: 0, avg: 0};
        let oldPoints = oldScore.points;
        if (HeroPoints > oldPoints) {
            localStorage.setItem('HHS.leagueScore', JSON.stringify(leagueScore));
        }

        if (HeroPosition > (playersTotal - 15)) {
            maxDemotePoints = topNonDemotePoints;
            maxDemoteDiff = maxDemotePoints - HeroPoints;
            if (HeroPoints == 0 && maxDemotePoints == 0) {
                maxDemoteDisplay = '±' + nThousand(maxDemoteDiff);
                textDemote = labels.demote_holdzero;
            }
            else {
                maxDemoteDisplay = '+' + nThousand(maxDemoteDiff);
                textDemote = labels.demote_up;
            }
        }
        else {
            maxDemotePoints = topDemotePoints
            maxDemoteDiff = maxDemotePoints - HeroPoints;
            if (HeroPoints == 0 && maxDemotePoints == 0) {
                maxDemoteDisplay = '±' + nThousand(maxDemoteDiff);
                textDemote = labels.demote_holdzero;
            }
            else {
                if (maxDemoteDiff == 0) {
                    maxDemoteDisplay = '-' + nThousand(maxDemoteDiff);
                }
                else {
                    maxDemoteDisplay = nThousand(maxDemoteDiff);
                }
                textDemote = labels.demote_down;
            }
        }

        if (HeroPosition > 15) {
            maxStagnatePoints = top15Points;
            maxStagnateDiff = maxStagnatePoints - HeroPoints;
            minTop15Points = maxStagnatePoints + 1;
            if (HeroPoints == 0 && maxStagnatePoints == 0) {
                maxStagnateDisplay = '±' + nThousand(maxStagnateDiff);
                minTop15Display = '±' + nThousand(maxStagnateDiff+1);
                textStagnate = labels.stagnate_holdzero;
                textTop15 = labels.top15_up;
            }
            else {
                maxStagnateDisplay = '+' + nThousand(maxStagnateDiff);
                minTop15Display = '+' + nThousand(maxStagnateDiff+1);
                textStagnate = labels.stagnate_up;
                textTop15 = labels.top15_up;
            }
        }
        else {
            maxStagnatePoints = top16Points;
            maxStagnateDiff = maxStagnatePoints - HeroPoints;
            minTop15Points = top16Points;
            if (HeroPoints == 0 && maxStagnatePoints == 0) {
                maxStagnateDisplay = '±' + nThousand(maxStagnateDiff);
                minTop15Display = '±' + nThousand(maxStagnateDiff);
                textStagnate = labels.stagnate_holdzero;
                textTop15 = labels.top15_hold;
            }
            else {
                if (maxStagnateDiff == 0) {
                    maxStagnateDisplay = '-' + nThousand(maxStagnateDiff);
                    minTop15Display = '-' + nThousand(maxStagnateDiff);
                }
                else {
                    maxStagnateDisplay = nThousand(maxStagnateDiff);
                    minTop15Display = nThousand(maxStagnateDiff);
                }
                textStagnate = labels.stagnate_down;
                textTop15 = labels.top15_hold;
            }
        }

        if (HeroPosition > 30) {
            minTop30Points = top30Points + 1;
            minTop30Diff = minTop30Points - HeroPoints;
            if (minTop30Diff > 0) {
                minTop30Display = '+' + (nThousand(minTop30Diff));
                textTop30 = labels.top30_up;
            }
            else {
                minTop30Display = nThousand(minTop30Diff);
                textTop30 = labels.top30_hold;
            }
        }
        else {
            minTop30Points = top31Points;
            minTop30Diff = minTop30Points - HeroPoints;
            if (minTop30Diff < 0) {
                minTop30Display = nThousand(minTop30Diff);
                textTop30 = labels.top30_hold;
            }
            else {
                minTop30Display = '+' + (nThousand(minTop30Diff));
                textTop30 = labels.top30_hold;
            }
        }

        if (HeroPosition > 4) {
            minTop4Points = top4Points + 1;
            minTop4Diff = minTop4Points - HeroPoints;
            if (minTop4Diff > 0) {
                minTop4Display = '+' + (nThousand(minTop4Diff));
                textTop4 = labels.top4_up;
            }
            else {
                minTop4Display = nThousand(minTop4Diff);
                textTop4 = labels.top4_hold;
            }
        }
        else {
            minTop4Points = top5Points;
            minTop4Diff = minTop4Points - HeroPoints;
            if (minTop4Diff > 0) {
                minTop4Display = '+' + (nThousand(minTop4Diff));
                textTop4 = labels.top4_hold;
            }
            else {
                minTop4Display = nThousand(minTop4Diff);
                textTop4 = labels.top4_hold;
            }
        }

        if (window.current_tier_number == 9) {
            $('.leagues_middle_header_script').append('<div class="scriptLeagueInfo">'
                                                      + '<span class="averageScore" tooltip="" hh_title="' + labels.averageScore + nThousand(Math.round(avgScore*100)/100) + '<BR>' + labels.scoreExpected + nThousand(scoreExpected) + '"><img src="https://cdn-icons-png.flaticon.com/32/1753/1753830.png" style="height: 15px; width: 16px; margin-left: 2px; margin-bottom: 5px;">' + nThousand(Math.round(avgScore*100)/100) + '</span>'
                                                      + '<span class="possibleChallenges" tooltip="" hh_title="' + labels.challenges_regen + challengesPossible + labels.challenges_left + challengesLeft + '"><img src="https://cdn-icons-png.flaticon.com/32/551/551227.png" style="height: 15px; width: 16px; margin-left: 6px; margin-bottom: 4px;">' + challengesPossible + '/' + challengesLeft
                                                      + '<span class="scriptLeagueInfoTooltip possibleChallengesTooltip"></span></span>'
                                                      + '<span class="minTop4" tooltip="" hh_title="' + textTop4 + nThousand(minTop4Points) + ' ' + labels.points + '"><img src="https://cdn-icons-png.flaticon.com/32/752/752667.png" style="height: 15px; width: 16px; margin-left: 6px; margin-bottom: 4px;">' + minTop4Display + '</span>'
                                                      + '<span class="minTop15" tooltip="" hh_title="' + textTop15 + nThousand(minTop15Points) + ' ' + labels.points + '"><img src="https://cdn-icons-png.flaticon.com/32/5259/5259722.png" style="height: 15px; width: 16px; margin-left: 6px; margin-bottom: 4px;">' + minTop15Display + '</span>'
                                                      + '<span class="minTop30" tooltip="" hh_title="' + textTop30 + nThousand(minTop30Points) + ' ' + labels.points + '"><img src="https://cdn-icons-png.flaticon.com/32/7123/7123659.png" style="height: 15px; width: 16px; margin-left: 6px; margin-bottom: 4px;">' + minTop30Display + '</span>'
                                                      + '<span class="maxDemote" tooltip="" hh_title="' + textDemote + nThousand(maxDemotePoints) + ' ' + labels.points + '"><img src="https://cdn-icons-png.flaticon.com/32/892/892505.png" style="height: 15px; width: 16px; margin-left: 6px; margin-bottom: 4px;">' + maxDemoteDisplay + '</span>'
                                                      + '</div>');

            if (includeBoard == false) {
                $('.minTop4').empty();
                $('.minTop15').empty();
                $('.minTop30').empty();
            }
        }
        else if (window.current_tier_number == 1) {
            $('.leagues_middle_header_script').append('<span class="scriptLeagueInfo">'
                                                      + '<span class="averageScore" tooltip="" hh_title="' + labels.averageScore + nThousand(Math.round(avgScore*100)/100) + '<BR>' + labels.scoreExpected + nThousand(scoreExpected) + '"><img src="https://cdn-icons-png.flaticon.com/32/1753/1753830.png" style="height: 15px; width: 16px; margin-left: 2px; margin-bottom: 5px;"> ' + nThousand(Math.round(avgScore*100)/100) + '</span>'
                                                      + '<span class="possibleChallenges" tooltip="" hh_title="' + labels.challenges_regen + challengesPossible + labels.challenges_left + challengesLeft + '"><img src="https://cdn-icons-png.flaticon.com/32/551/551227.png" style="height: 15px; width: 16px; margin-left: 7px; margin-bottom: 4px;"> ' + challengesPossible + '/' + challengesLeft
                                                      + '<span class="scriptLeagueInfoTooltip possibleChallengesTooltip"></span></span>'
                                                      + '<span class="maxStagnate" tooltip="" hh_title="' + textStagnate + nThousand(maxStagnatePoints) + ' ' + labels.points + '"><img src="https://i.postimg.cc/HnkyDtG3/icon-league-hold.png" style="margin-left: 7px; margin-bottom: 4px;"> ' + maxStagnateDisplay + '</span>'
                                                      + '<span class="minTop30" tooltip="" hh_title="' + textTop30 + nThousand(minTop30Points) + ' ' + labels.points + '"><img src="https://cdn-icons-png.flaticon.com/32/7123/7123659.png" style="height: 15px; width: 16px; margin-left: 7px; margin-bottom: 4px;"> ' + minTop30Display + '</span>'
                                                      + '</span>');

            if (includeBoard == false) {
                $('.minTop30').empty();
            }
        }
        else {
            $('.leagues_middle_header_script').append('<span class="scriptLeagueInfo">'
                                                      + '<span class="averageScore" tooltip="" hh_title="' + labels.averageScore + nThousand(Math.round(avgScore*100)/100) + '<BR>' + labels.scoreExpected + nThousand(scoreExpected) + '"><img src="https://cdn-icons-png.flaticon.com/32/1753/1753830.png" style="height: 15px; width: 16px; margin-left: 2px; margin-bottom: 5px;"> ' + nThousand(Math.round(avgScore*100)/100) + '</span>'
                                                      + '<span class="possibleChallenges" tooltip="" hh_title="' + labels.challenges_regen + challengesPossible + labels.challenges_left + challengesLeft + '"><img src="https://cdn-icons-png.flaticon.com/32/551/551227.png" style="height: 15px; width: 16px; margin-left: 6px; margin-bottom: 4px;"> ' + challengesPossible + '/' + challengesLeft
                                                      + '<span class="scriptLeagueInfoTooltip possibleChallengesTooltip"></span></span>'
                                                      + '<span class="minTop4" tooltip="" hh_title="' + textTop4 + nThousand(minTop4Points) + ' ' + labels.points + '"><img src="https://cdn-icons-png.flaticon.com/32/752/752667.png" style="height: 15px; width: 16px; margin-left: 6px; margin-bottom: 4px;">' + minTop4Display + '</span>'
                                                      + '<span class="maxStagnate" tooltip="" hh_title="' + textStagnate + nThousand(maxStagnatePoints) + ' ' + labels.points + '"><img src="https://i.postimg.cc/HnkyDtG3/icon-league-hold.png" style="height: 15px; width: 16px; margin-left: 6px; margin-bottom: 4px;"> ' + maxStagnateDisplay + '</span>'
                                                      + '<span class="minTop30" tooltip="" hh_title="' + textTop30 + nThousand(minTop30Points) + ' ' + labels.points + '"><img src="https://cdn-icons-png.flaticon.com/32/7123/7123659.png" style="height: 15px; width: 16px; margin-left: 6px; margin-bottom: 4px;"> ' + minTop30Display + '</span>'
                                                      + '<span class="maxDemote" tooltip="" hh_title="' + textDemote + nThousand(maxDemotePoints) + ' ' + labels.points + '"><img src="https://cdn-icons-png.flaticon.com/32/892/892505.png" style="height: 15px; width: 16px; margin-left: 6px; margin-bottom: 4px;"> ' + maxDemoteDisplay + '</span>'
                                                      + '</span>');

            if (includeBoard == false) {
                $('.minTop4').empty();
                $('.minTop30').empty();
            }
        }

        //CSS
        sheet.insertRule('.leagues_middle_header_script {'
                         + 'display: flow-root;'
                         + 'margin-top: 0px;}'
                        );

        sheet.insertRule('.scriptLeagueInfo {'
                         + 'position: relative;'
                         + 'left: 150px;'
                         + 'font-size: 13px;'
                         + 'color: #fff;'
                         + 'display: flex;'
                         + 'flex-direction: row;'
                         + 'float: right;}'
                        );

        sheet.insertRule(`${mediaDesktop} {`
                         + '.scriptLeagueInfo {'
                         + 'top: 5px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '.scriptLeagueInfo {'
                         + 'top: 2px;}}'
                        );

        sheet.insertRule('.scriptLeagueInfoTooltip {'
                         + 'visibility: hidden; '
                         + 'font-size: 12px; '
                         + 'background-color: black; '
                         + 'color: #fff; '
                         + 'text-align: center; '
                         + 'padding: 3px 5px 3px 5px; '
                         + 'border: 2px solid #905312; '
                         + 'border-radius: 6px; '
                         + 'background-color: rgba(32,3,7); '
                         + 'position: absolute; '
                         + 'margin-top: 5px; '
                         + 'z-index: 9;}'
                        );

        sheet.insertRule('.scriptLeagueInfoTooltip::after {'
                         + 'content: " "; '
                         + 'position: absolute; '
                         + 'bottom: 100%; '
                         + 'left: 50%; '
                         + 'margin-left: -10px; '
                         + 'border-width: 10px; '
                         + 'border-style: solid; '
                         + 'border-color: transparent transparent #905312 transparent;}'
                        );

        sheet.insertRule('.possibleChallengesTooltip {'
                         + 'top: 20px; '
                         + 'margin-left: -146px;}'
                        );

        sheet.insertRule('.possibleChallenges:hover .possibleChallengesTooltip {'
                         + 'visibility: visible;}'
                        );

        //League display
        sheet.insertRule(`${mediaMobile} {`
                         + '#league {'
                         + 'background: #222;}}'
                        );

        sheet.insertRule(`${mediaDesktop} {`
                         + '#leagues .league_content .league_tiers {'
                         + 'margin-top: -12px !important;}}'
                        );

        sheet.insertRule('#leagues .league_content .league_tiers .league_tier_progress .tier_icons {'
                         + 'height: 3rem !important;'
                         + 'margin-top: -3rem !important;}'
                        );

        sheet.insertRule('#leagues .league_content .league_tiers .league_tier_progress .tier_icons img {'
                         + 'flex: 0 !important;'
                         + 'width: 3rem !important;}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#leagues .league_content .league_tiers {'
                         + 'margin-top: -12px !important;}}'
                        );

        sheet.insertRule('#leagues .league_content .league_tiers .league_tier_progress .bar-wrap {'
                         + 'top: -14px;}'
                        );

        sheet.insertRule('#leagues .league_content .league_table .data-list .data-row.head-row {'
                         + 'margin-top: -1px;'
                         + 'height: 1.5rem !important;'
                         + 'border-top-left-radius: 0 !important;'
                         + 'min-height: 1.5rem !important;}'
                        );

        sheet.insertRule('#leagues .league_content .league_table {'
                         + 'height: 23.5rem !important;}'
                        );

        sheet.insertRule('#leagues .league_content .league_table .data-list .data-row.player-row {'
                         + 'top: 1.4rem !important;}'
                        );

        sheet.insertRule('#leagues .league_content .league_table .data-list .data-row .head-column[column="boosters"], #leagues .league_content .league_table .data-list .data-row .head-column[column="team"] {'
                         + 'height: 1.4rem !important;}'
                        )

        sheet.insertRule(`${mediaDesktop} {`
                         + '#leagues .league_content .league_table .data-list .data-row .data-column[column="boosters"] .boosters, #leagues .league_content .league_table .data-list .data-row .head-column[column="boosters"] .boosters {'
                         + 'width: 6.5rem !important;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#leagues .league_content .league_table .data-list .data-row .data-column[column="boosters"] .boosters, #leagues .league_content .league_table .data-list .data-row .head-column[column="boosters"] .boosters {'
                         + 'width: 6.5rem !important;}}'
                        );

        sheet.insertRule('#leagues .league_content .league_table .data-list .data-row.body-row {'
                         + 'min-height: 2.5rem !important;'
                         + 'max-height: 2.8rem;}'
                        );

        sheet.insertRule('#leagues .league_content .league_table .data-list .data-row .data-column[column="place"], #leagues .league_content .league_table .data-list .data-row .head-column[column="place"] {'
                         + 'min-width: 2.8rem !important;}'
                        );

        sheet.insertRule('#leagues .league_content .league_table .data-list .data-row .data-column[column="level"], #leagues .league_content.hidden_girl .league_table .data-list .data-row .head-column[column="level"] {'
                         + 'min-width: 2.5rem !important;}'
                        );

        sheet.insertRule('#leagues .league_content .league_table .data-list .data-row .data-column[column="power"], #leagues .league_content .league_table .data-list .data-row .head-column[column="power"] {'
                         + 'min-width: 3.8rem !important;}'
                        );

        sheet.insertRule('#leagues .league_content .league_table .data-list .data-row .data-column[column="match_history_sorting"], #leagues .league_content .league_table .data-list .data-row .head-column[column="match_history_sorting"] {'
                         + 'min-width: 4.5rem !important;}'
                        );

        sheet.insertRule('#leagues .league_content .league_table.hidden_girl .data-list .data-row .head-column[column="team"], #leagues .league_content.hidden_girl .league_table .data-list .data-row .data-column[column="team"] {'
                         + 'opacity: 1;}'
                        );

        sheet.insertRule('.hh_class_tooltip.hh_class_tooltip_click_disabled {'
                         + 'height: 131px !important;}'
                        );

        sheet.insertRule('#leagues .league_content .league_buttons {'
                         + 'margin-bottom: -4px !important;'
                         + 'height: 2rem !important;}'
                        );

        sheet.insertRule('#leagues .league_content .league_buttons .league_buttons_block {'
                         + 'margin-left: -38px;}'
                        );

        sheet.insertRule('#leagues .league_content .league_buttons .challenge_points {'
                         + 'left: -25px;}'
                        );

        sheet.insertRule('#leagues .league_content .league_buttons .league_end_in {'
                         + 'position: relative;'
                         + 'left: -90px;}'
                        );

        sheet.insertRule('#leagues .league_content .league_buttons .league_end_in .season-timer.timer {'
                         + 'width: max-content;}'
                        );

        sheet.insertRule('#leagues .league_content .league_buttons .change_team_container {'
                         + 'position: relative;'
                         + 'left: -160px;}'
                        );

        sheet.insertRule('#leagues .league_content .league_buttons #change_team {'
                         + 'width: max-content !important;}'
                        );

        function leagueFilter() {
            const LEAGUE_FILTER_DEFAULT = {none: 'checked', with_skill: 'checked', stun: 'checked', shield: 'checked', reflect: 'checked', execute: 'checked', fought: '', with_boosters: 'checked', no_boosters: 'checked'};
            let LEAGUE_FILTER = localStorage.getItem('HHS.leagueFilter') || JSON.stringify(LEAGUE_FILTER_DEFAULT);
            LEAGUE_FILTER = JSON.parse(LEAGUE_FILTER);
            if (LEAGUE_FILTER.with_skill == undefined) {
                if (LEAGUE_FILTER.stun == '' && LEAGUE_FILTER.shield == '' && LEAGUE_FILTER.reflect == '' && LEAGUE_FILTER.execute == '') LEAGUE_FILTER.with_skill = '';
                else LEAGUE_FILTER.with_skill = 'checked';
                localStorage.setItem('HHS.leagueFilter', JSON.stringify(LEAGUE_FILTER));
            }
            if (LEAGUE_FILTER.fought == undefined) {
                if (localStorage.getItem('HHS.hide_beaten') == 0) LEAGUE_FILTER.fought = 'checked';
                else LEAGUE_FILTER.fought = '';
                localStorage.setItem('HHS.leagueFilter', JSON.stringify(LEAGUE_FILTER));
            }
            if (LEAGUE_FILTER.with_boosters == undefined) {
                LEAGUE_FILTER.with_boosters = 'checked';
                LEAGUE_FILTER.no_boosters = 'checked';
                localStorage.setItem('HHS.leagueFilter', JSON.stringify(LEAGUE_FILTER));
            }
            localStorage.removeItem('HHS.hide_beaten');
            if (localStorage.getItem('HHS.leagueFilter') == undefined) localStorage.setItem('HHS.leagueFilter', JSON.stringify(LEAGUE_FILTER_DEFAULT));

            $(".leagues_middle_header_script").append('<button id="league_filter" class="blue_button_L">' + labels.filter + '</button>');
            $(".leagues_middle_header_script").append(createFilterBox());
            createFilterEvents();
            filterOpponents();

            function createFilterBox() {
                let totalHTML = `<fieldset id="league_filter_box">
                                <div class="filter_type" style="break-inside: avoid;"><legend>${labels.tier5_skill_filter}</legend>
                                <div>
                                    <input type="checkbox" id="filter_no_skill" name="tier5_skill" value="none" ${LEAGUE_FILTER.none}/>
                                    <label for="none">${labels.none}</label>
                                </div>
                                <div>
                                    <input type="checkbox" id="filter_with_skill" name="tier5_skill" value="with_skill" ${LEAGUE_FILTER.with_skill}/>
                                    <label for="with_skill">${labels.with}</label>
                                </div>
                                <div>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="filter_stun" name="tier5_skill" value="stun" ${LEAGUE_FILTER.stun}/>
                                    <label for="stun">Stun</label>
                                </div>
                                <div>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="filter_shield" name="tier5_skill" value="shield" ${LEAGUE_FILTER.shield}/>
                                    <label for="shield">Shield</label>
                                </div>
                                <div>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="filter_reflect" name="tier5_skill" value="reflect" ${LEAGUE_FILTER.reflect}/>
                                    <label for="reflect">Reflect</label>
                                </div>
                                <div>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="filter_execute" name="tier5_skill" value="execute" ${LEAGUE_FILTER.execute}/>
                                    <label for="execute">Execute</label>
                                </div>
                                </div>
                                <div><div class="filter_type"  style="break-inside: avoid;"><legend>${labels.opponents}</legend>
                                <div>
                                    <input type="checkbox" id="filter_fought" name="opponents" value="fought" ${LEAGUE_FILTER.fought}/>
                                    <label for="none">${labels.already_fought}</label>
                                </div></div>
                                <div class="filter_type" style="break-inside: avoid;"><legend style="padding: 15px 0 0;">${labels.Boosters}</legend>
                                <div>
                                    <input type="checkbox" id="filter_with_boosters" name="boosters" value="with_boosters" ${LEAGUE_FILTER.with_boosters}/>
                                    <label for="none">${labels.with_boosters}</label>
                                </div>
                                <div>
                                    <input type="checkbox" id="filter_no_boosters" name="boosters" value="no_boosters" ${LEAGUE_FILTER.no_boosters}/>
                                    <label for="none">${labels.no_boosters}</label>
                                </div></div></div>
                                </fieldset>`

                return totalHTML;
            }

            function createFilterEvents() {
                $('#league_filter').on('click', function() {
                    let currentBoxDisplay = $("#league_filter_box").css('display');
                    $('#league_filter_box').css('display', currentBoxDisplay == "none" ? 'grid' : 'none');
                });
                $('#filter_no_skill').on('change', () => {filterOpponents(); saveFilterParameters();});
                $('#filter_with_skill').on('change', () => {filterOpponents(); saveFilterParameters();});
                $('#filter_stun').on('change', () => {filterOpponents(); saveFilterParameters();});
                $('#filter_shield').on('change', () => {filterOpponents(); saveFilterParameters();});
                $('#filter_reflect').on('change', () => {filterOpponents(); saveFilterParameters();});
                $('#filter_execute').on('change', () => {filterOpponents(); saveFilterParameters();});
                $('#filter_fought').on('change', () => {filterOpponents(); saveFilterParameters();});
                $('#filter_with_boosters').on('change', () => {filterOpponents(); saveFilterParameters();});
                $('#filter_no_boosters').on('change', () => {filterOpponents(); saveFilterParameters();});

                $('#filter_with_skill').click(function() {
                    if (!$(this).is(':checked')) {
                        $('#filter_stun').prop('checked', false);
                        $('#filter_shield').prop('checked', false);
                        $('#filter_reflect').prop('checked', false);
                        $('#filter_execute').prop('checked', false);
                    }
                    else {
                        $('#filter_stun').prop('checked', true);
                        $('#filter_shield').prop('checked', true);
                        $('#filter_reflect').prop('checked', true);
                        $('#filter_execute').prop('checked', true);
                    }
                });
                $('#filter_stun').click(function() {
                    if ($(this).is(':checked')) {
                        $('#filter_with_skill').prop('checked', true);
                    }
                    if (!$('#filter_stun').is(':checked') && !$('#filter_shield').is(':checked') && !$('#filter_reflect').is(':checked') && !$('#filter_execute').is(':checked'))
                        $('#filter_with_skill').prop('checked', false);
                });
                $('#filter_shield').click(function() {
                    if ($(this).is(':checked')) {
                        $('#filter_with_skill').prop('checked', true);
                    }
                    if (!$('#filter_stun').is(':checked') && !$('#filter_shield').is(':checked') && !$('#filter_reflect').is(':checked') && !$('#filter_execute').is(':checked'))
                        $('#filter_with_skill').prop('checked', false);
                });
                $('#filter_reflect').click(function() {
                    if ($(this).is(':checked')) {
                        $('#filter_with_skill').prop('checked', true);
                    }
                    if (!$('#filter_stun').is(':checked') && !$('#filter_shield').is(':checked') && !$('#filter_reflect').is(':checked') && !$('#filter_execute').is(':checked'))
                        $('#filter_with_skill').prop('checked', false);
                });
                $('#filter_execute').click(function() {
                    if ($(this).is(':checked')) {
                        $('#filter_with_skill').prop('checked', true);
                    }
                    if (!$('#filter_stun').is(':checked') && !$('#filter_shield').is(':checked') && !$('#filter_reflect').is(':checked') && !$('#filter_execute').is(':checked'))
                        $('#filter_with_skill').prop('checked', false);
                });
            }

            function saveFilterParameters() {
                document.querySelector('#filter_no_skill').checked ? LEAGUE_FILTER.none = 'checked' : LEAGUE_FILTER.none = 'none';
                document.querySelector('#filter_with_skill').checked ? LEAGUE_FILTER.with_skill = 'checked' : LEAGUE_FILTER.with_skill = 'none';
                document.querySelector('#filter_stun').checked ? LEAGUE_FILTER.stun = 'checked' : LEAGUE_FILTER.stun = 'none';
                document.querySelector('#filter_shield').checked ? LEAGUE_FILTER.shield = 'checked' : LEAGUE_FILTER.shield = 'none';
                document.querySelector('#filter_reflect').checked ? LEAGUE_FILTER.reflect = 'checked' : LEAGUE_FILTER.reflect = 'none';
                document.querySelector('#filter_execute').checked ? LEAGUE_FILTER.execute = 'checked' : LEAGUE_FILTER.execute = 'none';
                document.querySelector('#filter_fought').checked ? LEAGUE_FILTER.fought = 'checked' : LEAGUE_FILTER.fought = 'none';
                document.querySelector('#filter_with_boosters').checked ? LEAGUE_FILTER.with_boosters = 'checked' : LEAGUE_FILTER.with_boosters = 'none';
                document.querySelector('#filter_no_boosters').checked ? LEAGUE_FILTER.no_boosters = 'checked' : LEAGUE_FILTER.no_boosters = 'none';
                localStorage.setItem('HHS.leagueFilter', JSON.stringify(LEAGUE_FILTER))
            }

            //CSS
            sheet.insertRule('#league_filter_box {'
                             + 'position: absolute;'
                             + 'grid-template-columns: 1fr 1fr;'
                             + 'background-color: rgba(30, 38, 30, 0.85);'
                             + 'color: #fff;'
                             + 'font-size: 18px;'
                             + 'box-shadow: rgba(255, 255, 255, 0.73) 0px 0px;'
                             + 'border-radius: 8px 10px 10px 8px;'
                             + 'border: 1px solid #ffa23e;'
                             + 'display: none;'
                             + 'left: 60px;'
                             + 'width: max-content;'
                             + 'top: 36px;}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#league_filter_box {'
                             + 'column-gap: 35px;}}'
                            );

            sheet.insertRule(`${mediaDesktop} {`
                             + '#league_filter_box {'
                             + 'column-gap: 25px;}}'
                            );

            sheet.insertRule('#league_filter {'
                             + 'position: absolute;'
                             + 'left: 190px;'
                             + 'height: 26px;'
                             + 'line-height: 0px;'
                             + 'font-size: 16px;'
                             + 'width: max-content;'
                             + 'top: 8px;}'
                            );

            sheet.insertRule('#league_filter_box legend {'
                             + 'color: #ffb827;}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#league_filter_box .filter_type div {'
                             + 'line-height: 40px;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#league_filter_box label {'
                             + 'position: relative;'
                             + 'top: 10px;}}'
                            );

            sheet.insertRule(`${mediaDesktop} {`
                             + '#league_filter_box label {'
                             + 'position: relative;'
                             + 'top: 4px;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#league_filter_box .filter_type div:first-of-type{'
                             + 'margin-top: -15px;}}'
                            );
        }

        function filterOpponents() {
            const opponents = document.querySelectorAll('.data-row.body-row:not(.player-row)');

            let filterNoSkill = document.querySelector('#filter_no_skill').checked ? 0 : 1;
            //let filterWithSkill = document.querySelector('#filter_with_skill').checked ? 0 : 1;
            let filterStun = document.querySelector('#filter_stun').checked ? "stun" : "none";
            let filterShield = document.querySelector('#filter_shield').checked ? "shield" : "none";
            let filterReflect = document.querySelector('#filter_reflect').checked ? "reflect" : "none";
            let filterExecute = document.querySelector('#filter_execute').checked ? "execute" : "none";
            let filterFought = document.querySelector('#filter_fought').checked ? 1 : 0;
            let filterWithBoosters = document.querySelector('#filter_with_boosters').checked ? 0 : 1;
            let filterNoBoosters = document.querySelector('#filter_no_boosters').checked ? 1 : 0;

            for (let opponent of opponents) {
                const tier5 = $(opponent).find('.tier5_skill');
                const fights = $(opponent).find('.result.won').length + $(opponent).find('.result.lost').length;
                const boosters = $(opponent).find('.boosters .slot');
                let boosters_expired = 1;
                for (let booster of boosters) {
                    if (JSON.parse($(booster).attr('data-d')).expiration > 0) boosters_expired = 0;
                }

                let matchesNoSkill = (filterNoSkill == tier5.length);
                //let matchesWithSkill = (tier5.length > 0) ? true : false;
                let matchesStun = (tier5.length > 0) ? (tier5.text().includes(filterStun)) : false;
                let matchesShield = (tier5.length > 0) ? (tier5.text().includes(filterShield)) : false;
                let matchesReflect = (tier5.length > 0) ? (tier5.text().includes(filterReflect)) : false;
                let matchesExecute = (tier5.length > 0) ? (tier5.text().includes(filterExecute)) : false;
                let matchesFought = (filterFought == 1 || (fights < 3 && filterFought == 0));
                let matchesWithBoosters = ((filterWithBoosters == 0) && (boosters_expired == 0));
                let matchesNoBoosters = (filterNoBoosters == 1) && (boosters_expired == 1);

                if (document.querySelector('#filter_no_skill').checked) {
                    $(opponent).removeClass('displayOpponent');
                    $(opponent).removeClass('hiddenOpponent');
                    if ((matchesNoSkill || (matchesStun || matchesShield || matchesReflect || matchesExecute)) && matchesFought && (matchesWithBoosters || matchesNoBoosters)) $(opponent).addClass('displayOpponent');
                    else $(opponent).addClass('hiddenOpponent');
                }
                else {
                    $(opponent).removeClass('displayOpponent');
                    $(opponent).removeClass('hiddenOpponent');
                    if ((matchesNoSkill && (matchesStun || matchesShield || matchesReflect || matchesExecute)) && matchesFought && (matchesWithBoosters || matchesNoBoosters)) $(opponent).addClass('displayOpponent');
                    else $(opponent).addClass('hiddenOpponent');
                }
            }

            stripedLeague();
            $('.league_table').getNiceScroll().resize();

            //CSS
            sheet.insertRule('.hiddenOpponent {'
                             + 'display: none !important;}'
                            );
        }

        function stripedLeague() {
            let opponents = $('.body-row.displayOpponent');
            let isStripe = true;
            for (let opponent of opponents) {
                $(opponent).removeClass('script-stripe');
                $(opponent).removeClass('stripedOpponent')
                if (isStripe) $(opponent).addClass('stripedOpponent')
                isStripe = !isStripe;
            }

            //CSS
            sheet.insertRule('.stripedOpponent {'
                             + 'background-color: rgba(191,40,90,.25) !important;}'
                            );
        }

        function displayLeaguePlayersInfo() {
            let board = document.getElementsByClassName("data-list")[0];
            if(!board) return;
            let opponents = board.getElementsByClassName("data-row body-row");
            let reflectOpponents = JSON.parse(localStorage.getItem('HHS.reflectLeaguePlayers')) || [];
            let shieldOpponents = JSON.parse(localStorage.getItem('HHS.shieldLeaguePlayers')) || [];
            let stunOpponents = JSON.parse(localStorage.getItem('HHS.stunLeaguePlayers')) || [];
            let executeOpponents = JSON.parse(localStorage.getItem('HHS.executeLeaguePlayers')) || [];

            for (let i=0; i<opponents.length; i++) {
                let team_elements = JSON.parse($($(opponents[i]).find('div[column = "team"]')[0].children[0]).attr('synergy-data'));
                let team_theme = [];
                team_elements.forEach((el) => {
                    if(el.team_girls_count >= 3) {
                        team_theme.push(el.element.type);
                    }
                })

                //Display team theme
                if (team_theme.length == 0) team_theme.push('multicolor');
                $(opponents[i]).find('div[column = "team"] .teamThemeLeague').remove();
                $(opponents[i]).find('div[column = "team"]').append($('<span class="teamThemeLeague">'));
                for(let j=0; j<team_theme.length; j++) {
                    let left = 11 - (team_theme.length - 1) * 16 + 27 * j;
                    let icon;
                    if (team_theme[j] == 'multicolor') icon = 'Multicolored';
                    else icon = ELEMENTS_ICON_NAMES[team_theme[j]];
                    $(opponents[i]).find('div[column = "team"] .teamThemeLeague').append($('<img class="teamThemeIcon" style="left: ' + left + 'px; position: absolute;" src="' + window.IMAGES_URL + '/pictures/girls_elements/' + icon + '.png">'));
                }

                //Display team power
                if ($('.data-list :nth-child(' + (i+2) + ')').find('div[column = "team"] .teamPower').length == 0)
                    $('.data-list :nth-child(' + (i+2) + ')').find('div[column = "team"]').append($('<div class="teamPower">' + nThousand(Math.ceil(parseInt(window.opponents_list[i].player.team.total_power, 10))) + '</div>'));

                if (!((window.opponents_list[i]).match_history[(window.opponents_list[i]).player.id_fighter][0] != null && (window.opponents_list[i]).match_history[(window.opponents_list[i]).player.id_fighter][1] != null && (window.opponents_list[i]).match_history[(window.opponents_list[i]).player.id_fighter][2] != null)) {
                    //Display true opponent defense
                    const opp_def = window.opponents_list[i].player.defense;
                    let opponent_defense = opp_def < 10000 ? Math.ceil(opp_def) : (opp_def >= 100000 ? nRounding(opp_def, 0, 1) : nRounding(opp_def, 1, 1));
                    $($('.data-list').find('#player_defence_stat #stats-defense')[i]).text(opponent_defense);

                    //Add booster status
                    if (opponents[i].className.indexOf('player-row') == -1 && $(opponents[i]).find('.boosters .circular-progress').length == 0) {
                        let opponent_boosters = Array.from($(opponents[i]).find('.boosters .slot'));
                        opponent_boosters.forEach((booster) => ($(opponents[i]).find('.boosters ')).append(leagueBoosterStatus(booster)));
                    }
                }

                //Display tier 5 skill
                if ([11, 12, 13, 14].some(index => window.opponents_list[i].player.team.girls[0].skills[index])) {
                    const skill5_girl = window.opponents_list[i].player.team.girls[0].skills;
                    //Stun
                    if (!(skill5_girl[11] == undefined) && $(opponents[i]).find('.tier5_skill').length == 0) {
                        if ($($(opponents[i]).find('.nickname')[0]).attr('id-member') != window.Hero.infos.id) stunOpponents.push($($(opponents[i]).find('.nickname')[0]).attr('id-member'));
                        ($(opponents[i]).find('.boosters ')).after(`<span class="tier5_skill"><span class="stun_icn"></span>${skill5_girl[11].skill.skill_type}/${skill5_girl[11].skill.display_value_text}</span>`)
                    }
                    //Shield
                    else if (!(skill5_girl[12] == undefined) && $(opponents[i]).find('.tier5_skill').length == 0) {
                        if ($($(opponents[i]).find('.nickname')[0]).attr('id-member') != window.Hero.infos.id) shieldOpponents.push($($(opponents[i]).find('.nickname')[0]).attr('id-member'));
                        ($(opponents[i]).find('.boosters ')).after(`<span class="tier5_skill"><span class="shield_icn"></span>${skill5_girl[12].skill.skill_type}/${skill5_girl[12].skill.display_value_text}</span>`)
                    }
                    //Reflect
                    else if (!(skill5_girl[13] == undefined) && $(opponents[i]).find('.tier5_skill').length == 0) {
                        if ($($(opponents[i]).find('.nickname')[0]).attr('id-member') != window.Hero.infos.id) reflectOpponents.push($($(opponents[i]).find('.nickname')[0]).attr('id-member'));
                        ($(opponents[i]).find('.boosters ')).after(`<span class="tier5_skill"><span class="reflect_icn"></span>${skill5_girl[13].skill.skill_type}/${skill5_girl[13].skill.display_value_text}</span>`)
                    }
                    //Execute
                    else if (!(skill5_girl[14] == undefined) && $(opponents[i]).find('.tier5_skill').length == 0) {
                        if ($($(opponents[i]).find('.nickname')[0]).attr('id-member') != window.Hero.infos.id) executeOpponents.push($($(opponents[i]).find('.nickname')[0]).attr('id-member'));
                        ($(opponents[i]).find('.boosters ')).after(`<span class="tier5_skill"><span class="execute_icn"></span>${skill5_girl[14].skill.skill_type}/${skill5_girl[14].skill.display_value_text}</span>`)
                    }
                }

                if (reflectOpponents.includes($($(opponents[i]).find('.nickname')[0]).attr('id-member'))) $($(opponents[i]).find('.nickname')[0]).css('color', '#b968e6');
                else if (shieldOpponents.includes($($(opponents[i]).find('.nickname')[0]).attr('id-member'))) $($(opponents[i]).find('.nickname')[0]).css('color', 'orange');
                else if (stunOpponents.includes($($(opponents[i]).find('.nickname')[0]).attr('id-member'))) $($(opponents[i]).find('.nickname')[0]).css('color', '#14b4d9');
                else if (executeOpponents.includes($($(opponents[i]).find('.nickname')[0]).attr('id-member'))) $($(opponents[i]).find('.nickname')[0]).css('color', '#66cd00');
            }

            localStorage.setItem('HHS.reflectLeaguePlayers', JSON.stringify(reflectOpponents));
            localStorage.setItem('HHS.shieldLeaguePlayers', JSON.stringify(shieldOpponents));
            localStorage.setItem('HHS.stunLeaguePlayers', JSON.stringify(stunOpponents));
            localStorage.setItem('HHS.executeLeaguePlayers', JSON.stringify(executeOpponents));

            try {
                let player_boosters = [];
                if (!(localStorage.getItem('HHS.booster_status') == null || localStorage.getItem('HHS.booster_status') == undefined)) {
                    JSON.parse(localStorage.getItem('HHS.booster_status')).mythic.forEach((booster) => {
                        player_boosters.push(booster.item.identifier);
                    });
                }

                let player_carac_dmg = window.opponents_list.find((el) => el.player.id_fighter == window.Hero.infos.id).player.damage;
                let player_carac_def = window.opponents_list.find((el) => el.player.id_fighter == window.Hero.infos.id).player.team.caracs.defense;

                window.opponents_list.find((el) => el.player.id_fighter == window.Hero.infos.id).player.defense = player_carac_def;
                if (player_boosters.indexOf("MB2") != -1 || player_boosters.indexOf("MB8") != -1) {
                    player_carac_dmg *= 1.15;
                    window.opponents_list.find((el) => el.player.id_fighter == window.Hero.infos.id).player.team.caracs.damage = player_carac_dmg;
                }

                let player_dmg = player_carac_dmg < 10000 ? Math.ceil(player_carac_dmg) : (player_carac_dmg >= 100000 ? nRounding(player_carac_dmg, 0, 1) : nRounding(player_carac_dmg, 1, 1));
                let player_defense = player_carac_def < 10000 ? Math.ceil(player_carac_def) : (player_carac_def >= 100000 ? nRounding(player_carac_def, 0, 1) : nRounding(player_carac_def, 1, 1));
                
                //Display current player stats
                $('.player-row #player_attack_stat #stats-damage').text(player_dmg);
                $('.player-row #player_defence_stat #stats-defense').text(player_defense);

                //Display sim score
                if (loadSetting('simLeagueBoardFight')) {
                    if (localStorage.getItem('HHS.simLeagueBoardFight') == undefined) localStorage.setItem('HHS.simLeagueBoardFight', true);

                    //CSS
                    sheet.insertRule('#leagues .league_content .league_table .data-list .body-row .go_pre_battle {'
                                     + 'opacity: 0;}'
                                    );

                    sheet.insertRule('#leagues .league_content .league_table .data-list .data-row .data-column[column="can_fight"] .blue_button_L, #leagues .league_content .league_table .data-list .data-row .head-column[column="can_fight"] .blue_button_L {'
                                     + 'padding: 0 !important;}'
                                    );

                    sheet.insertRule('#leagues .league_content.hidden_girl .league_table .data-list .data-row .data-column[column="boosters"], #leagues .league_content.hidden_girl .league_table .data-list .data-row .head-column[column="boosters"] {'
                                     + 'min-width: 14.5rem !important;}'
                                    );

                    sheet.insertRule('#leagues .league_content .league_table .data-list .data-row .data-column[column="can_fight"], #leagues .league_content .league_table .data-list .data-row .head-column[column="can_fight"] {'
                                     + 'min-width: 4rem !important;}'
                                    );

                    if ($('.head-column[column=can_fight]').length) {
                        $('.head-column[column=can_fight] > span')[0].firstChild.data = "SIM";
                    }

                    for (let i=0; i<opponents.length; i++) {
                        if (window.opponents_list[i].player.id_fighter != window.Hero.infos.id && !((window.opponents_list[i]).match_history[(window.opponents_list[i]).player.id_fighter][0] != null && (window.opponents_list[i]).match_history[(window.opponents_list[i]).player.id_fighter][1] != null && (window.opponents_list[i]).match_history[(window.opponents_list[i]).player.id_fighter][2] != null)) {
                            if($($('.body-row .data-column[column=can_fight]')[i]).find('.matchRating').length == 0) {
                                $($('.body-row .data-column[column=can_fight]')[i]).append(calcSimResults(window.opponents_list[i]));
                            }
                        }
                    }

                    sortLeagueSimScore();
                }
            } catch {}

            collectLeagueOpponents();

            function calcSimResults(opponentData) {
                let playerData = window.opponents_list.find((el) => el.player.id_fighter == window.Hero.infos.id).player;

                let playerAtk = playerData.team.caracs.damage;
                let playerEgo = playerData.team.caracs.ego;
                let playerDef = playerData.team.caracs.defense;
                let playerCrit = playerData.team.caracs.chance;

                let playerElements = [];
                playerData.team.theme_elements.forEach((el) => playerElements.push(el.type));

                const playerBonuses = {
                    critDamage: playerData.team.synergies.find(({element: {type}})=>type == 'fire').bonus_multiplier,
                    critChance: playerData.team.synergies.find(({element: {type}})=>type == 'stone').bonus_multiplier,
                    defReduce: playerData.team.synergies.find(({element: {type}})=>type == 'sun').bonus_multiplier,
                    healOnHit: playerData.team.synergies.find(({element: {type}})=>type == 'water').bonus_multiplier
                };

                let opponentAtk = opponentData.player.damage;
                let opponentEgo = opponentData.player.remaining_ego;
                let opponentDef = opponentData.player.defense;
                let opponentCrit = opponentData.player.chance;

                let opponentElements = [];
                opponentData.player.team.theme_elements.forEach((el) => opponentElements.push(el.type));

                const opponentBonuses = {
                    critDamage: opponentData.player.team.synergies.find(({element: {type}})=>type == 'fire').bonus_multiplier,
                    critChance: opponentData.player.team.synergies.find(({element: {type}})=>type == 'stone').bonus_multiplier,
                    defReduce: opponentData.player.team.synergies.find(({element: {type}})=>type == 'sun').bonus_multiplier,
                    healOnHit: opponentData.player.team.synergies.find(({element: {type}})=>type == 'water').bonus_multiplier
                };

                const dominanceBonuses = calculateDominationBonuses(playerElements, opponentElements);

                let player = {
                    hp: playerEgo * (1+dominanceBonuses.player.ego),
                    atk: playerAtk * (1+dominanceBonuses.player.attack),
                    adv_def: opponentDef,
                    critchance: calculateCritChanceShare(playerCrit, opponentCrit) + dominanceBonuses.player.chance + playerBonuses.critChance,
                    bonuses: playerBonuses,
                    tier4: calculateTier4SkillValue(playerData.team.girls),
                    tier5: calculateTier5SkillValue(playerData.team.girls)
                };

                let opponent = {
                    hp: opponentEgo,
                    atk: opponentAtk,
                    adv_def: playerDef * (1-opponentBonuses.defReduce),
                    critchance: calculateCritChanceShare(opponentCrit, playerCrit) + dominanceBonuses.opponent.chance + opponentBonuses.critChance,
                    name: opponentData.player.nickname,
                    bonuses: opponentBonuses,
                    tier4: calculateTier4SkillValue(opponentData.player.team.girls),
                    tier5: calculateTier5SkillValue(opponentData.player.team.girls)
                };

                const {points: calc, win, scoreClass} = calculateBattleProbabilities(player, opponent);

                let probabilityTooltip = `<table class='probabilityTable'>`;
                let expectedValue = 0;
                const pointGrade=['#fff','#fff','#fff','#ff2f2f','#fe3c25','#fb4719','#f95107','#f65b00','#f26400','#ed6c00','#e97400','#e37c00','#de8400','#d88b00','#d19100','#ca9800','#c39e00','#bba400','#b3aa00','#aab000','#a1b500','#97ba00','#8cbf00','#81c400','#74c900','#66cd00'];
                for (let i=25; i>=3; i--) {
                    if (calc[i]) {
                        const isW = i>=15
                        probabilityTooltip += `<tr style='color:${isW?pointGrade[25]:pointGrade[3]};' data-tint='${isW?'w':'l'}'><td>${i}</td><td>${(100*calc[i]).toFixed(2)}%</td></tr>`;
                        expectedValue += i*calc[i];
                    }
                }
                probabilityTooltip += `<tr class='${scoreClass}'><td>${window.GT.design.leagues_won_letter}</td><td>${(100*win).toFixed(2)}%</td></tr>`;
                probabilityTooltip += '</table>';

                const $rating = $(`<div class="matchRating" tooltip="" style="color:${pointGrade[Math.round(expectedValue)]};" hh_title="${probabilityTooltip}">${(100*win).toFixed(2)}%<BR> ${expectedValue.toFixed(2)}</div>`)

                opponentData.sim_result = $rating;
                opponentData.can_fight = expectedValue;

                return $rating
            }

            function leagueBoosterStatus(booster) {
                const CIRCULAR_THRESHOLDS = {
                    1: 'green',
                    0.5: 'yellow',
                    0.2: 'red'
                };

                const buildProgressWrapper = (current, max) => {
                    const percentage = Math.min(current/max, 1)
                    const firstHalf = Math.min(percentage, 0.5) * 2
                    const secondHalf = Math.max(percentage - 0.5, 0) * 2

                    let colorClass = ''
                    let flashingClass = ''

                    //if (percentage > 0) {
                    Object.entries(CIRCULAR_THRESHOLDS).forEach(([threshold, className]) => {
                        if (percentage <= threshold) {
                            colorClass = className
                        }
                    })

                    if (percentage <= 0.0035 && percentage > 0) {
                        flashingClass = 'flashing'
                    }

                    if (percentage <= 0) {
                        flashingClass = 'expired'
                    }
                    //}

                    const $wrapper = $(`
                            <div class="circular-progress">
                                <div class="circle">
                                    <div class="circle-bar left ${flashingClass}">
                                        <div class="progress ${colorClass}" style="transform: rotate(${180 * secondHalf}deg)"></div>
                                    </div>
                                    <div class="circle-bar right ${flashingClass}">
                                        <div class="progress ${colorClass}" style="transform: rotate(${180 * firstHalf}deg)"></div>
                                    </div>
                                </div>
                            </div>
                        `)
                    return $wrapper
                }

                const booster_data = JSON.parse($(booster).attr('data-d'));
                let booster_status = buildProgressWrapper(booster_data.expiration, parseInt(booster_data.item.duration, 10)*60);
                booster_status.prepend($(booster));

                return booster_status;
            }

            //CSS
            sheet.insertRule(`${mediaDesktop} {`
                             + '.teamThemeIcon {'
                             + 'z-index: 0;'
                             + 'height: 26px !important;'
                             + 'width: 26px !important;'
                             + 'top: 0px !important;'
                             + 'border: none !important;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '.teamThemeIcon {'
                             + 'z-index: 0;'
                             + 'height: 27px !important;'
                             + 'width: 27px !important;'
                             + 'top: 0px !important;'
                             + 'border: none !important;}}'
                            );

            sheet.insertRule('#leagues .league_content .league_table .data-list .data-row .data-column[column="team"] .button_team_synergy, #leagues .league_content .league_table .data-list .data-row .head-column[column="team"] .button_team_synergy {'
                             + 'left: 20px !important;'
                             + 'top: -6px;'
                             + 'background-image: none;'
                             + 'z-index: 1;}'
                            );

            sheet.insertRule('.teamPower {'
                             + 'font-size: 12px;'
                             + 'position: relative;'
                             + 'top: 15px;'
                             + 'left: -16px;}'
                            );

            sheet.insertRule('.tier5_skill {'
                             + 'position: relative;'
                             + 'top: 12px;'
                             + 'left: -82px;'
                             + 'width: max-content;'
                             + 'font-size: 14px;}'
                            );

            sheet.insertRule('.tier5_skill > .active_skills_icn, .tier5_skill > .stun_icn, .tier5_skill > .shield_icn, .tier5_skill > .reflect_icn, .tier5_skill > .execute_icn {'
                             + 'position: absolute;'
                             + 'background-position: left;'
                             + 'background-size: 17px !important;'
                             + 'left: -21px;}'
                            );

            sheet.insertRule('#leagues .boosters {'
                             + 'z-index: 0;'
                             + 'display: flex;'
                             + 'flex-direction: row;}'
                            );

            sheet.insertRule('#leagues .circular-progress {'
                             + 'margin-right: 2px;'
                             + 'position: relative;'
                             + 'height: 24px;'
                             + 'width: 24px;}'
                            );

            sheet.insertRule('#leagues .circular-progress .green {'
                             + 'background-color: #01d10b;}'
                            );

            sheet.insertRule('#leagues .circular-progress .yellow {'
                             + 'background-color: #ffc400;}'
                            );

            sheet.insertRule('#leagues .circular-progress .red {'
                             + 'background-color: #ff0000;}'
                            );

            sheet.insertRule('#leagues .circular-progress .slot {'
                             + 'position: absolute !important;'
                             + 'height: 20px !important;'
                             + 'width: 20px !important;'
                             + 'top: 2px !important;'
                             + 'left: 2px !important;'
                             + 'border-width: 0px !important;'
                             + 'z-index: 6 !important;}'
                            );

            sheet.insertRule('#leagues .slot.size_xs {'
                             +'border-radius: 0 !important;}'
                            );

            sheet.insertRule('#leagues .circular-progress .slot.empty {'
                             + 'cursor: inherit !important;}'
                            );

            sheet.insertRule('#leagues .circular-progress .empty + .circle {'
                             + 'box-shadow: none;}'
                            );

            sheet.insertRule('#leagues .circular-progress .empty + .circle .circle-bar {'
                             + 'background-color: transparent;}'
                            );

            sheet.insertRule('#leagues .circular-progress .circle {'
                             + 'height: 100%;'
                             + 'width: 100%;'
                             + 'box-shadow: 0px 0px 5px #000, 0px 0px 4px #000, 0px 0px 3px #000, 0px 0px 2px #000;}'
                            );

            sheet.insertRule('#leagues .circular-progress .circle-bar {'
                             + 'position: absolute;'
                             + 'height: 100%;'
                             + 'width: 100%;'
                             + 'background-color: #000000bf;'
                             + 'clip-path: polygon(0% 0%, 0% 100%, 50% 100%, 50% 0%);'
                             + 'overflow: hidden;}'
                            );

            sheet.insertRule('#leagues .circular-progress .circle-bar.flashing {'
                             + 'animation-name: flashing-background;'
                             + 'animation-duration: 3s;'
                             + 'animation-iteration-count: infinite;}'
                            );

            sheet.insertRule('@keyframes flashing-background {'
                             + '0% {background-color: #000000bf;}'
                             + '50% {background-color: #ff0000;}'
                             + '100% {background-color: #000000bf;}}'
                            );

            sheet.insertRule('#leagues .circular-progress .circle-bar.expired {'
                             + 'z-index: 10;'
                             + 'animation-name: expired-background;'
                             + 'animation-duration: 3s;'
                             + 'animation-iteration-count: infinite;}'
                            );

            sheet.insertRule('@keyframes expired-background {'
                             + '0% {background-color: #000000bf;}'
                             + '50% {background-color: rgba(255,0,0,0.75);}'
                             + '100% {background-color: #000000bf;}}'
                            );

            sheet.insertRule('#leagues .circular-progress .circle-bar .progress {'
                             + 'position: absolute;'
                             + 'height: 200%;'
                             + 'width: 200%;'
                             + 'top: -50%;'
                             + 'left: -50%;'
                             + 'clip-path: polygon(50% -50%, 150% -50%, 150% 150%, 50% 150%);}'
                            );

            sheet.insertRule('#leagues .circular-progress .circle-bar.right {'
                             + 'transform: rotate(180deg);'
                             + 'z-index: 3;}'
                            );

            sheet.insertRule('#leagues .circular-progress .circle-bar.left .progress {'
                             + 'z-index: 1;}'
                            );


            if (localStorage.getItem('HHPlusPlusConfig')) {
                if (JSON.parse(localStorage.getItem('HHPlusPlusConfig')).st_leagueTableCompressed) {
                    sheet.insertRule(`${mediaDesktop} {`
                                     + '.teamThemeIcon {'
                                     + 'top: 0px !important;}}'
                                    );

                    sheet.insertRule(`${mediaDesktop} {`
                                     + '.teamThemeIcon:nth-child(1) {'
                                     + 'margin-left: -5px !important;}}'
                                    );

                    sheet.insertRule(`${mediaDesktop} {`
                                     + '.teamThemeIcon:nth-child(2) {'
                                     + 'margin-left: 12px !important;}}'
                                    );

                    sheet.insertRule(`${mediaDesktop} {`
                                     + '.classLeague {'
                                     + 'margin-left: 35px !important;}}'
                                    );
                }
            }

            sheet.insertRule('#leagues .league_content .league_table .data-list .data-row .head-column[column="sim_score"] {'
                             + 'display: flex;'
                             + 'align-items: center;'
                             + 'justify-content: center;'
                             + 'min-width: 5.5rem;}'
                            );

            sheet.insertRule('.matchRating {'
                             + 'position: absolute;'
                             + 'text-align: center;'
                             + 'width: 4rem;'
                             + 'margin-right: 10px;'
                             + 'text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000;'
                             + 'font-size: 12px;}'
                            );

            sheet.insertRule('.probabilityTable tr {'
                             + 'line-height: 16px;'
                             + 'color: #fff;}'
                            );

            sheet.insertRule('.probabilityTable tr:nth-of-type(odd) {'
                             + 'background-color: rgba(0,0,0,0.2);}'
                            );

            sheet.insertRule('.probabilityTable tr:nth-of-type(even)[data-tint=w] {'
                             + 'background-color: #66cd0028;}'
                            );

            sheet.insertRule('.probabilityTable tr:nth-of-type(even)[data-tint=l] {'
                             + 'background-color: #ff2f2f28;}'
                            );

            sheet.insertRule('.probabilityTable .plus {'
                             + 'color: #66CD00;}'
                            );

            sheet.insertRule('.probabilityTable .minus {'
                             + 'color: #FF2F2F;}'
                            );

            sheet.insertRule('.probabilityTable .close {'
                             + 'color: #FFA500;}'
                            );

            sheet.insertRule('.winProb {'
                             + 'text-align: center; '
                             + 'text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000; '
                             + 'line-height: 17px; '
                             + 'font-size: 16px;}'
                            );

            sheet.insertRule('#leagues .league_content .league_table .data-list .data-row .head-column[column="team"] {'
                             + 'overflow: visible !important;'
                             + 'cursor: pointer !important;}'
                            );

            sheet.insertRule('#leagues .league_content .league_table .data-list .data-row .head-column[column="team"] > span > span {'
                             + 'display: inline-block !important;}'
                            );
        }

        function collectLeagueOpponents() {
            let opponents_id = [];
            Array.from($('.body-row:not(.player-row)')).forEach((el) => {
                if(($(el).find('.result.won').length + $(el).find('.result.lost').length) < 3) opponents_id.push($(el).find('.nickname').attr('id-member'));
            });
            localStorage.setItem('HHS.leagueOppId', JSON.stringify(opponents_id));
        }

        function sortLeagueSimScore() {
            let tbody = document.querySelector('.data-list');
            let tr_player = tbody.querySelectorAll('.data-row.body-row');

            const compare = (asc) => (row1, row2) => {
                const tdValue = row => row.lastElementChild.lastChild.lastChild == undefined ? 0 : parseFloat(row.lastElementChild.lastChild.lastChild.nodeValue)
                const tri = (v1, v2) => v1 - v2;
                return tri(tdValue(asc ? row1 : row2), tdValue(asc ? row2 : row1));
            };

            if (document.querySelector('.data-column.head-column[column="can_fight"] > span > span').className == "upArrow_mix_icn") {
                let classe = Array.from(tr_player).sort(compare(true));
                classe.forEach(tr => tbody.appendChild(tr));
            }
            else if (document.querySelector('.data-column.head-column[column="can_fight"] > span > span').className == "downArrow_mix_icn") {
                let classe = Array.from(tr_player).sort(compare(false));
                classe.forEach(tr => tbody.appendChild(tr));
            }
        }

        function sortLeagueTeamPower() {
            let tbody = document.querySelector('.data-list');
            const th_name = document.querySelector('.data-column.head-column[column="team"]');
            let tr_player = tbody.querySelectorAll('.data-row.body-row');

            const compare = (asc) => (row1, row2) => {
                const tdValue = row => parseInt(Array.from(row.children).find((el) => el.attributes.column.nodeValue == "team").lastElementChild.innerText.replace(/\s/g, ''), 10);
                const tri = (v1, v2) => v1 - v2;
                return tri(tdValue(asc ? row1 : row2), tdValue(asc ? row2 : row1));
            };

            if (localStorage.getItem('leaderboard_sorting')  == '{"column":"team","sorting":"ASC"}') {
                document.querySelector('.data-column.head-column[column="team"] > span > span').className = "upArrow_mix_icn";
                let classe = Array.from(tr_player).sort(compare(true));
                classe.forEach(tr => tbody.appendChild(tr));
            }
            else if (localStorage.getItem('leaderboard_sorting')  == '{"column":"team","sorting":"DESC"}') {
                asc = false;
                document.querySelector('.data-column.head-column[column="team"] > span > span').className = "downArrow_mix_icn";
                let classe = Array.from(tr_player).sort(compare(false));
                classe.forEach(tr => tbody.appendChild(tr));
            }

            collectLeagueOpponents();

            function leagueTeamPowerEvent() {
                tbody = document.querySelector('.data-list');
                tr_player = tbody.querySelectorAll('.data-row.body-row');
                let newSort = (localStorage.getItem('leaderboard_sorting')  == '{"column":"team","sorting":"ASC"}') ? 0 : 1;
                newSort = (newSort + 1) % 2;

                let listSort = $('.head-column:not([column="team"])');
                for (let sort of listSort) {
                    let arrow = sort.lastElementChild.lastElementChild;
                    if (arrow.className != "upDownArrows_mix_icn") arrow.className = "upDownArrows_mix_icn";
                    sort.removeAttribute('sorting');
                }

                switch (newSort) {
                    case 0:
                        document.querySelector('.data-column.head-column[column="team"] > span > span').className = "upArrow_mix_icn";
                        localStorage.setItem('leaderboard_sorting', JSON.stringify({"column":"team","sorting":"ASC"}));
                        classe = Array.from(tr_player).sort(compare(true));
                        classe.forEach(tr => tbody.appendChild(tr));
                        collectLeagueOpponents();
                        stripedLeague();
                        break;
                    case 1:
                        document.querySelector('.data-column.head-column[column="team"] > span > span').className = "downArrow_mix_icn";
                        localStorage.setItem('leaderboard_sorting', JSON.stringify({"column":"team","sorting":"DESC"}));
                        classe = Array.from(tr_player).sort(compare(false));
                        classe.forEach(tr => tbody.appendChild(tr));
                        collectLeagueOpponents();
                        stripedLeague();
                        break;
                }
            }

            th_name.addEventListener('click', () => {leagueTeamPowerEvent()});
        }

        //Save results of the league
        function saveVictories() {
            let leagueDateInit = (DST == true) ? 11*3600 : 12*3600;

            let current_date_ts = Math.floor(new Date().getTime()/1000);
            let date_end_league = leagueDateInit + Math.ceil((current_date_ts - leagueDateInit)/604800)*604800;

            let time_results = localStorage.getItem('HHS.leagueTime');
            if (!time_results) {
                time_results = date_end_league;
                localStorage.setItem('HHS.leagueTime', time_results);
            }
            //Next Thursday after DST at 12:00 UTC (14:00 Paris time)
            if (time_results == 1712232000) {
                time_results = 1712228400;
                localStorage.setItem('HHS.leagueTime', time_results);
            }

            //Next Thursday after non-DST at 11:00 UTC (12:00 Paris time)
            if (time_results == 1698922800) {
                time_results = 1698926400;
                localStorage.setItem('HHS.leagueTime', time_results);
            }

            if (current_date_ts > time_results) {
                localStorage.setItem('HHS.oldLeagueTime', localStorage.getItem('HHS.leagueTime'));
                localStorage.setItem('HHS.oldLeaguePlayers', localStorage.getItem('HHS.leaguePlayers'));
                localStorage.setItem('HHS.oldLeagueScore', localStorage.getItem('HHS.leagueScore'));
                localStorage.setItem('HHS.oldLeagueVictories', localStorage.getItem('HHS.leagueVictories'));
                localStorage.setItem('HHS.oldLeagueDefeats', localStorage.getItem('HHS.leagueDefeats'));
                localStorage.setItem('HHS.oldLeagueLvl', localStorage.getItem('HHS.leagueLvl'));
                localStorage.setItem('HHS.leagueTime', date_end_league);
                localStorage.removeItem('HHS.leagueScore');
                localStorage.removeItem('HHS.reflectLeaguePlayers');
                localStorage.removeItem('HHS.shieldLeaguePlayers');
                localStorage.removeItem('HHS.stunLeaguePlayers');
                localStorage.removeItem('HHS.executeLeaguePlayers');
            }

            calculateVictories();
        }

        function calculateVictories() {
            let nb_opponents = $('.body-row:not(.player-row)').length ;
            localStorage.setItem('HHS.leaguePlayers', nb_opponents);

            let tot_victory = $('.body-row .data-column .result.won').length ;
            localStorage.setItem('HHS.leagueVictories', tot_victory);
            let tot_defeat = $('.body-row .data-column .result.lost').length ;
            localStorage.setItem('HHS.leagueDefeats', tot_defeat);
            let tot_notPlayed = 3*nb_opponents - tot_victory - tot_defeat;

            let lvl_data = Array.from($('.body-row .data-column[column="level"]'));
            let lvl = Array.from(lvl_data, (el) => parseInt(el.innerText, 10));
            let lvl_min = Math.min(...lvl);
            let lvl_max = Math.max(...lvl);

            let lvl_sum = 0;
            lvl.forEach((el) => lvl_sum += el);
            let lvl_avg = parseInt(lvl_sum / lvl.length, 10);

            localStorage.setItem('HHS.leagueLvl', JSON.stringify({min: lvl_min, max: lvl_max, avg: lvl_avg}));

            $('span.possibleChallenges span.scriptLeagueInfoTooltip.possibleChallengesTooltip').append('<span id="leagueStats"><u>' + labels.current_league + '</u>'
                                                                                                       + '<br />'
                                                                                                       + '<BR>' + labels.opponents + ' : ' + nb_opponents
                                                                                                       + '<BR>' + window.GT.design.level_range + ' : ' + lvl_min + ' ... [' + lvl_avg + '] ... ' + lvl_max
                                                                                                       + '<BR>' + labels.victories + ' : ' + tot_victory + ' / ' + 3*nb_opponents
                                                                                                       + '<BR>' + labels.defeats + ' : ' + tot_defeat + ' / ' + 3*nb_opponents
                                                                                                       + '<BR>' + labels.notPlayed + ' : ' + tot_notPlayed + ' / ' + 3*nb_opponents
                                                                                                       + '</span>');

            let old_nb_opponents = localStorage.getItem('HHS.oldLeaguePlayers') || 0;
            let old_lvl_min = localStorage.getItem('HHS.oldLeagueLvl') ? JSON.parse(localStorage.getItem('HHS.oldLeagueLvl')).min : 0;
            let old_lvl_max = localStorage.getItem('HHS.oldLeagueLvl') ? JSON.parse(localStorage.getItem('HHS.oldLeagueLvl')).max : 0;
            let old_lvl_avg = localStorage.getItem('HHS.oldLeagueLvl') ? JSON.parse(localStorage.getItem('HHS.oldLeagueLvl')).avg : 0;
            let old_score = JSON.parse(localStorage.getItem('HHS.oldLeagueScore')) || {};
            let old_tot_victory = localStorage.getItem('HHS.oldLeagueVictories') ? localStorage.getItem('HHS.oldLeagueVictories') : 0;
            let old_tot_defeat = localStorage.getItem('HHS.oldLeagueDefeats') ? localStorage.getItem('HHS.oldLeagueDefeats') : 0;
            let old_tot_notPlayed = 3*old_nb_opponents - old_tot_victory - old_tot_defeat;
            let old_points = old_score.points || 0;
            let old_avg = old_score.avg || 0;

            const options = {year: 'numeric', month: 'short', day: 'numeric'};
            let old_date_end_league = new Date(localStorage.getItem('HHS.oldLeagueTime')*1000).toLocaleDateString(undefined, options);

            if (localStorage.getItem('HHS.oldLeagueTime')) {
                $('span.possibleChallenges span.scriptLeagueInfoTooltip.possibleChallengesTooltip').append('<span id="oldLeagueStats"><BR>_______________________'
                                                                                                           + '<BR><BR>' + labels.league_finished + old_date_end_league
                                                                                                           + '<br />'
                                                                                                           + '<BR>' + labels.opponents + ' : ' + old_nb_opponents
                                                                                                           + '<BR>' + window.GT.design.level_range + ' : ' + old_lvl_min + ' ... [' + old_lvl_avg + '] ... ' + old_lvl_max
                                                                                                           + '<BR>' + labels.victories + ' : ' + old_tot_victory + ' / ' + 3*old_nb_opponents
                                                                                                           + '<BR>' + labels.defeats + ' : ' + old_tot_defeat + ' / ' + 3*old_nb_opponents
                                                                                                           + '<BR>' + labels.notPlayed + ' : ' + old_tot_notPlayed + ' / ' + 3*old_nb_opponents
                                                                                                           + '<BR>' + labels.leaguePoints + ' : ' + nThousand(old_points)
                                                                                                           + '<BR>' + labels.avg + ' : ' + nThousand(old_avg)
                                                                                                           + '</span>');
            }
        }

        saveVictories();
        displayLeaguePlayersInfo();
        leagueFilter();
        sortLeagueTeamPower();
        stripedLeague();

        let observeCallback = function() {
            displayLeaguePlayersInfo();
            filterOpponents();
            stripedLeague();
        }

        let childrenObserved = $('.data-row.head-row')[0].children;
        for (let child of childrenObserved) {
            if(child.attributes.column.nodeValue != "team") child.addEventListener('click', () => {observeCallback()});
        }

        //CSS
        sheet.insertRule('.record_league #last_week {'
                         + 'position: relative;'
                         + 'left: -55px;}'
                        );

        sheet.insertRule('.record_league #this_week {'
                         + 'position: relative;'
                         + 'left: -125px;}'
                        );
    }
}

function moduleLeagueOpponentsShortcut() {
    try{
        let opponents_id = JSON.parse(localStorage.getItem('HHS.leagueOppId'));
        const current_id = window.location.href.substring(window.location.href.indexOf('=') + 1);
        const previous_id = opponents_id[(opponents_id.length + opponents_id.indexOf(current_id) - 1) % (opponents_id.length)];
        const next_id = opponents_id[(opponents_id.indexOf(current_id) + 1) % (opponents_id.length)];

        $('.battle-buttons-row').prepend('<a href="' + transformNutakuURL('/leagues-pre-battle.html?id_opponent=' + previous_id) + '" class="back_button_s" id="previous_league_opp"></a>');
        $('.battle-buttons-row').append('<a href="' + transformNutakuURL('/leagues-pre-battle.html?id_opponent=' + next_id) + '" class="back_button_s" id="next_league_opp"></a>');

        //CSS
        sheet.insertRule('#previous_league_opp, #next_league_opp {'
                         + 'position: relative;'
                         + 'background-size: 38px;'
                         + 'background-position: center;'
                         + 'background-repeat: no-repeat;}'
                        );

        sheet.insertRule('#previous_league_opp {'
                         + 'background-image: url(https://cdn-icons-png.flaticon.com/64/2879/2879564.png) !important;'
                         + 'left: -4% !important;}'
                        );

        sheet.insertRule('#next_league_opp {'
                         + 'background-image: url(https://cdn-icons-png.flaticon.com/64/2879/2879593.png) !important;'
                         + 'left: 5% !important;}'
                        );

        sheet.insertRule('.battle-buttons-row {'
                         + 'width: 106% !important;'
                         + 'margin-left: -16px;'
                         + 'justify-content: space-evenly !important;}'
                        );
    } catch{}
}

function moduleHideLeaguex3Button() {
    $('.league-multiple-battle-button').remove();
}

/* ============
	LEAGUE SIM
   ============ */

function moduleLeagueSim() {
    function calculatePower() {
        let playerAtk = window.hero_data.damage;
        let playerEgo = window.hero_data.remaining_ego;
        let playerDef = window.hero_data.defense;
        let playerCrit = window.hero_data.chance;

        let playerElements = [];
        window.hero_data.team.theme_elements.forEach((el) => playerElements.push(el.type));

        const playerBonuses = {
            critDamage: window.hero_data.team.synergies.find(({element: {type}})=>type == 'fire').bonus_multiplier,
            critChance: window.hero_data.team.synergies.find(({element: {type}})=>type == 'stone').bonus_multiplier,
            defReduce: window.hero_data.team.synergies.find(({element: {type}})=>type == 'sun').bonus_multiplier,
            healOnHit: window.hero_data.team.synergies.find(({element: {type}})=>type == 'water').bonus_multiplier
        };

        let opponentAtk = window.opponent_fighter.player.damage;
        let opponentEgo = window.opponent_fighter.player.remaining_ego;
        let opponentDef = window.opponent_fighter.player.defense;
        let opponentCrit = window.opponent_fighter.player.chance;

        let opponentElements = [];
        window.opponent_fighter.player.team.theme_elements.forEach((el) => opponentElements.push(el.type));

        const opponentBonuses = {
            critDamage: window.opponent_fighter.player.team.synergies.find(({element: {type}})=>type == 'fire').bonus_multiplier,
            critChance: window.opponent_fighter.player.team.synergies.find(({element: {type}})=>type == 'stone').bonus_multiplier,
            defReduce: window.opponent_fighter.player.team.synergies.find(({element: {type}})=>type == 'sun').bonus_multiplier,
            healOnHit: window.opponent_fighter.player.team.synergies.find(({element: {type}})=>type == 'water').bonus_multiplier
        };

        const dominanceBonuses = calculateDominationBonuses(playerElements, opponentElements);

        let player = {
            hp: playerEgo,
            atk: playerAtk,
            adv_def: opponentDef,
            critchance: calculateCritChanceShare(playerCrit, opponentCrit) + dominanceBonuses.player.chance + playerBonuses.critChance,
            bonuses: playerBonuses,
            tier4: calculateTier4SkillValue(window.hero_data.team.girls),
            tier5: calculateTier5SkillValue(window.hero_data.team.girls)
        };

        let opponent = {
            hp: opponentEgo,
            atk: opponentAtk,
            adv_def: playerDef,
            critchance: calculateCritChanceShare(opponentCrit, playerCrit) + dominanceBonuses.opponent.chance + opponentBonuses.critChance,
            name: window.opponent_fighter.player.nickname,
            bonuses: opponentBonuses,
            tier4: calculateTier4SkillValue(window.opponent_fighter.player.team.girls),
            tier5: calculateTier5SkillValue(window.opponent_fighter.player.team.girls)
        };

        //Display tier 5 skill
        //Player team
        if ([11, 12, 13, 14].some(index => window.hero_data.team.girls[0].skills[index])) {
            const skill5_girl = window.hero_data.team.girls[0].skills;
            //Stun
            if (!(skill5_girl[11] == undefined)) {
                $('#pre-battle .player_team_block.battle_hero .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[11].skill.skill_type}/${skill5_girl[11].skill.display_value_text}</span>`)
            }
            //Shield
            else if (!(skill5_girl[12] == undefined)) {
                $('#pre-battle .player_team_block.battle_hero .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[12].skill.skill_type}/${skill5_girl[12].skill.display_value_text}</span>`)
            }
            //Reflect
            else if (!(skill5_girl[13] == undefined)) {
                $('#pre-battle .player_team_block.battle_hero .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[13].skill.skill_type}/${skill5_girl[13].skill.display_value_text}</span>`)
            }
            //Execute
            else if (!(skill5_girl[14] == undefined)) {
                $('#pre-battle .player_team_block.battle_hero .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[14].skill.skill_type}/${skill5_girl[14].skill.display_value_text}</span>`)
            }
        }

        //Opponent team
        if ([11, 12, 13, 14].some(index => window.opponent_fighter.player.team.girls[0].skills[index])) {
            const skill5_girl = window.opponent_fighter.player.team.girls[0].skills;
            //Stun
            if (!(skill5_girl[11] == undefined)) {
                $('#pre-battle .player_team_block.opponent .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[11].skill.skill_type}/${skill5_girl[11].skill.display_value_text}</span>`)
            }
            //Shield
            else if (!(skill5_girl[12] == undefined)) {
                $('#pre-battle .player_team_block.opponent .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[12].skill.skill_type}/${skill5_girl[12].skill.display_value_text}</span>`)
            }
            //Reflect
            else if (!(skill5_girl[13] == undefined)) {
                $('#pre-battle .player_team_block.opponent .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[13].skill.skill_type}/${skill5_girl[13].skill.display_value_text}</span>`)
            }
            //Execute
            else if (!(skill5_girl[14] == undefined)) {
                $('#pre-battle .player_team_block.opponent .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[14].skill.skill_type}/${skill5_girl[14].skill.display_value_text}</span>`)
            }
        }

        const {points: calc, win, scoreClass} = calculateBattleProbabilities(player, opponent);

        let probabilityTooltip = `<table class='probabilityTable'>`;
        let expectedValue = 0;
        const pointGrade=['#fff','#fff','#fff','#ff2f2f','#fe3c25','#fb4719','#f95107','#f65b00','#f26400','#ed6c00','#e97400','#e37c00','#de8400','#d88b00','#d19100','#ca9800','#c39e00','#bba400','#b3aa00','#aab000','#a1b500','#97ba00','#8cbf00','#81c400','#74c900','#66cd00'];
        for (let i=25; i>=3; i--) {
            if (calc[i]) {
                const isW = i>=15
                probabilityTooltip += `<tr style='color:${isW?pointGrade[25]:pointGrade[3]};' data-tint='${isW?'w':'l'}'><td>${i}</td><td>${(100*calc[i]).toFixed(2)}%</td></tr>`;
                expectedValue += i*calc[i];
            }
        }
        probabilityTooltip += `<tr class='${scoreClass}'><td>${window.GT.design.leagues_won_letter}</td><td>${(100*win).toFixed(2)}%</td></tr>`;
        probabilityTooltip += '</table>';

        const $rating = $(`<div class="matchRating" tooltip="" style="color:${pointGrade[Math.round(expectedValue)]};" hh_title="${probabilityTooltip}">${(100*win).toFixed(2)}% / ${expectedValue.toFixed(2)}</div>`)
        $('#pre-battle .player_team_block.opponent .average-lvl').after($rating);
    }

    calculatePower();

    //CSS
    sheet.insertRule(`${mediaDesktop} {`
                     + '.matchRating {'
                     + 'text-align: center;'
                     + 'text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000;'
                     + 'line-height: 25px;'
                     + 'font-size: 18px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.matchRating {'
                     + 'margin-left: 15px;'
                     + 'margin-top: 15px;'
                     + 'text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000;'
                     + 'line-height: 10px;'
                     + 'font-size: 18px;}}'
                    );

    sheet.insertRule('.probabilityTable tr {'
                     + 'line-height: 16px;'
                     + 'color: #fff;}'
                    );

    sheet.insertRule('.probabilityTable tr:nth-of-type(odd) {'
                     + 'background-color: rgba(0,0,0,0.2);}'
                    );

    sheet.insertRule('.probabilityTable tr:nth-of-type(even)[data-tint=w] {'
                     + 'background-color: #66cd0028;}'
                    );

    sheet.insertRule('.probabilityTable tr:nth-of-type(even)[data-tint=l] {'
                     + 'background-color: #ff2f2f28;}'
                    );

    sheet.insertRule('.probabilityTable .plus {'
                     + 'color: #66CD00;}'
                    );

    sheet.insertRule('.probabilityTable .minus {'
                     + 'color: #FF2F2F;}'
                    );

    sheet.insertRule('.probabilityTable .close {'
                     + 'color: #FFA500;}'
                    );

    sheet.insertRule('.winProb {'
                     + 'text-align: center; '
                     + 'text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000; '
                     + 'line-height: 17px; '
                     + 'font-size: 16px;}'
                    );

    sheet.insertRule('.tier5_skill {'
                     + 'position: relative;'
                     + 'margin-bottom: -22px;'
                     + 'bottom: 26px;'
                     + 'left: 75px;}'
                    );

    sheet.insertRule('.tier5_skill > .active_skills_icn {'
                     + 'position: absolute;'
                     + 'bottom: 25px;}'
                    );
}

function calculateDominationBonuses(playerElements, opponentElements) {
    const bonuses = {
        player: {
            ego: 0,
            attack: 0,
            chance: 0
        },
        opponent: {
            ego: 0,
            attack: 0,
            chance: 0
        }
    };

    [
        {a: playerElements, b: opponentElements, k: 'player'},
        {a: opponentElements, b: playerElements, k: 'opponent'}
    ].forEach(({a,b,k})=>{
        a.forEach(element => {
            if (ELEMENTS.egoDamage[element] && b.includes(ELEMENTS.egoDamage[element])) {
                bonuses[k].ego += 0.1
                bonuses[k].attack += 0.1
            }
            if (ELEMENTS.chance[element] && b.includes(ELEMENTS.chance[element])) {
                bonuses[k].chance += 0.2
            }
        })
    })

    return bonuses
}

function countElementsInTeam(elements) {
    return elements.reduce((a,b)=>{a[b]++;return a}, {
        fire: 0,
        stone: 0,
        sun: 0,
        water: 0,
        nature: 0,
        darkness: 0,
        light: 0,
        psychic: 0
    })
}

function calculateCritChanceShare(ownHarmony, otherHarmony) {
    return 0.3*ownHarmony/(ownHarmony+otherHarmony)
}

function calculateTier4SkillValue(teamGirlsArray) {
    let skill_tier_4 = {dmg: 0, def: 0};

    teamGirlsArray.forEach((girl) => {
        if (girl.skills[9]) skill_tier_4.dmg += girl.skills[9].skill.percentage_value/100;
        if (girl.skills[10]) skill_tier_4.def += girl.skills[10].skill.percentage_value/100;
    })
    return skill_tier_4;
}

function calculateTier5SkillValue(teamGirlsArray) {
    let skill_tier_5 = {id: 0, value: 0};
    const girl = teamGirlsArray[0];

    tier5_Skill_Id.forEach((id) => {
        if (girl.skills[id]) {
            skill_tier_5.id = id;
            skill_tier_5.value = (id == 11) ? parseInt(girl.skills[id].skill.display_value_text, 10)/100 : girl.skills[id].skill.percentage_value/100;
        }
    })
    return skill_tier_5;
}

function calculateBattleProbabilities(player, opponent) {
    this.player = player;
    this.opponent = opponent;

    const setup = x => {
        x.critMultiplier = 2 + x.bonuses.critDamage;
        x.hp = Math.ceil(x.hp);
    }

    setup(this.player);
    setup(this.opponent);

    this.cache = {};
    this.runs = 0;

    //Tier 5 skill : Shield
    let playerShield = 0;
    let opponentShield = 0;

    let ret;
    try{
        // start simulation from player's turn
        ret = playerTurn(this.player.hp, this.opponent.hp, 0);
    } catch (error){
        return {
            points: [],
            win: Number.NaN,
            loss: Number.NaN,
            avgTurns: Number.NaN,
            scoreClass: 'minus'
        };
    }

    const sum = ret.win + ret.loss;
    ret.win /= sum;
    ret.loss /= sum;
    ret.scoreClass = ret.win>0.9?'plus':ret.win<0.5?'minus':'close';

    return ret;

    function calculateDmg(x, turns) {
        const dmg = x.atk * (1 + x.tier4.dmg) ** turns - x.adv_def * (1 + x.tier4.def) ** turns;

        return {
            baseAtk : {
                probability: 1 - x.critchance,
                damageAmount: Math.ceil(dmg)
            },
            critAtk : {
                probability: x.critchance,
                damageAmount: Math.ceil(dmg * x.critMultiplier)
            }
        }
    }

    function mergeResult(x, xProbability, y, yProbability) {
        const points = {};
        Object.entries(x.points).map(([point, probability]) => [point, probability * xProbability])
            .concat(Object.entries(y.points).map(([point, probability]) => [point, probability * yProbability]))
            .forEach(([point, probability]) => {
            points[point] = (points[point] || 0) + probability
        });
        const merge = (x, y) => x * xProbability + y * yProbability;
        const win = merge(x.win, y.win);
        const loss = merge(x.loss, y.loss);
        const avgTurns = merge(x.avgTurns, y.avgTurns);
        return { points, win, loss, avgTurns };
    }

    function playerTurn(playerHP, opponentHP, turns) {
        turns += 1;
        // avoid a stack overflow
        const maxAllowedTurns = 50;
        if (turns > maxAllowedTurns) throw new Error();

        // read cache
        const cachedResult = this.cache?.[playerHP]?.[opponentHP];
        if (cachedResult) return cachedResult;

        // simulate base attack and critical attack
        const {baseAtk, critAtk} = calculateDmg(this.player, turns);
        const baseAtkResult = playerAttack(playerHP, opponentHP, baseAtk, turns);
        const critAtkResult = playerAttack(playerHP, opponentHP, critAtk, turns);
        // merge result
        const mergedResult = mergeResult(baseAtkResult, baseAtk.probability, critAtkResult, critAtk.probability);

        // count player's turn
        mergedResult.avgTurns += 1;

        // write cache
        if (!this.cache[playerHP]) this.cache[playerHP] = {};
        if (!this.cache[playerHP][opponentHP]) this.cache[playerHP][opponentHP] = {};
        this.cache[playerHP][opponentHP] = mergedResult;

        return mergedResult;
    }

    function playerAttack(playerHP, opponentHP, attack, turns) {
        //Tier 5 skill : Stun
        if (this.opponent.tier5.id == 11 && (turns == 2 || turns == 3)) {
            // next turn
            return playerTurn(playerHP, opponentHP, turns);
        }

        let playerDamage = Math.max(0, (attack.damageAmount - opponentShield));
        opponentHP -= playerDamage;

        //Tier 5 skill : Shield
        if (this.player.tier5.id == 12 && turns == 1) {
            playerShield = Math.ceil(this.player.tier5.value * this.player.hp);
        }
        if (this.opponent.tier5.id == 12 && turns > 1) {
            opponentShield -= attack.damageAmount;
            opponentShield = Math.max(0, opponentShield);
        }

        //Tier 5 skill : Reflect
        let opponentReflectDmg = 0;
        if (this.opponent.tier5.id == 13 && (turns == 2 || turns == 3)) {
            opponentReflectDmg = Math.ceil(this.opponent.tier5.value * attack.damageAmount);
            playerHP -= Math.max(0, (opponentReflectDmg - playerShield));
            playerShield -= opponentReflectDmg;
            playerShield = Math.max(0, playerShield);
        }

        //Tier 5 skill : Execute
        if (this.player.tier5.id == 14) {
            let opponentHPRate = opponentHP / this.opponent.hp;
            if (opponentHPRate <= this.player.tier5.value) {
                opponentHP = 0;
            }
        }

        // heal on hit
        let playerHeal = Math.ceil(this.player.bonuses.healOnHit * playerDamage);
        playerHP += playerHeal;
        playerHP = Math.min(playerHP, this.player.hp);

        // check win
        if (opponentHP <= 0) {
            const point = Math.min(25, 15 + Math.ceil(10 * playerHP / this.player.hp));
            this.runs += 1;
            return { points: { [point]: 1 }, win: 1, loss: 0, avgTurns: 0 };
        }

        // next turn
        return opponentTurn(playerHP, opponentHP, turns);
    }

    function opponentTurn(playerHP, opponentHP, turns) {
        // simulate base attack and critical attack
        const {baseAtk, critAtk} = calculateDmg(this.opponent, turns);
        const baseAtkResult = opponentAttack(playerHP, opponentHP, baseAtk, turns);
        const critAtkResult = opponentAttack(playerHP, opponentHP, critAtk, turns);
        // merge result
        return mergeResult(baseAtkResult, baseAtk.probability, critAtkResult, critAtk.probability);
    }

    function opponentAttack(playerHP, opponentHP, attack, turns) {
        //Tier 5 skill : Stun
        if (this.player.tier5.id == 11 && (turns == 1 || turns == 2)) {
            // next turn
            return playerTurn(playerHP, opponentHP, turns);
        }

        // damage
        let opponentDamage = Math.max(0, (attack.damageAmount - playerShield));
        playerHP -= opponentDamage;

        //Tier 5 skill : Shield
        if (this.opponent.tier5.id == 12 && turns == 1) {
            opponentShield = Math.ceil(this.opponent.tier5.value * this.opponent.hp);
        }
        if (this.player.tier5.id == 12) {
            playerShield -= attack.damageAmount;
            playerShield = Math.max(0, playerShield);
        }

        //Tier 5 skill : Reflect
        let playerReflectDmg = 0;
        if (this.player.tier5.id == 13 && (turns == 1 || turns == 2)) {
            playerReflectDmg = Math.ceil(this.player.tier5.value * attack.damageAmount);
            opponentHP -= Math.max(0, (playerReflectDmg - opponentShield));
            opponentShield -= playerReflectDmg;
            opponentShield = Math.max(0, opponentShield);
        }

        //Tier 5 skill : Execute
        if (this.opponent.tier5.id == 14) {
            let playerHPRate = playerHP / this.player.hp;
            if (playerHPRate <= this.opponent.tier5.value) {
                playerHP = 0;
            }
        }

        // heal on hit
        let opponentHeal = Math.ceil(this.opponent.bonuses.healOnHit * opponentDamage);
        opponentHP += opponentHeal;
        opponentHP = Math.min(opponentHP, this.opponent.hp);

        // check loss
        if (playerHP <= 0) {
            const point = Math.max(3, 3 + Math.ceil(10 * (this.opponent.hp - opponentHP) / this.opponent.hp));
            this.runs += 1;
            return { points: { [point]: 1 }, win: 0, loss: 1, avgTurns: 0 };
        }

        // next turn
        return playerTurn(playerHP, opponentHP, turns);
    }
}

/* ============
	SEASON SIM
   ============ */

function moduleSeasonSim() {
    function calculateSeasonPower(idOpponent) {
        // INIT
        let playerAtk = window.hero_data.damage;
        let playerEgo = window.hero_data.remaining_ego;
        let playerDef = window.hero_data.defense;
        let playerCrit = window.hero_data.chance;

        let playerElements = [];
        window.hero_data.team.theme_elements.forEach((el) => playerElements.push(el.type));

        const playerBonuses = {
            critDamage: window.hero_data.team.synergies.find(({element: {type}})=>type == 'fire').bonus_multiplier,
            critChance: window.hero_data.team.synergies.find(({element: {type}})=>type == 'stone').bonus_multiplier,
            defReduce: window.hero_data.team.synergies.find(({element: {type}})=>type == 'sun').bonus_multiplier,
            healOnHit: window.hero_data.team.synergies.find(({element: {type}})=>type == 'water').bonus_multiplier
        };

        let opponentAtk = window.opponents[idOpponent].player.damage;
        let opponentEgo = window.opponents[idOpponent].player.remaining_ego;
        let opponentDef = window.opponents[idOpponent].player.defense;
        let opponentCrit = window.opponents[idOpponent].player.chance;

        let opponentElements = [];
        window.opponents[idOpponent].player.team.theme_elements.forEach((el) => opponentElements.push(el.type));

        const opponentBonuses = {
            critDamage: window.opponents[idOpponent].player.team.synergies.find(({element: {type}})=>type == 'fire').bonus_multiplier,
            critChance: window.opponents[idOpponent].player.team.synergies.find(({element: {type}})=>type == 'stone').bonus_multiplier,
            defReduce: window.opponents[idOpponent].player.team.synergies.find(({element: {type}})=>type == 'sun').bonus_multiplier,
            healOnHit: window.opponents[idOpponent].player.team.synergies.find(({element: {type}})=>type == 'water').bonus_multiplier
        };

        const dominanceBonuses = calculateDominationBonuses(playerElements, opponentElements);

        let player = {
            hp: playerEgo,
            atk: playerAtk,
            adv_def: opponentDef,
            critchance: calculateCritChanceShare(playerCrit, opponentCrit) + dominanceBonuses.player.chance + playerBonuses.critChance,
            bonuses: playerBonuses,
            tier4: calculateTier4SkillValue(window.hero_data.team.girls),
            tier5: calculateTier5SkillValue(window.hero_data.team.girls)
        };

        let opponent = {
            hp: opponentEgo,
            atk: opponentAtk,
            adv_def: playerDef,
            critchance: calculateCritChanceShare(opponentCrit, playerCrit) + dominanceBonuses.opponent.chance + opponentBonuses.critChance,
            name: window.opponents[idOpponent].player.nickname,
            bonuses: opponentBonuses,
            tier4: calculateTier4SkillValue(window.opponents[idOpponent].player.team.girls),
            tier5: calculateTier5SkillValue(window.opponents[idOpponent].player.team.girls)
        };

        //Display tier 5 skill
        //Player team
        if ([11, 12, 13, 14].some(index => window.hero_data.team.girls[0].skills[index])) {
            const skill5_girl = window.hero_data.team.girls[0].skills;
            $('#season-arena .player_team_block.battle_hero .tier5_skill').remove();
            //Stun
            if (!(skill5_girl[11] == undefined)) {
                $('#season-arena .player_team_block.battle_hero .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[11].skill.skill_type}/${skill5_girl[11].skill.display_value_text}</span>`)
            }
            //Shield
            else if (!(skill5_girl[12] == undefined)) {
                $('#season-arena .player_team_block.battle_hero .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[12].skill.skill_type}/${skill5_girl[12].skill.display_value_text}</span>`)
            }
            //Reflect
            else if (!(skill5_girl[13] == undefined)) {
                $('#season-arena .player_team_block.battle_hero .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[13].skill.skill_type}/${skill5_girl[13].skill.display_value_text}</span>`)
            }
            //Execute
            else if (!(skill5_girl[14] == undefined)) {
                $('#season-arena .player_team_block.battle_hero .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[14].skill.skill_type}/${skill5_girl[14].skill.display_value_text}</span>`)
            }
        }

        //Opponent team
        if ([11, 12, 13, 14].some(index => window.opponents[idOpponent].player.team.girls[0].skills[index])) {
            const skill5_girl = window.opponents[idOpponent].player.team.girls[0].skills;
            $('#season-arena .opponents_arena .season_arena_opponent_container.opponent-' + idOpponent + ' .tier5_skill').remove();
            //Stun
            if (!(skill5_girl[11] == undefined)) {
                $('#season-arena .opponents_arena .season_arena_opponent_container.opponent-' + idOpponent + ' .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[11].skill.skill_type}/${skill5_girl[11].skill.display_value_text}</span>`)
            }
            //Shield
            else if (!(skill5_girl[12] == undefined)) {
                $('#season-arena .opponents_arena .season_arena_opponent_container.opponent-' + idOpponent + ' .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[12].skill.skill_type}/${skill5_girl[12].skill.display_value_text}</span>`)
            }
            //Reflect
            else if (!(skill5_girl[13] == undefined)) {
                $('#season-arena .opponents_arena .season_arena_opponent_container.opponent-' + idOpponent + ' .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[13].skill.skill_type}/${skill5_girl[13].skill.display_value_text}</span>`)
            }
            //Execute
            else if (!(skill5_girl[14] == undefined)) {
                $('#season-arena .opponents_arena .season_arena_opponent_container.opponent-' + idOpponent + ' .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[14].skill.skill_type}/${skill5_girl[14].skill.display_value_text}</span>`)
            }
        }

        const simu = calculateBattleProbabilities(player, opponent);

        $('#season-arena .opponents_arena .season_arena_opponent_container.opponent-' + idOpponent + ' .matchRating').remove();
        $('#season-arena .opponents_arena .season_arena_opponent_container.opponent-' + idOpponent + ' .average-lvl').before(`<span class="matchRating ${simu.scoreClass}">${nRounding(100*simu.win, 2, -1)}%</span>`);
    }

    calculateSeasonPower(0);
    calculateSeasonPower(1);
    calculateSeasonPower(2);

    const observer = new MutationObserver(() => {calculateSeasonPower(0);
                                                 calculateSeasonPower(1);
                                                 calculateSeasonPower(2);});
    observer.observe($('#season-arena .opponents_arena')[0], {subtree: true, attributes: true, attributeFilter: ['class']})

    //CSS
    sheet.insertRule('.matchRating {'
                     + 'position: relative;'
                     + 'top: -23px;'
                     + 'left: -70px;'
                     + 'text-align: center;'
                     + 'margin-left: 10px;'
                     + 'text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000;'
                     + 'line-height: 17px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.matchRating {'
                     + 'font-size: 16px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.matchRating {'
                     + 'font-size: 22px;}}'
                    );

    sheet.insertRule('.plus {'
                     + 'color: #66CD00;}'
                    );

    sheet.insertRule('.minus {'
                     + 'color: #FF2F2F;}'
                    );

    sheet.insertRule('.close {'
                     + 'color: #FFA500;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#season-arena .hero_team .team-hexagon-container .average-lvl {'
                     + 'margin-left: -15px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#season-arena .hero_team .team-hexagon-container .average-lvl {'
                     + 'margin-left: -15px;}}'
                    );

    sheet.insertRule('.player_team_block.opponent .player-team .average-lvl {'
                     + 'margin-top: -1rem !important;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.player_team_block.opponent .player-team .average-lvl {'
                     + 'font-size: 1rem !important;'
                     + 'margin-top: -1rem !important;}'
                    );

    sheet.insertRule('.tier5_skill {'
                     + 'position: relative;'
                     + 'margin-bottom: -22px;'
                     + 'bottom: 26px;'
                     + 'left: 67px;}'
                    );

    sheet.insertRule('.tier5_skill > .active_skills_icn {'
                     + 'position: absolute;'
                     + 'bottom: 25px;}'
                    );
}

/* ====================
	BATTLE SIMULATION
   ==================== */

function moduleBattleSim() {
    // INIT
    let playerAtk = window.hero_data.damage;
    let playerEgo = window.hero_data.remaining_ego;
    let playerDef = window.hero_data.defense;
    let playerCrit = window.hero_data.chance;

    let playerElements = [];
    window.hero_data.team.theme_elements.forEach((el) => playerElements.push(el.type));

    const playerBonuses = {
        critDamage: window.hero_data.team.synergies.find(({element: {type}})=>type == 'fire').bonus_multiplier,
        critChance: window.hero_data.team.synergies.find(({element: {type}})=>type == 'stone').bonus_multiplier,
        defReduce: window.hero_data.team.synergies.find(({element: {type}})=>type == 'sun').bonus_multiplier,
        healOnHit: window.hero_data.team.synergies.find(({element: {type}})=>type == 'water').bonus_multiplier
    };

    let opponentAtk = window.opponent_fighter.player.damage;
    let opponentEgo = window.opponent_fighter.player.remaining_ego;
    let opponentDef = window.opponent_fighter.player.defense;
    let opponentCrit = window.opponent_fighter.player.chance;

    let opponentElements = [];
    window.opponent_fighter.player.team.theme_elements.forEach((el) => opponentElements.push(el.type));

    const opponentBonuses = {
        critDamage: window.opponent_fighter.player.team.synergies.find(({element: {type}})=>type == 'fire').bonus_multiplier,
        critChance: window.opponent_fighter.player.team.synergies.find(({element: {type}})=>type == 'stone').bonus_multiplier,
        defReduce: window.opponent_fighter.player.team.synergies.find(({element: {type}})=>type == 'sun').bonus_multiplier,
        healOnHit: window.opponent_fighter.player.team.synergies.find(({element: {type}})=>type == 'water').bonus_multiplier
    };

    const dominanceBonuses = calculateDominationBonuses(playerElements, opponentElements);

    let player = {
        hp: playerEgo,
        atk: playerAtk,
        adv_def: opponentDef,
        critchance: calculateCritChanceShare(playerCrit, opponentCrit) + dominanceBonuses.player.chance + playerBonuses.critChance,
        bonuses: playerBonuses,
        tier4: calculateTier4SkillValue(window.hero_data.team.girls),
        tier5: calculateTier5SkillValue(window.hero_data.team.girls)
    };

    let opponent = {
        hp: opponentEgo,
        atk: opponentAtk,
        adv_def: playerDef,
        critchance: calculateCritChanceShare(opponentCrit, playerCrit) + dominanceBonuses.opponent.chance + opponentBonuses.critChance,
        name: window.opponent_fighter.player.nickname,
        bonuses: opponentBonuses,
        tier4: calculateTier4SkillValue(window.opponent_fighter.player.team.girls),
        tier5: calculateTier5SkillValue(window.opponent_fighter.player.team.girls)
    };

    //Display tier 5 skill
    //Player team
    if ([11, 12, 13, 14].some(index => window.hero_data.team.girls[0].skills[index])) {
        const skill5_girl = window.hero_data.team.girls[0].skills;
        //Stun
        if (!(skill5_girl[11] == undefined)) {
            $('#pre-battle .player_team_block.battle_hero .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[11].skill.skill_type}/${skill5_girl[11].skill.display_value_text}</span>`)
        }
        //Shield
        else if (!(skill5_girl[12] == undefined)) {
            $('#pre-battle .player_team_block.battle_hero .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[12].skill.skill_type}/${skill5_girl[12].skill.display_value_text}</span>`)
        }
        //Reflect
        else if (!(skill5_girl[13] == undefined)) {
            $('#pre-battle .player_team_block.battle_hero .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[13].skill.skill_type}/${skill5_girl[13].skill.display_value_text}</span>`)
        }
        //Execute
        else if (!(skill5_girl[14] == undefined)) {
            $('#pre-battle .player_team_block.battle_hero .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[14].skill.skill_type}/${skill5_girl[14].skill.display_value_text}</span>`)
        }
    }

    //Opponent team
    if ([11, 12, 13, 14].some(index => window.opponent_fighter.player.team.girls[0].skills[index])) {
        const skill5_girl = window.opponent_fighter.player.team.girls[0].skills;
        //Stun
        if (!(skill5_girl[11] == undefined)) {
            $('#pre-battle .player_team_block.opponent .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[11].skill.skill_type}/${skill5_girl[11].skill.display_value_text}</span>`)
        }
        //Shield
        else if (!(skill5_girl[12] == undefined)) {
            $('#pre-battle .player_team_block.opponent .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[12].skill.skill_type}/${skill5_girl[12].skill.display_value_text}</span>`)
        }
        //Reflect
        else if (!(skill5_girl[13] == undefined)) {
            $('#pre-battle .player_team_block.opponent .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[13].skill.skill_type}/${skill5_girl[13].skill.display_value_text}</span>`)
        }
        //Execute
        else if (!(skill5_girl[14] == undefined)) {
            $('#pre-battle .player_team_block.opponent .icon-area').after(`<span class="tier5_skill"><span class="active_skills_icn"></span>${skill5_girl[14].skill.skill_type}/${skill5_girl[14].skill.display_value_text}</span>`)
        }
    }

    const simu = calculateBattleProbabilities(player, opponent);

    $('#pre-battle .player_team_block.opponent .average-lvl')
        .wrap('<div class="gridWrapper"></div>')
        .after(`<span class="matchRating ${simu.scoreClass}">${nRounding(100*simu.win, 2, -1)}%</span>`);

    //CSS
    sheet.insertRule('.plus {'
                     + 'color: #66CD00;}'
                    );

    sheet.insertRule('.minus {'
                     + 'color: #FF2F2F;}'
                    );

    sheet.insertRule('.close {'
                     + 'color: #FFA500;}'
                    );

    sheet.insertRule('.gridWrapper {'
                     + 'display: grid;'
                     + 'grid-template-columns: 2fr 1fr;'
                     + 'width: 100%;}'
                    );

    sheet.insertRule('.matchRating {'
                     + 'text-align: center;'
                     + 'font-size: 16px;}'
                    );

    sheet.insertRule('#pre-battle .fighter-team .team-hexagon-container .average-lvl {'
                     + 'text-align: center;'
                     + 'margin-top: 0px;'
                     + 'line-height: 26px;}'
                    );

    sheet.insertRule('.tier5_skill {'
                     + 'position: relative;'
                     + 'margin-bottom: -22px;'
                     + 'bottom: 26px;'
                     + 'left: 75px;}'
                    );

    sheet.insertRule('.tier5_skill > .active_skills_icn {'
                     + 'position: absolute;'
                     + 'bottom: 25px;}'
                    );
}

/* ========================================
	TEAMS FILTER (Credit : randomfapper34)
   ======================================== */

function moduleTeamsFilter() {
    let arenaGirls = undefined;
    let girlsData = undefined;

    $(document).ready(function() {
        if (CurrentPage.includes('edit-team') || CurrentPage.includes('add-boss-bang-team') || CurrentPage.includes('waifu')) {
            arenaGirls = $('.harem-panel-girls .harem-girl-container');
            girlsData = CurrentPage.includes('waifu') ? window.girlsDataList : window.availableGirls;
            if (CurrentPage.includes('edit-team') || CurrentPage.includes('add-boss-bang-team')) {
                $("h3.panel-title").after('<button id="arena_filter" class="blue_text_button">' + labels.filter + '</button>');
                $("h3.panel-title").after(createFilterBox("default"));
            }
            else {
                $(".change-girl-panel #filter_girls").after('<button id="arena_filter" class="blue_text_button">' + labels.filter + '</button>');
                $(".change-girl-panel #filter_girls").after(createFilterBox("default"));
            } 
            createFilterEvents();
        }
    });

    function createFilterEvents() {
        $("#arena_filter").on('click', function() {
            if (typeof arenaGirls == 'undefined' || typeof girlsData == 'undefined') return;
            let currentBoxDisplay = $("#arena_filter_box").css('display');
            $("#arena_filter_box").css('display', currentBoxDisplay == "none" ? 'block' : 'none');
        });
        $("#filter_name").get(0).oninput = filterGirls;
        $("#filter_class").on('change', filterGirls);
        $("#filter_element").on('change', filterGirls);
        $("#filter_rarity").on('change', filterGirls);
        $("#filter_aff_category").on('change', filterGirls);
        $("#filter_aff_lvl").on('change', filterGirls);
        $("#filter_blessed_attributes").on('change', filterGirls);
        $("#filter_skills").on('change', filterGirls);
        $("#filter_pose").on('change', filterGirls);
        $("#filter_zodiac").on('change', filterGirls);
        $("#filter_hair").on('change', filterGirls);
        $("#filter_eye").on('change', filterGirls);
    }

    function filterGirls() {
        let filterName = $("#filter_name").get(0).value;
        let nameRegex = new RegExp(filterName, "i");
        let filterClass = $("#filter_class").get(0).selectedIndex;
        let filterElement = $("#filter_element").get(0).value;
        let filterRarity = $("#filter_rarity").get(0).value;
        let filterAffCategory = $("#filter_aff_category").get(0).value;
        let filterAffLvl = $("#filter_aff_lvl").get(0).value;
        let filterBlessedAttributes = $("#filter_blessed_attributes").get(0).value;
        let filterSkills = $("#filter_skills").get(0).value;
        let filterPose = $("#filter_pose").get(0).value;
        let filterZodiac = $("#filter_zodiac").get(0).value;
        let filterHair= $("#filter_hair").get(0).value;
        let filterEye = $("#filter_eye").get(0).value;

        let girlsFiltered = $.map(girlsData, function(girl, index) {
            let matchesName = (girl.name.search(nameRegex) > -1);
            let matchesClass = (girl.class == filterClass) || (filterClass == 0);
            let matchesElement = (girl.element == filterElement) || (filterElement == 'all');
            let matchesRarity = (girl.rarity == filterRarity) || (filterRarity == 'all');
            let matchesAffCategory = (girl.nb_grades == filterAffCategory) || (filterAffCategory == 'all');
            let matchesAffLvl = (girl.graded == filterAffLvl) || (filterAffLvl == 'all');

            let matchesBlessedAttributes;
            switch (filterBlessedAttributes) {
                case 'blessed_attributes':
                    matchesBlessedAttributes = (girl.blessed_attributes != undefined);
                    break;
                case 'non_blessed_attributes':
                    matchesBlessedAttributes = (girl.blessed_attributes == undefined);
                    break;
                case 'all':
                    matchesBlessedAttributes = (filterBlessedAttributes == 'all');
                    break;
            }

            let skills = girl.skill_tiers_info;
            let indexSkill = 0;
            for (let id=1; id<6; id++) {
                if (skills[id])
                    if(skills[id].skill_points_used > 0) indexSkill = id;
            }
            let matchesSkills = (indexSkill >= filterSkills) || (filterSkills == 'all')

            let matchesPose = (girl.figure == filterPose) || (filterPose == 'all');
            let matchesZodiac = (girl.zodiac == filterZodiac) || (filterZodiac == 'all');
            let matchesHair = (girl.hair_color1 == filterHair) || (girl.hair_color2 == filterHair) || (filterHair == 'all');
            let matchesEye = (girl.eye_color1 == filterEye) || (girl.eye_color2 == filterEye) || (filterEye == 'all');

            return (matchesName && matchesClass && matchesElement && matchesRarity && matchesAffCategory && matchesAffLvl && matchesBlessedAttributes && matchesSkills && matchesPose && matchesZodiac && matchesHair && matchesEye) ? index : null;
        });

        $.each(arenaGirls, function(index, girlElem) {
            $(girlElem).css('display', $.inArray(index, girlsFiltered) > -1 ? 'block' : 'none');
        });

        //update scroll display
        $(".harem-panel-girls").css('overflow', '');
        $(".harem-panel-girls").css('overflow', 'hidden');
    }

    function createFilterBox() {
        let totalHTML = '<div id="arena_filter_box" class="form-wrapper">';

        totalHTML += '<div class="form-control"><div class="input-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_name">' + window.GT.design.Name + '</label>'
            + '<input type="text" autocomplete="off" id="filter_name" placeholder="' + labels.girl_name + '" icon="search">'
            + '</div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_class">' + window.GT.design.mythic_equipment_class + '</label>'
            + '<select name="filter_class" id="filter_class" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="hardcore">' + window.GT.caracs[1] + '</option>'
            + '<option value="charm">' + window.GT.caracs[2] + '</option>'
            + '<option value="knowhow">' + window.GT.caracs[3] + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_element">' + labels.element + '</label>'
            + '<select name="filter_element" id="filter_element" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="darkness" style="color: #000; text-shadow: 1px 1px 0 #24a0ff,-1px 1px 0 #24a0ff,-1px -1px 0 #24a0ff,1px -1px 0 #24a0ff;">' + window.GT.design.darkness_flavor_element + '</option>'
            + '<option value="light" style="color: #fff;">' + window.GT.design.light_flavor_element + '</option>'
            + '<option value="psychic" style="color: #7e0c8e;">' + window.GT.design.psychic_flavor_element + '</option>'
            + '<option value="fire" style="color: #ff2a52;">' + window.GT.design.fire_flavor_element + '</option>'
            + '<option value="nature" style="color: #00e772;">' + window.GT.design.nature_flavor_element + '</option>'
            + '<option value="stone" style="color: #cb6f2b;">' + window.GT.design.stone_flavor_element + '</option>'
            + '<option value="sun" style="color: #fff049;">' + window.GT.design.sun_flavor_element + '</option>'
            + '<option value="water" style="color: #24a0ff;">' + window.GT.design.water_flavor_element + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_rarity">' + window.GT.design.selectors_Rarity + '</label>'
            + '<select name="filter_rarity" id="filter_rarity" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="starting">' + window.GT.design.girls_rarity_starting + '</option>'
            + '<option value="common">' + window.GT.design.girls_rarity_common + '</option>'
            + '<option value="rare">' + window.GT.design.girls_rarity_rare + '</option>'
            + '<option value="epic">' + window.GT.design.girls_rarity_epic + '</option>'
            + '<option value="legendary">' + window.GT.design.girls_rarity_legendary + '</option>'
            + '<option value="mythic">' + window.GT.design.girls_rarity_mythic + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_aff_category">' + window.GT.design.affection_category + '</label>'
            + '<select name="filter_aff_category" id="filter_aff_category" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="1">' + labels.one_star + '</option>'
            + '<option value="3">' + labels.three_stars + '</option>'
            + '<option value="5">' + labels.five_stars + '</option>'
            + '<option value="6">' + labels.six_stars + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_aff_lvl">' + labels.aff_lvl + '</label>'
            + '<select name="filter_aff_lvl" id="filter_aff_lvl" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="0">' + labels.zero_star + '</option>'
            + '<option value="1">' + labels.one_star + '</option>'
            + '<option value="2">' + labels.two_stars + '</option>'
            + '<option value="3">' + labels.three_stars + '</option>'
            + '<option value="4">' + labels.four_stars + '</option>'
            + '<option value="5">' + labels.five_stars + '</option>'
            + '<option value="6">' + labels.six_stars + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_blessed_attributes">' + labels.blessed_attributes + '</label>'
            + '<select name="filter_blessed_attributes" id="filter_blessed_attributes" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="blessed_attributes">' + labels.blessed_attributes + '</option>'
            + '<option value="non_blessed_attributes">' + labels.non_blessed_attributes + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="skills">' + window.GT.design.girl_skills + '</label>'
            + '<select name="filter_skills" id="filter_skills" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="1">' + window.GT.design.tier + '&nbsp;≥ 1</option>'
            + '<option value="2">' + window.GT.design.tier + '&nbsp;≥ 2</option>'
            + '<option value="3">' + window.GT.design.tier + '&nbsp;≥ 3</option>'
            + '<option value="4">' + window.GT.design.tier + '&nbsp;≥ 4</option>'
            + '<option value="5">' + window.GT.design.tier + '&nbsp;≥ 5</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_pose">' + window.GT.design.filter_pose + '</label>'
            + '<select name="filter_pose" id="filter_pose" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="1">' + window.GT.figures[1] + '</option>'
            + '<option value="2">' + window.GT.figures[2] + '</option>'
            + '<option value="3">' + window.GT.figures[3] + '</option>'
            + '<option value="4">' + window.GT.figures[4] + '</option>'
            + '<option value="5">' + window.GT.figures[5] + '</option>'
            + '<option value="6">' + window.GT.figures[6] + '</option>'
            + '<option value="7">' + window.GT.figures[7] + '</option>'
            + '<option value="8">' + window.GT.figures[8] + '</option>'
            + '<option value="9">' + window.GT.figures[9] + '</option>'
            + '<option value="10">' + window.GT.figures[10] + '</option>'
            + '<option value="11">' + window.GT.figures[11] + '</option>'
            + '<option value="12">' + window.GT.figures[12] + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_zodiac">' + window.GT.design.haremdex_zodiac_sign + '</label>'
            + '<select name="filter_zodiac" id="filter_zodiac" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="' + labels.zodiac[1] + '">' + labels.zodiac[1] + '</option>'
            + '<option value="' + labels.zodiac[2] + '">' + labels.zodiac[2] + '</option>'
            + '<option value="' + labels.zodiac[3] + '">' + labels.zodiac[3] + '</option>'
            + '<option value="' + labels.zodiac[4] + '">' + labels.zodiac[4] + '</option>'
            + '<option value="' + labels.zodiac[5] + '">' + labels.zodiac[5] + '</option>'
            + '<option value="' + labels.zodiac[6] + '">' + labels.zodiac[6] + '</option>'
            + '<option value="' + labels.zodiac[7] + '">' + labels.zodiac[7] + '</option>'
            + '<option value="' + labels.zodiac[8] + '">' + labels.zodiac[8] + '</option>'
            + '<option value="' + labels.zodiac[9] + '">' + labels.zodiac[9] + '</option>'
            + '<option value="' + labels.zodiac[10] + '">' + labels.zodiac[10] + '</option>'
            + '<option value="' + labels.zodiac[11] + '">' + labels.zodiac[11] + '</option>'
            + '<option value="' + labels.zodiac[12] + '">' + labels.zodiac[12] + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_hair">' + window.GT.design.haremdex_hair_color + '</label>'
            + '<select name="filter_hair" id="filter_hair" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="F99" style="color: #ff5a81;">' + labels.color['F99'] + '</option>'
            + '<option value="F00" style="color: #ff2a52;">' + labels.color['F00'] + '</option>'
            + '<option value="B62" style="color: #cb6f2b;">' + labels.color['B62'] + '</option>'
            + '<option value="FFF" style="color: #fff;">' + labels.color['FFF'] + '</option>'
            + '<option value="321" style="color: #67422a; text-shadow: 1px 1px 0 #fff,-1px 1px 0 #fff,-1px -1px 0 #fff,1px -1px 0 #fff;">' + labels.color['321'] + '</option>'
            + '<option value="00F" style="color: #24a0ff;">' + labels.color['00F'] + '</option>'
            + '<option value="FF0" style="color: #fff049;">' + labels.color['FF0'] + '</option>'
            + '<option value="0F0" style="color: #00e772;">' + labels.color['0F0'] + '</option>'
            + '<option value="XXX" style="color: #fff;">' + labels.color['XXX'] + '</option>'
            + '<option value="A55" style="color: #cb6f2b;">' + labels.color['A55'] + '</option>'
            + '<option value="000" style="color: #000; text-shadow: 1px 1px 0 #24a0ff,-1px 1px 0 #24a0ff,-1px -1px 0 #24a0ff,1px -1px 0 #24a0ff;">' + labels.color['000'] + '</option>'
            + '<option value="CCC" style="color: #ccc;">' + labels.color['CCC'] + '</option>'
            + '<option value="F0F" style="color: #e42eff;">' + labels.color['F0F'] + '</option>'
            + '<option value="F90" style="color: #ff9600;">' + labels.color['F90'] + '</option>'
            + '<option value="EB8" style="color: #ffa792;">' + labels.color['EB8'] + '</option>'
            + '<option value="B06" style="color: #ca0080;">' + labels.color['B06'] + '</option>'
            + '<option value="888" style="color: #999;">' + labels.color['888'] + '</option>'
            + '<option value="FD0" style="color: #ffb923;">' + labels.color['FD0'] + '</option>'
            + '<option value="D83" style="color: #ca8521;">' + labels.color['D83'] + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_eye">' + window.GT.design.haremdex_eye_color + '</label>'
            + '<select name="filter_eye" id="filter_eye" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="F99" style="color: #ff5a81;">' + labels.color['F99'] + '</option>'
            + '<option value="00F" style="color: #24a0ff;">' + labels.color['00F'] + '</option>'
            + '<option value="A55" style="color: #cb6f2b;">' + labels.color['A55'] + '</option>'
            + '<option value="0F0" style="color: #00e772;">' + labels.color['0F0'] + '</option>'
            + '<option value="F0F" style="color: #e42eff;">' + labels.color['F0F'] + '</option>'
            + '<option value="FD0" style="color: #ffb923;">' + labels.color['FD0'] + '</option>'
            + '<option value="F00" style="color: #ff2a52;">' + labels.color['F00'] + '</option>'
            + '<option value="B06" style="color: #ca0080;">' + labels.color['B06'] + '</option>'
            + '<option value="F90" style="color: #ff9600;">' + labels.color['F90'] + '</option>'
            + '<option value="888" style="color: #999;">' + labels.color['888'] + '</option>'
            + '<option value="CCC" style="color: #ccc;">' + labels.color['CCC'] + '</option>'
            + '<option value="000" style="color: #000; text-shadow: 1px 1px 0 #24a0ff,-1px 1px 0 #24a0ff,-1px -1px 0 #24a0ff,1px -1px 0 #24a0ff;">' + labels.color['000'] + '</option>'
            + '<option value="XXX" style="color: #fff;">' + labels.color['XXX'] + '</option>'
            + '<option value="321" style="color: #67422a; text-shadow: 1px 1px 0 #fff,-1px 1px 0 #fff,-1px -1px 0 #fff,1px -1px 0 #fff;">' + labels.color['321'] + '</option>'
            + '<option value="FFF" style="color: #fff;">' + labels.color['FFF'] + '</option>'
            + '</select></div></div>';

        totalHTML += '</div>';

        return totalHTML;
    }

    //CSS
    sheet.insertRule('#arena_filter_box {'
                     + 'columns: 2;'
                     + 'position: absolute;'
                     + 'width: 417px;'
                     + 'right: 408px;'
                     + 'z-index: 99;'
                     + 'border-radius: 8px 10px 10px 8px;'
                     + 'background-color: #1e261e;'
                     + 'box-shadow: rgba(255, 255, 255, 0.73) 0px 0px;'
                     + 'padding: 5px;'
                     + 'border: 1px solid #ffa23e;'
                     + 'display: none;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#arena_filter_box {'
                     + 'top: 98px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#arena_filter_box {'
                     + 'top: 66px;}}'
                    );

    sheet.insertRule('.form-control {'
                     + 'display: grid;}'
                    );

    sheet.insertRule('.form-wrapper > .form-control > .select-group > select > option {'
                     + 'font-weight: bold;'
                     + 'text-shadow: 1px 1px 0 #000,-1px 1px 0 #000,-1px -1px 0 #000,1px -1px 0 #000;}'
                    );

    sheet.insertRule('.personal_info.hero {'
                     + 'margin-top: 5px; }');

    sheet.insertRule('#season-arena .season_arena_block.battle_hero .hero_stats div {'
                     + 'margin: 0; }');

    sheet.insertRule(`${mediaMobile} {`
                     + '.change-team-panel #filter_girls {'
                     + 'margin-top: 16px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.change-team-panel #filter_girls {'
                     + 'margin-top: 11px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.change-team-panel #arena_filter {'
                     + 'position: absolute;'
                     + 'width: 84px;'
                     + 'top: 82px;'
                     + 'right: 98px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.change-team-panel #arena_filter {'
                     + 'position: absolute;'
                     + 'width: 84px;'
                     + 'top: 60px;'
                     + 'right: 98px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.change-team-panel .panel-title {'
                     + 'margin-right: 70px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#change-team-page .change-team-panel.team-panel {'
                     + 'margin-top: 20px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#change-team-page .change-team-panel.harem-panel {'
                     + 'margin-top: 17px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.change-team-panel .panel-title {'
                     + 'margin-right: 70px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#waifu-page #arena_filter {'
                     + 'position: absolute;'
                     + 'width: 84px;'
                     + 'top: 47px;'
                     + 'right: 68px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#waifu-page #arena_filter {'
                     + 'position: absolute;'
                     + 'width: 84px;'
                     + 'top: 20px;'
                     + 'right: 68px;}}'
                    );

    sheet.insertRule('#waifu-page #arena_filter_box {'
                     + 'right: 346px !important;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#waifu-page #arena_filter_box {'
                     + 'top: 72px;}}'
                    );
}

//Filter on girls selection screen for labyrinth
function moduleLabyrinthFilter() {
    let arenaGirls = undefined;
    let girlsData = undefined;

    $(document).ready(function() {
        getFilterGirlData();
        $(".team-pool-selection-container").append('<button id="labyrinth_filter" class="blue_text_button">' + labels.filter + '</button>');
        $(".team-pool-selection-container").append(createFilterBox("default"));
        createFilterEvents();
    });

    function getFilterGirlData() {
        arenaGirls = $('.girl-grid .girl-container');

        girlsData = $.map(arenaGirls, function(girl, index) {
            return JSON.parse($(girl).find('.girl-image').attr("data-new-girl-tooltip"));
        });
    }

    function createFilterEvents() {
        $("#labyrinth_filter").on('click', function() {
            if (typeof arenaGirls == 'undefined' || typeof girlsData == 'undefined') return;
            let currentBoxDisplay = $("#labyrinth_filter_box").css('display');
            $("#labyrinth_filter_box").css('display', currentBoxDisplay == "none" ? 'block' : 'none');
        });
        $("#filter_class").on('change', filterGirls);
        $("#filter_rarity").on('change', filterGirls);
        $("#filter_name").get(0).oninput = filterGirls;
        $("#filter_aff_category").on('change', filterGirls);
        $("#filter_aff_lvl").on('change', filterGirls);
        $("#filter_element").on('change', filterGirls);
        $("#filter_skill5").on('change', filterGirls);
    }

    function filterGirls() {
        let filterClass = $("#filter_class").get(0).selectedIndex;
        let filterRarity = $("#filter_rarity").get(0).value;
        let filterName = $("#filter_name").get(0).value;
        let nameRegex = new RegExp(filterName, "i");
        let filterAffCategory = $("#filter_aff_category").get(0).value;
        let filterAffLvl = $("#filter_aff_lvl").get(0).value;
        let filterElement = $("#filter_element").get(0).value;
        let filterSkill5 = $("#filter_skill5").get(0).value;

        let girlsFiltered = $.map(girlsData, function(girl, index) {
            let matchesClass = (girl.class == filterClass) || (filterClass == 0);
            let matchesRarity = (girl.rarity == filterRarity) || (filterRarity == 'all');
            let matchesName = (girl.name.search(nameRegex) > -1);

            let affectionStr = girl.graded2;
            let affectionCategoryStr = affectionStr.split('</g>');
            let affectionCategory = affectionCategoryStr.length-1;
            let affectionLvlStr = affectionStr.split('<g >');
            let affectionLvl = affectionLvlStr.length-1;

            let matchesAffCategory = (affectionCategory == filterAffCategory) || (filterAffCategory == 'all');
            let matchesAffLvl = (affectionLvl == filterAffLvl) || (filterAffLvl == 'all');
            let matchesElement = (girl.element_data.type == filterElement) || (filterElement == 'all');

            let skill5Active = 0;
            if (girl.skill_tiers_info[5] != undefined) skill5Active = (girl.skill_tiers_info[5].skill_points_used == 0) ? 0 : 1;
            let matchesSkill5 = (skill5Active == filterSkill5) || (filterSkill5 == 'all');

            return (matchesClass && matchesRarity && matchesName && matchesAffCategory && matchesAffLvl && matchesElement && matchesSkill5) ? index : null;
        });

        $.each(arenaGirls, function(index, girlElem) {
            $(girlElem).css('display', $.inArray(index, girlsFiltered) > -1 ? 'block' : 'none');
        });

        //update scroll display
        $('.girl-grid').css('overflow', '');
        $('.girl-grid').css('overflow', 'hidden');
    }

    function createFilterBox() {
        let totalHTML = '<div id="labyrinth_filter_box" class="form-wrapper">';

        totalHTML += '<div class="form-control"><div class="input-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_name">' + window.GT.design.Name + '</label>'
            + '<input type="text" autocomplete="off" id="filter_name" placeholder="' + labels.girl_name + '" icon="search">'
            + '</div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_class">' + window.GT.design.mythic_equipment_class + '</label>'
            + '<select name="filter_class" id="filter_class" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="hardcore">' + window.GT.design.class_hardcore + '</option>'
            + '<option value="charm">' + window.GT.design.class_charm + '</option>'
            + '<option value="knowhow">' + window.GT.design.class_knowhow + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_element">' + labels.element + '</label>'
            + '<select name="filter_element" id="filter_element" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="darkness" style="color: #000; text-shadow: 1px 1px 0 #24a0ff,-1px 1px 0 #24a0ff,-1px -1px 0 #24a0ff,1px -1px 0 #24a0ff;">' + window.GT.design.darkness_flavor_element + '</option>'
            + '<option value="light" style="color: #fff;">' + window.GT.design.light_flavor_element + '</option>'
            + '<option value="psychic" style="color: #7e0c8e;">' + window.GT.design.psychic_flavor_element + '</option>'
            + '<option value="fire" style="color: #ff2a52;">' + window.GT.design.fire_flavor_element + '</option>'
            + '<option value="nature" style="color: #00e772;">' + window.GT.design.nature_flavor_element + '</option>'
            + '<option value="stone" style="color: #cb6f2b;">' + window.GT.design.stone_flavor_element + '</option>'
            + '<option value="sun" style="color: #fff049;">' + window.GT.design.sun_flavor_element + '</option>'
            + '<option value="water" style="color: #24a0ff;">' + window.GT.design.water_flavor_element + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_rarity">' + window.GT.design.selectors_Rarity + '</label>'
            + '<select name="filter_rarity" id="filter_rarity" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="starting">' + window.GT.design.girls_rarity_starting + '</option>'
            + '<option value="common">' + window.GT.design.girls_rarity_common + '</option>'
            + '<option value="rare">' + window.GT.design.girls_rarity_rare + '</option>'
            + '<option value="epic">' + window.GT.design.girls_rarity_epic + '</option>'
            + '<option value="legendary">' + window.GT.design.girls_rarity_legendary + '</option>'
            + '<option value="mythic">' + window.GT.design.girls_rarity_mythic + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_skill5">' + window.GT.design.girl_skills + ' ' + window.GT.design.tier + ' 5</label>'
            + '<select name="filter_skill5" id="filter_skill5" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value=1>' + window.GT.design.Yes + '</option>'
            + '<option value=0>' + window.GT.design.No + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_aff_category">' + window.GT.design.affection_category + '</label>'
            + '<select name="filter_aff_category" id="filter_aff_category" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="1">' + labels.one_star + '</option>'
            + '<option value="3">' + labels.three_stars + '</option>'
            + '<option value="5">' + labels.five_stars + '</option>'
            + '<option value="6">' + labels.six_stars + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_aff_lvl">' + labels.aff_lvl + '</label>'
            + '<select name="filter_aff_lvl" id="filter_aff_lvl" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="0">' + labels.zero_star + '</option>'
            + '<option value="1">' + labels.one_star + '</option>'
            + '<option value="2">' + labels.two_stars + '</option>'
            + '<option value="3">' + labels.three_stars + '</option>'
            + '<option value="4">' + labels.four_stars + '</option>'
            + '<option value="5">' + labels.five_stars + '</option>'
            + '<option value="6">' + labels.six_stars + '</option>'
            + '</select></div></div>';

        totalHTML += '</div>';

        return totalHTML;
    }

    //CSS
    sheet.insertRule('#labyrinth_filter_box {'
                     + 'columns: 2;'
                     + 'position: absolute;'
                     + 'width: 417px;'
                     + 'top: 10px;'
                     + 'left: 110px;'
                     + 'z-index: 99;'
                     + 'border-radius: 8px 10px 10px 8px;'
                     + 'background-color: #1e261e;'
                     + 'box-shadow: rgba(255, 255, 255, 0.73) 0px 0px;'
                     + 'padding: 5px;'
                     + 'border: 1px solid #ffa23e;'
                     + 'display: none;}'
                    );

    sheet.insertRule('.form-control {'
                     + 'display: grid;}'
                    );

    sheet.insertRule('.form-wrapper > .form-control > .select-group > select > option {'
                     + 'font-weight: bold;'
                     + 'text-shadow: 1px 1px 0 #000,-1px 1px 0 #000,-1px -1px 0 #000,1px -1px 0 #000;}'
                    );

    sheet.insertRule('.team-pool-selection-container #labyrinth_filter {'
                     + 'position: absolute;'
                     + 'width: 84px;'
                     + 'height: 45px;'
                     + 'left: 10px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.team-pool-selection-container #labyrinth_filter {'
                     + 'top: 6px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.team-pool-selection-container #labyrinth_filter {'
                     + 'top: 0px;}}'
                    );

    sheet.insertRule('.form-wrapper > .form-control label.head-group {'
                     + 'text-align: left;}'
                    );
}

//Filter on team selection screen in the labyrinth
function moduleLabyrinthTeamFilter() {
    let arenaGirls = undefined;
    let girlsData = undefined;

    $(document).ready(function() {
        getFilterGirlData();
        $("h3.panel-title").append('<button id="labyrinth_filter" class="blue_text_button">' + labels.filter + '</button>');
        $("h3.panel-title").append(createFilterBox("default"));
        createFilterEvents();
    });

    function getFilterGirlData() {
        arenaGirls = $('.harem-panel-girls .harem-girl-container');

        girlsData = $.map(arenaGirls, function(girl, index) {
            return JSON.parse($(girl).find('.girl_img').attr("data-new-girl-tooltip"));
        });
    }

    function createFilterEvents() {
        $("#labyrinth_filter").on('click', function() {
            if (typeof arenaGirls == 'undefined' || typeof girlsData == 'undefined') return;
            let currentBoxDisplay = $("#labyrinth_filter_box").css('display');
            $("#labyrinth_filter_box").css('display', currentBoxDisplay == "none" ? 'block' : 'none');
        });
        $("#filter_class").on('change', filterGirls);
        $("#filter_rarity").on('change', filterGirls);
        $("#filter_name").get(0).oninput = filterGirls;
        $("#filter_aff_category").on('change', filterGirls);
        $("#filter_aff_lvl").on('change', filterGirls);
        $("#filter_element").on('change', filterGirls);
        $("#filter_skill5").on('change', filterGirls);
    }

    function filterGirls() {
        let filterClass = $("#filter_class").get(0).selectedIndex;
        let filterRarity = $("#filter_rarity").get(0).value;
        let filterName = $("#filter_name").get(0).value;
        let nameRegex = new RegExp(filterName, "i");
        let filterAffCategory = $("#filter_aff_category").get(0).value;
        let filterAffLvl = $("#filter_aff_lvl").get(0).value;
        let filterElement = $("#filter_element").get(0).value;
        let filterSkill5 = $("#filter_skill5").get(0).value;

        let girlsFiltered = $.map(girlsData, function(girl, index) {
            let matchesClass = (girl.class == filterClass) || (filterClass == 0);
            let matchesRarity = (girl.rarity == filterRarity) || (filterRarity == 'all');
            let matchesName = (girl.name.search(nameRegex) > -1);

            let affectionStr = girl.graded2;
            let affectionCategoryStr = affectionStr.split('</g>');
            let affectionCategory = affectionCategoryStr.length-1;
            let affectionLvlStr = affectionStr.split('<g >');
            let affectionLvl = affectionLvlStr.length-1;

            let matchesAffCategory = (affectionCategory == filterAffCategory) || (filterAffCategory == 'all');
            let matchesAffLvl = (affectionLvl == filterAffLvl) || (filterAffLvl == 'all');
            let matchesElement = (girl.element == filterElement) || (filterElement == 'all');

            let skill5Active = 0;
            if (girl.skill_tiers_info[5] != undefined) skill5Active = (girl.skill_tiers_info[5].skill_points_used == 0) ? 0 : 1;
            let matchesSkill5 = (skill5Active == filterSkill5) || (filterSkill5 == 'all');

            return (matchesClass && matchesRarity && matchesName && matchesAffCategory && matchesAffLvl && matchesElement && matchesSkill5) ? index : null;
        });

        $.each(arenaGirls, function(index, girlElem) {
            $(girlElem).css('display', $.inArray(index, girlsFiltered) > -1 ? 'block' : 'none');
        });

        //update scroll display
        $('.harem-panel-girls').css('overflow', '');
        $('.harem-panel-girls').css('overflow', 'hidden');
    }

    function createFilterBox() {
        let totalHTML = '<div id="labyrinth_filter_box" class="form-wrapper">';

        totalHTML += '<div class="form-control"><div class="input-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_name">' + window.GT.design.Name + '</label>'
            + '<input type="text" autocomplete="off" id="filter_name" placeholder="' + labels.girl_name + '" icon="search">'
            + '</div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_class">' + window.GT.design.mythic_equipment_class + '</label>'
            + '<select name="filter_class" id="filter_class" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="hardcore">' + window.GT.design.class_hardcore + '</option>'
            + '<option value="charm">' + window.GT.design.class_charm + '</option>'
            + '<option value="knowhow">' + window.GT.design.class_knowhow + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_element">' + labels.element + '</label>'
            + '<select name="filter_element" id="filter_element" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="darkness" style="color: #000; text-shadow: 1px 1px 0 #24a0ff,-1px 1px 0 #24a0ff,-1px -1px 0 #24a0ff,1px -1px 0 #24a0ff;">' + window.GT.design.darkness_flavor_element + '</option>'
            + '<option value="light" style="color: #fff;">' + window.GT.design.light_flavor_element + '</option>'
            + '<option value="psychic" style="color: #7e0c8e;">' + window.GT.design.psychic_flavor_element + '</option>'
            + '<option value="fire" style="color: #ff2a52;">' + window.GT.design.fire_flavor_element + '</option>'
            + '<option value="nature" style="color: #00e772;">' + window.GT.design.nature_flavor_element + '</option>'
            + '<option value="stone" style="color: #cb6f2b;">' + window.GT.design.stone_flavor_element + '</option>'
            + '<option value="sun" style="color: #fff049;">' + window.GT.design.sun_flavor_element + '</option>'
            + '<option value="water" style="color: #24a0ff;">' + window.GT.design.water_flavor_element + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_rarity">' + window.GT.design.selectors_Rarity + '</label>'
            + '<select name="filter_rarity" id="filter_rarity" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="starting">' + window.GT.design.girls_rarity_starting + '</option>'
            + '<option value="common">' + window.GT.design.girls_rarity_common + '</option>'
            + '<option value="rare">' + window.GT.design.girls_rarity_rare + '</option>'
            + '<option value="epic">' + window.GT.design.girls_rarity_epic + '</option>'
            + '<option value="legendary">' + window.GT.design.girls_rarity_legendary + '</option>'
            + '<option value="mythic">' + window.GT.design.girls_rarity_mythic + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_skill5">' + window.GT.design.girl_skills + ' ' + window.GT.design.tier + ' 5</label>'
            + '<select name="filter_skill5" id="filter_skill5" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value=1>' + window.GT.design.Yes + '</option>'
            + '<option value=0>' + window.GT.design.No + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_aff_category">' + window.GT.design.affection_category + '</label>'
            + '<select name="filter_aff_category" id="filter_aff_category" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="1">' + labels.one_star + '</option>'
            + '<option value="3">' + labels.three_stars + '</option>'
            + '<option value="5">' + labels.five_stars + '</option>'
            + '<option value="6">' + labels.six_stars + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group" style="break-inside: avoid;">'
            + '<label class="head-group" for="filter_aff_lvl">' + labels.aff_lvl + '</label>'
            + '<select name="filter_aff_lvl" id="filter_aff_lvl" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option>'
            + '<option value="0">' + labels.zero_star + '</option>'
            + '<option value="1">' + labels.one_star + '</option>'
            + '<option value="2">' + labels.two_stars + '</option>'
            + '<option value="3">' + labels.three_stars + '</option>'
            + '<option value="4">' + labels.four_stars + '</option>'
            + '<option value="5">' + labels.five_stars + '</option>'
            + '<option value="6">' + labels.six_stars + '</option>'
            + '</select></div></div>';

        totalHTML += '</div>';

        return totalHTML;
    }

    //CSS
    sheet.insertRule('#labyrinth_filter_box {'
                     + 'columns: 2;'
                     + 'position: absolute;'
                     + 'width: 417px;'
                     + 'right: 408px;'
                     + 'z-index: 99;'
                     + 'border-radius: 8px 10px 10px 8px;'
                     + 'background-color: #1e261e;'
                     + 'box-shadow: rgba(255, 255, 255, 0.73) 0px 0px;'
                     + 'padding: 5px;'
                     + 'border: 1px solid #ffa23e;'
                     + 'display: none;}'
                    );
    
    sheet.insertRule(`${mediaMobile} {`
                     + '#labyrinth_filter_box {'
                     + 'top: 119px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#labyrinth_filter_box {'
                     + 'top: 90px;}}'
                    );

    sheet.insertRule('.form-control {'
                     + 'display: grid;}'
                    );

    sheet.insertRule('.form-wrapper > .form-control > .select-group > select > option {'
                     + 'font-weight: bold;'
                     + 'text-shadow: 1px 1px 0 #000,-1px 1px 0 #000,-1px -1px 0 #000,1px -1px 0 #000;}'
                    );

    sheet.insertRule('.personal_info.hero {'
                     + 'margin-top: 5px; }'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.change-team-panel #filter_girls {'
                     + 'margin-top: 16px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.change-team-panel #filter_girls {'
                     + 'margin-top: 11px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.change-team-panel #labyrinth_filter {'
                     + 'position: absolute;'
                     + 'font-size: 16px;'
                     + 'width: 84px;'
                     + 'height: 47px;'
                     + 'top: 82px;'
                     + 'right: 98px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.change-team-panel #labyrinth_filter {'
                     + 'position: absolute;'
                     + 'font-size: 16px;'
                     + 'width: 84px;'
                     + 'height: 47px;'
                     + 'top: 60px;'
                     + 'right: 98px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.change-team-panel .panel-title {'
                     + 'margin-right: 70px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#change-team-page .change-team-panel.team-panel {'
                     + 'margin-top: 20px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#change-team-page .change-team-panel.harem-panel {'
                     + 'margin-top: 17px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.change-team-panel .panel-title {'
                     + 'margin-right: 70px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.team-context {'
                     + 'top: 5rem !important;}}'
                    );

    sheet.insertRule('.form-wrapper > .form-control label.head-group {'
                     + 'text-align: left;}'
                    );

    sheet.insertRule('.team-context {'
                     + 'top: 3.3rem !important;}'
                    );
}


/* =========================================
	CHAMPIONS INFORMATION (Credit: Entwine)
   ========================================= */

function moduleChampions() {
    if (sessionStorage.getItem('championsCallBack') && $('.page-shop').length) {
        const championsCallBack = JSON.parse(sessionStorage.getItem('championsCallBack'));
        $('#breadcrumbs .back').after('<span>&gt;</span><a class="back" href="' + transformNutakuURL('/champions-map.html') + '" >'
                                      + $('nav [rel="content"] a[href="' + transformNutakuURL('/champions-map.html') + '"]').text().trim()
                                      + '<span class="mapArrowBack_flat_icn"></span></a><span>&gt;</span><a class="back" href="'
                                      + championsCallBack.location + '">'
                                      + championsCallBack.name + '<span class="mapArrowBack_flat_icn"></span></a>');
        sessionStorage.removeItem('championsCallBack');
    }
    else if(CurrentPage.indexOf('/champions-map') != -1) {
        const champions_unlocked = $('.champion-lair-girl').length - $('.champion-lair-name.locked').length ;
        localStorage.setItem('HHS.nb_champions', champions_unlocked);
    }
    else if(CurrentPage.indexOf('/champions/') != -1 || CurrentPage.indexOf('/club-champion') != -1) {
        const DEFAULT_CHAMPIONS_DATA = '{"attempts": {}, "config" : {}, "positions" : {}, "statistics" : {}}';
        const personalKey = window.Hero.infos.id + '/' + window.championData.champion.id;
        let championsData = ($('.page-champions').length == 1) ? JSON.parse(localStorage.getItem('HHS.championsData') || DEFAULT_CHAMPIONS_DATA) : JSON.parse(localStorage.getItem('HHS.clubChampionsData') || DEFAULT_CHAMPIONS_DATA);
        let positions = championsData.positions[personalKey];
        let positions2 = window.championData.champion.poses;
        let statistics = championsData.statistics[window.championData.champion.id];
        let attempts = championsData.attempts[personalKey] || 0;
        let config = championsData.config[window.Hero.infos.id] || {};

        $('.champions-top__title').append('<span class="champion-lvl">(' + window.GT.design.Lvl + window.championData.champion.level + ')</span>');

        let page = (CurrentPage.indexOf('/champions/') != -1) ? $('.page-champions') : $('.page-club_champion');
        let isSkipButtonClicked;
        markMatchedPositions();
        highlightGirlPose();
        if (CurrentPage.indexOf('/champions/') != -1) {
            showAdditionalInformation();
        }

        showNumberOfTicketsWhileTeamResting();

        page
            .on('click', '.champions-bottom__draft-box > button', () => {setTimeout(() => {markMatchedPositions()}, 1000)})
            .on('click', '.champions-bottom__confirm-team', showNumberOfTicketsWhileTeamResting)
            .on('click', '.champions-bottom__skip-champion-cooldown', () => {isSkipButtonClicked = true});
        $('.page-club_champion')
            .on('click', '.champions-bottom__draft-box > button', () => {setTimeout(() => {markMatchedPositions()}, 1000)})
            .on('click', '.champions-bottom__confirm-team', showNumberOfTicketsWhileTeamResting)
            .on('click', '.champions-bottom__skip-champion-cooldown', () => {isSkipButtonClicked = true});
        $(window).on('beforeunload', () => {
            championsData = (window.location.pathname.indexOf('/champions/') != -1) ? JSON.parse(localStorage.getItem('HHS.championsData') || DEFAULT_CHAMPIONS_DATA) : JSON.parse(localStorage.getItem('HHS.clubChampionsData') || DEFAULT_CHAMPIONS_DATA);
            championsData.positions[personalKey] = positions;
            championsData.attempts[personalKey] = attempts;
            championsData.statistics[window.championData.champion.id] = statistics;
            championsData.config[window.Hero.infos.id] = Object.keys(config).length? config : undefined;
            if (window.location.pathname.indexOf('/champions/') != -1) {
                localStorage.setItem('HHS.championsData', JSON.stringify(championsData));
            }
            else {
                localStorage.setItem('HHS.clubChampionsData', JSON.stringify(championsData));
            }
        });
        $(document).ajaxComplete(function(event, xhr, options) {
            if(!xhr.responseText.length) return;

            const response = JSON.parse(xhr.responseText);

            if(!response || !response.success) return;

            if (response.positions) {
                if (!positions) {
                    if (!statistics) {
                        statistics = Array($('.rounds-info__figures .figure').length).fill(0);
                    }
                    response.positions.forEach((e) => statistics[e]++);
                    attempts = 0;
                }
                if (response.final.attacker_ego > 0 || response.final.winner.type == 'hero') {
                    positions = undefined;
                }
                else {
                    positions = response.positions;
                }
                attempts += parseInt($('.champions-bottom__amount-slider .input-field .battles-number')[0].innerText, 10);
            }
            else {
                markMatchedPositions();
            }
            if (isSkipButtonClicked) {
                showAdditionalInformation();
                isSkipButtonClicked = false;
            }
        });
        const restTimer = $('.champions-bottom__rest [timer], .champions-middle__champion-resting[timer]');
        if (restTimer.is(':visible')) {
            const delayTime = Math.ceil(restTimer.attr('timer') * 1000 - Date.now());
            markMatchedPositions;
            setTimeout(markMatchedPositions, delayTime + 400);
        }

        if(CurrentPage.indexOf('/champions/') != -1) championShortcuts();

        function showAdditionalInformation() {
            if ($('.champions-middle__champion-resting-text').is(':visible') && positions) {
                positions = undefined;
            }
            if ($('#additionalInformation').is(':visible')) {
                return;
            }
            if (positions) {
                createCurrentPositionsInfo();
            }
            else if (statistics) {
                createStatisticsInfo();
            }
            if (positions || statistics) {
                configureInfoBox();
            }
        }

        function markMatchedPositions() {
            $('.girl-selection__girl-box').each(function(index) {
                const currentGirlsPose = $(this).find('.girl-box__pose');
                const currentGirlsPower = $(this).find('.damage_number');

                if (currentGirlsPose.next().length == 0) {
                    currentGirlsPose.parent().append('<span style="margin-left: 35px;" />');
                }
                if (positions2) {
                    if (currentGirlsPose.attr('src').indexOf(preparePositionImage(positions2[index % positions2.length])) >= 0) {
                        currentGirlsPose.next().removeClass('empty');
                        currentGirlsPose.next().addClass('green-tick-icon');
                        currentGirlsPose.next().css('filter', 'none');
                        currentGirlsPower.css('color', '#b0ff26');
                    }
                    else if (positions2.some((e) => (preparePositionImage(e) == currentGirlsPose.attr('src')))) {
                        currentGirlsPose.next().addClass('green-tick-icon empty');
                        currentGirlsPose.next().css('filter', 'hue-rotate(-233deg)');
                        let newPower = localeStringToNumber(currentGirlsPower.attr('hh_title'))*2;
                        if (newPower < 100000) currentGirlsPower[0].innerText = nRounding(newPower, 1, 1);
                        else currentGirlsPower[0].innerText = nRounding(newPower, 0, 1);
                        currentGirlsPower.css('color', '#009fff');
                    }
                    else {
                        currentGirlsPose.next().removeClass('green-tick-icon');
                    }
                }
                else if (statistics) {
                    currentGirlsPose.next().css({'filter': 'invert'});
                    if (statistics.some((elem, idx) => (elem > 0 && preparePositionImage(idx) == currentGirlsPose.attr('src')))) {
                        currentGirlsPose.next().addClass('green-tick-icon empty');
                        currentGirlsPose.next().css('filter', 'hue-rotate(-233deg)');
                    }
                    else {
                        currentGirlsPose.next().removeClass('green-tick-icon');
                    }
                }
            });
        }

        function showNumberOfTicketsWhileTeamResting() {
            if ($('.champions-bottom__ticket-amount').is(':visible') == false) {
                $('.champions-bottom__rest').css({'width': '280px'})
                    .before('<div class="champions-bottom__ticket-amount"><span class="ticket_icn"></span><span cur="ticket">x ' + window.championData.champion.currentTickets + '</span></div>');
            }
        }

        function preparePositionImage(positionID) {
            return window.IMAGES_URL + '/pictures/design/battle_positions/' + positionID + '.png';
        }

        function createCurrentPositionsInfo() {
            let positionsBox = ('<div id="additionalInformation" style="position: absolute; top:' + (config.top || 130) + 'px; right:' + (config.right || -75)
                                + 'px;"><div style="border: 2px solid #ffa23e; background-color: rgba(60,20,30,.8); border-radius: 7px; width: max-content;">&nbsp;' + labels.Current_positions + ':<div>');
            positions.forEach((e) => {
                positionsBox += '<img style="height: 48px; width: 48px; cursor: pointer;" src="' + preparePositionImage(e) + '" hh_title="' + window.GT.figures[e]+ '">';
            });
            positionsBox += '</div>&nbsp;' + labels.Current_stage + ': ' + attempts + ' ' + (attempts == 1 ? labels.attempt:labels.attempts) + '&nbsp;</div></div>';
            $('.champions-over__champion-wrapper').append(positionsBox);
            $('#additionalInformation #ascrail2000-hr').remove();
        }

        function createStatisticsInfo() {
            let statisticsBox = ('<div id="additionalInformation" style="position: absolute; top:' + (config.top || 130) + 'px; right:' + (config.right || -75)
                                 + 'px;"><div style="border: 2px solid #ffa23e; background-color: rgba(0,0,0,.8); border-radius: 7px; width: max-content;">&nbsp;' + labels.Statistics + ':'
                                 + '<div class="scroll-area" style="font-size: 14px; max-width: 208px;"><div>');
            let total = statistics.reduce((a, b) => a + b);
            let positionList = (statistics.map((elem, idx) => ({'index': idx, 'value': elem}))
                                .filter((e) => e.index > 0 && e.value > 0)
                                .sort((a, b) => (a.value == b.value)? a.index - b.index : b.value - a.value));
            positionList.forEach((p) => {
                statisticsBox += '<div style="display: inline-block; width: 52px; text-align: center;">'
                    + '<img style="height: 48px; width: 48px; margin-bottom: -6px; cursor: pointer;" src="'
                    + preparePositionImage(p.index) + '" hh_title="' + window.GT.figures[p.index] + '" ><span>'
                    + Math.round(p.value / total * 1000) / 10 + '%</span></div>';
            });
            statisticsBox += '</div></div>' + (attempts? ('&nbsp;' + labels.Prev_stage + ': ' + attempts + ' ' + (attempts == 1 ? labels.attempt:labels.attempts) + '&nbsp;') : '') + '</div></div>';
            $('.champions-over__champion-wrapper').append(statisticsBox);
            $('.champions-over__champion-wrapper').find('.scroll-area > div').css({'width': positionList.length * 52 + 'px'});
            if (positionList.length > 4) {
                if (window.is_mobile_size()) {
                    $('.champions-over__champion-wrapper').find('.scroll-area').css({'padding-bottom': '10px', 'margin-bottom': '-5px'});
                }
                else {
                    $('.champions-over__champion-wrapper').find('.scroll-area').css({'padding-bottom': '', 'margin-bottom': '5px'});
                }
                $('.champions-over__champion-wrapper').find('.scroll-area').niceScroll().resize();
            }
            $('#additionalInformation #ascrail2000-hr').remove();
        }

        function configureInfoBox() {
            $('.girl-box__draggable').droppable('option', 'accept', (e) => e.hasClass('girl-box__draggable'));
            $('#additionalInformation').on('click', '.eye', (e) => {
                config.visible = config.visible == undefined? false : undefined;
                $(e.currentTarget).next().toggle('slow');
                $(e.currentTarget).children().toggle('fast');
            }).draggable({
                cursor: 'move',
                start: function () {
                    $(this).css({'right': ''});
                },
                drag: function (event, ui) {
                    ui.position.top /= window.FullSize.scale;
                    ui.position.left /= window.FullSize.scale;
                },
                stop: function (event, ui) {
                    config.right = Math.round($(this).parent().width() - ui.position.left - $(this).width());
                    config.top = Math.round(ui.position.top);
                    $(this).css({'left': '', 'right': config.right + 'px'});
                    $(event.originalEvent.target).one('click', (e) => e.stopImmediatePropagation());
                }
            }).prepend('<a class="eye" style="top: 3px; right: 3px; position: absolute; cursor: pointer;">'
                       + '<img src="' + window.IMAGES_URL + '/quest/ic_eyeclosed.svg" style="width: 30px; display: block;">'
                       + '<img src="' + window.IMAGES_URL + '/quest/ic_eyeopen.svg" style="width: 50px; display: none;">'
                       + '</div></a>');
            if (config.visible == false) {
                $('#additionalInformation .eye').children().toggle();
                $('#additionalInformation .eye').next().toggle();
            }
        }

        //Add previous/next arrows in Places of Power to navigate easily between them
        function championShortcuts() {
            const champions_nb = parseInt(localStorage.getItem('HHS.nb_champions'), 10) || 6;
            let champions_id = [];
            for (let i=1; i<=champions_nb; i++) champions_id.push(i);
            const currentChampionId = parseInt(window.championData.champion.id, 10);

            $('.champions-over__champion-info').prepend('<a href="' + transformNutakuURL('/champions/' + champions_id[(champions_nb + (currentChampionId-2)) % champions_nb]) + '" class="round_blue_button champion_shortcut" id="previous_champion"></a>');
            $('#previous_champion').after('<a href="' + transformNutakuURL('/champions/' + champions_id[currentChampionId % champions_nb]) + '" class="round_blue_button champion_shortcut" id="next_champion"></a>');
        }

        //Highlight champion girl's pose
        function highlightGirlPose() {
            const girl_figure = window.championData.champion.girl.figure;
            window.championData.champion.poses.forEach((pose, index) => {
                if(pose == girl_figure) {
                    $($('.champion-pose')[index]).addClass('matched');
                    $('.champion-pose')[index].setAttribute('tooltip', "");
                    $('.champion-pose')[index].setAttribute('hh_title', labels.champion_girl_pose);
                }
            });
        }

        //CSS
        sheet.insertRule('.champions-bottom__ticket-amount {'
                         + 'width: 145px;}'
                        );

        sheet.insertRule('.champions-bottom__ticket-amount.right {'
                         + 'text-align: left !important;}'
                        );

        sheet.insertRule('.champion_shortcut {'
                         + 'position: absolute;'
                         + 'top: 5px;'
                         + 'pointer-events: auto !important;'
                         + 'background-size: 28px;'
                         + 'background-position: center;'
                         + 'background-repeat: no-repeat;}'
                        );

        sheet.insertRule('#previous_champion {'
                         + 'left: -35px;'
                         + 'background-image: url(https://cdn-icons-png.flaticon.com/64/2879/2879564.png) !important;}'
                        );

        sheet.insertRule('#next_champion {'
                         + 'left: 260px;'
                         + 'background-image: url(https://cdn-icons-png.flaticon.com/64/2879/2879593.png) !important;}'
                        );

        sheet.insertRule('.champions-over__champion-info .round_blue_button {'
                         + 'width: 30px !important;'
                         + 'height: 30px !important;}'
                        );

        sheet.insertRule('.champion-pose.matched {'
                         + 'filter: drop-shadow(0px 0px 3px #00ff00) drop-shadow(0px 0px 3px #00ff00) drop-shadow(0px 0px 3px #00ff00);}'
                        );

        sheet.insertRule('.champions-over__champion-wrapper {'
                         + 'pointer-events: auto !important;}'
                        );
    }
}


/* =======
    LINKS
   ======= */

function moduleLinks() {
    let time_now = window.server_now_ts;
    const options = {hour: '2-digit', minute: '2-digit'};

    // Current page: Homepage
    if (CurrentPage.includes('home')) home();
    // Current page: Pachinko
    else if (CurrentPage.includes('pachinko')) pachinko();
    // Current page: Activities
    else if (CurrentPage.includes('activities')){
        activities();
        if ($('#activities-tabs').children('[data-tab=pop]').length > 0) pop();
        if (window.location.href.includes('?tab=pop&index')) popShortcuts();
    }
    // Current page: Champions
    else if (CurrentPage.includes('champions')) champions();
    // Current page: Market
    else if (CurrentPage.includes('shop')) collectBoostersFromMarket();
    else if ((CurrentPage.includes('map')) || (CurrentPage.includes('world')) || (CurrentPage.includes('quest'))) questTitle();
    else if (CurrentPage.includes('path-of-valor')) pov();
    else if (CurrentPage.includes('path-of-glory')) pog();
    else if (CurrentPage == '/season.html') season();

    function calculateTime(deadline) {
        let currentTime = new Date();
        let remaining = Math.floor((deadline - currentTime.getTime())/1000);
        return convertToTimeFormat(remaining);
    }

    function convertToTimeFormat(remainingTime) {
        let remM = Math.floor(remainingTime / 60);
        let remS = remainingTime - remM*60;
        if(remainingTime < 0){
            remM = 0;
            remS = 0;
        }
        if(remM > 59){
            let remH = Math.floor(remM / 60);
            let remD = Math.floor(remH / 24);
            remM -= remH * 60;
            remH -= remD * 24;
            //if (remD > 0) return remD + labels.day + " " + remH + labels.hour + " " + remM + labels.minute + " ";
            if (remD > 0) return remD + labels.day + " " + remH + labels.hour + " ";
            return remH + labels.hour + " " + remM + labels.minute + " ";
        }
        else if(remM > 0){
            if (remS > 9) return remM + labels.minute + " " + remS + labels.second;
            else return remM + labels.minute + " 0" + remS + labels.second;
        }
        if (remS > 9 || remS < 1) return remS + labels.second;
        else return "0" + remS + labels.second;
    }

    function convertToTimeFormatMinutes(remainingTime) {
        let remM = Math.floor(remainingTime /60);
        let remS = remainingTime - remM*60;
        if(remainingTime < 0){
            remM = 0;
            remS = 0;
        }
        if(remM > 59){
            let remH = Math.floor(remM / 60);
            remM -= remH * 60;
            return remH + labels.hour + " " + remM + labels.minute + " "
        }
        else if(remM > 0) return remM + labels.minute;
        else if(remS < 10 & remS > 0) return "0" + remS + labels.second;
        return remS + labels.second;
    }

    function parseTime(remainingTimeStr) {
        let indexDay = remainingTimeStr.indexOf(labels.day);
        let indexHour = remainingTimeStr.indexOf(labels.hour);
        let indexMinute = remainingTimeStr.indexOf(labels.minute);
        let indexSecond = remainingTimeStr.indexOf(labels.second);
        let day = indexDay == -1 ? 0 : parseInt(remainingTimeStr.substring(0, indexDay).trim());
        let hour = indexHour == -1 ? 0 : parseInt(remainingTimeStr.substring(indexDay+1, indexHour).trim());
        let minute = indexMinute == -1 ? 0 : parseInt(remainingTimeStr.substring(indexHour+1, indexMinute).trim());
        let second = indexSecond == -1 ? 0 : parseInt(remainingTimeStr.substring(indexMinute+1, indexSecond).trim());
        return (day*24*3600 + hour*3600 + minute*60 + second);
    }

    getClubStatus();
    collectBoostersFromHeroUpdate();
    collectBoostersFromAjaxResponses();
    scriptTimers();

    if (localStorage.getItem("HHS.LeagueExists") == 1 && window.Hero.infos.level >= 20) {
        $('header .currency').before('<div class="league_counter" id="LeagueTimer">'
                                     + '<span class="league_icn" tooltip=""></span>'
                                     + '<a href="' + transformNutakuURL('/leagues.html') + '">'
                                     + '<div id="league_bar" class="tier_bar_league"></div>'
                                     + '<div class="white_text centered_s" style="width: 100%;">'
                                     + '<div id="league_data" style="width: 100%;">'
                                     + '<span id="scriptLeagueAttempts">0</span>/<span rel="max">' + window.Hero.energies.challenge.max_regen_amount + '</span>'
                                     + '<span id="scriptLeagueTimer" rel="league_count_txt" timeforsinglepoint="2100" timeonload="24"></span>'
                                     + '</a></div></div></div>');
    }

    if (localStorage.getItem("HHS.SeasonExists") == 1) {
        $('header .currency').before('<div class="scriptSeasonInfo" id="FightSeason">'
                                     + '<span class="season_icn" tooltip=""></span>'
                                     + '<a href="' + transformNutakuURL('/season-arena.html') + '">'
                                     + '<div id="kisses_bar" class="tier_bar_season"></div>'
                                     + '<div class="white_text centered_s" style="width: 100%;">'
                                     + '<div id="kisses_data" style="width: 100%;">'
                                     + '<span id="scriptSeasonAttempts">0</span>/<span rel="max">' + window.Hero.energies.kiss.max_regen_amount + '</span>'
                                     + '<span id="scriptSeasonTimer" rel="season_count_txt" timeforsinglepoint="3600" timeonload="24"></span>'
                                     + '</a></div></div></div>');
    }

    if (window.Hero.infos.level >= 15 && window.Hero.energies.worship != undefined) {
        $('header .currency').before('<div class="scriptPantheonInfo" id="FightPantheon">'
                                     + '<span class="pantheon_icn" tooltip=""></span>'
                                     + '<a href="' + transformNutakuURL('/pantheon.html') + '">'
                                     + '<div id="worship_bar" class="tier_bar_pantheon"></div>'
                                     + '<div class="white_text centered_s" style="width: 100%;">'
                                     + '<div id="worship_data" style="width: 100%;">'
                                     + '<span id="scriptPantheonAttempts">0</span>/<span rel="max">' + window.Hero.energies.worship.max_regen_amount + '</span>'
                                     + '<span id="scriptPantheonTimer" rel="pantheon_count_txt" timeforsinglepoint="8640"></span>'
                                     + '</a></div></div></div>');
    }

    if (localStorage.getItem("HHS.nb_Pop") > 0) {
        $('header .currency').before('<div class="pop_timer" id="PoPTimer" tooltip="">'
                                     + '<a href="' + transformNutakuURL('/activities.html?tab=pop') + '">'
                                     + '<div id="pop_bar" class="tier_bar_pop"></div>'
                                     + '<div class="white_text centered_s" style="width: 100%;">'
                                     + '<div id="pop_data" style="width: 100%;">' + labels.pop
                                     + '<span id="scriptPoPTimer" rel="pop_count_txt"></span>'
                                     + '</a></div></div></div>');
    }

    $('#fight_energy_bar .hudBattlePts_mix_icn')[0].className = "trollPts_icn";
    document.querySelector('.trollPts_icn').removeAttribute('energy-fight-tooltip');
    document.querySelector('.trollPts_icn').setAttribute('tooltip', "");

    $('#quest_energy_bar .hudEnergy_mix_icn')[0].className = "energy_icn";
    document.querySelector('.energy_icn').removeAttribute('energy-quest-tooltip');
    document.querySelector('.energy_icn').setAttribute('tooltip', "");
    document.querySelector('.energy_counter_bar').setAttribute('tooltip', "");


    function scriptTimers(){
        questLink();

        addBoosterStatus();

        setInterval(function(){
            questTooltip();
            trollTooltip();
            popTimer();
            if (localStorage.getItem("HHS.LeagueExists") == 1 && window.Hero.infos.level >= 20) leagueBattles();
            if (localStorage.getItem("HHS.SeasonExists") == 1) seasonBattles();
            if (window.Hero.energies.worship != undefined && window.Hero.infos.level >= 15) pantheonBattles();
            addBoosterStatus();
        }, 1000);
    }

    function questTitle(){
        $('#breadcrumbs').css('z-index', '99');
        $('#breadcrumbs').css('top', '67px');
        $('.ico-quest[href="/quest/1305"]').css('top', '0%');
    }

    function questLink() {
        let quest_link = window.Hero.infos.questing.current_url;
        if (!quest_link.includes('quest') && window.Hero.infos.questing.id_world >= (trolls.length+1)) {
            quest_link = "/champions-help.html";
        }
        else {
            quest_link = "/quest/" + window.Hero.infos.questing.id_quest;
        }

        const $energybar = $('#quest_energy_bar .energy_counter_bar .bar-wrapper .over');
        $energybar.prepend('<a href="' + transformNutakuURL(quest_link) + '"></a>');
        $energybar.find('a').append($energybar.find('.energy_counter_amount'));
        $energybar.find('a').append($energybar.find('span[rel="count_txt"]'));
    }

    function questTooltip() {
        $('#energyTool').empty();

        let current_quest_energy = parseInt(window.Hero.energies.quest.amount, 10);
        const max_quest_energy = parseInt(window.Hero.energies.quest.max_regen_amount, 10);
        const time_for_new_quest = parseInt(window.Hero.energies.quest.seconds_per_point, 10);
        let remaining_quest_time = parseInt(window.Hero.energies.quest.next_refresh_ts, 10);
        let full_remaining_quest_time = remaining_quest_time + Math.max(0, (max_quest_energy-current_quest_energy-1))*time_for_new_quest;
        let full_quest_date = time_now + full_remaining_quest_time;

        if (current_quest_energy >= max_quest_energy) {
            document.querySelector('.energy_icn').setAttribute('hh_title', '<h5 class="">' + labels.energy + '</h5>'
                                                               + '<span class="orange" rel="timer">' + labels.full + '</span>');

            document.querySelector('.energy_counter_bar').setAttribute('hh_title', '<h5 class="">' + labels.energy + '</h5>'
                                                                        + '<span class="orange" rel="timer">' + labels.full + '</span>');
        }
        else {
            document.querySelector('.energy_icn').setAttribute('hh_title', '<h5 class="">' + labels.energy + '</h5>'
                                                               + labels.full_in + ' <span class="orange" rel="timer">' + calculateTime(full_quest_date*1000) + '</span><BR>'
                                                               + labels.ends_at + ' <span class="orange" rel="timer">' + new Date(full_quest_date*1000).toLocaleTimeString(undefined, options) + '</span><BR>'
                                                               + labels.date_on + ' ' + new Date(full_quest_date*1000).toLocaleDateString());

            document.querySelector('.energy_counter_bar').setAttribute('hh_title', '<h5 class="">' + labels.energy + '</h5>'
                                                                        + labels.full_in + ' <span class="orange" rel="timer">' + calculateTime(full_quest_date*1000) + '</span><BR>'
                                                                        + labels.ends_at + ' <span class="orange" rel="timer">' + new Date(full_quest_date*1000).toLocaleTimeString(undefined, options) + '</span><BR>'
                                                                        + labels.date_on + ' ' + new Date(full_quest_date*1000).toLocaleDateString());
        }
    }

    function trollTooltip() {
        let current_troll_energy = parseInt(window.Hero.energies.fight.amount, 10);
        const max_troll_energy = parseInt(window.Hero.energies.fight.max_regen_amount, 10);
        const time_for_new_troll = parseInt(window.Hero.energies.fight.seconds_per_point, 10);
        let remaining_troll_time = parseInt(window.Hero.energies.fight.next_refresh_ts, 10);
        let full_remaining_troll_time = remaining_troll_time + Math.max(0, (max_troll_energy-current_troll_energy-1))*time_for_new_troll;
        let full_troll_date = time_now + full_remaining_troll_time;

        if (current_troll_energy >= max_troll_energy) {
            document.querySelector('.trollPts_icn').setAttribute('hh_title', '<h5 class="">' + labels.combativity + '</h5>'
                                                                 + '<span class="orange" rel="timer">' + labels.full + '</span>');
        }
        else {
            document.querySelector('.trollPts_icn').setAttribute('hh_title', '<h5 class="">' + labels.combativity + '</h5>'
                                                                 + labels.full_in + ' <span class="orange" rel="timer">' + calculateTime(full_troll_date*1000) + '</span><BR>'
                                                                 + labels.ends_at + ' <span class="orange" rel="timer">' + new Date(full_troll_date*1000).toLocaleTimeString(undefined, options) + '</span><BR>'
                                                                 + labels.date_on + ' ' + new Date(full_troll_date*1000).toLocaleDateString());
        }
    }

    function pop(){
        let current_date_sec = Math.floor(new Date().getTime()/1000);
        let popDate = current_date_sec;
        let popTime = 0;
        let popRemainingTime = 0;
        let popList = [];
        let popId = 0;
        let popAll = document.getElementsByClassName("pop_thumb");
        for (let i=0; i<popAll.length; i++) {
            let className = popAll[i].className;
            if (!className.includes('greyed')) {
                popList.push(popAll[i]);

                let id = parseInt(popAll[i].attributes.pop_id.nodeValue, 10);
                if ((id >= 7 && id <= 9) || (id >= 13 && id <= 15)) {
                    $('div.pop_thumb_container:nth-child(3)').after($('div.pop_thumb_container:nth-child(' + (i+1) + ')'));
                }
            }
        }
        let nb_Pop = popList.length
        localStorage.setItem("HHS.nb_Pop", nb_Pop);
        update();

        function update() {
            for (let i=0; i<popList.length; i++) {
                if (popList[i].className.includes('pop_thumb_selected')) {
                    popId = (i+1);
                }
                if (popList[i].attributes[2].value == "pending_reward") {
                    popDate = current_date_sec;
                    popTime = 0;
                }
                else if (popList[i].attributes[2].value == "can_start") {
                    localStorage.setItem("HHS.pop_" + (i+1) + "_can_start", "true");
                }
                else {
                    let id = parseInt(popList[i].attributes.pop_id.nodeValue, 10);
                    popRemainingTime = parseInt(window.pop_data[id].remaining_time, 10);
                    popDate = current_date_sec + popRemainingTime;
                    popTime = window.pop_data[id].time_to_finish;
                    localStorage.setItem("HHS.pop_" + (i+1) + "_can_start", "false");
                }
                if (current_date_sec > localStorage.getItem("HHS.popDate" + (i+1))) {
                    localStorage.setItem("HHS.popDate" + (i+1), popDate);
                    localStorage.setItem("HHS.popTime" + (i+1), popTime);
                }
            }
        }

        let button = document.querySelector('#pop_info .pop_central_part.dark_subpanel_box button.blue_button_L');
        button.addEventListener('click', function(){
            popRemainingTime = parseTime($('.pop_remaining > span:nth-child(1)')[0].innerText);
            popDate = current_date_sec + popRemainingTime;
            popTime = popRemainingTime;
            localStorage.setItem("HHS.pop_" + popId + "_can_start", "false");
            localStorage.setItem("HHS.popDate" + popId, popDate);
            localStorage.setItem("HHS.popTime" + popId, popTime);
        });

        displayClassGirl();

        function displayClassGirl() {
            let girls = $('#pop #pop_info .pop_right_part .grid_view')[0].children;

            for (let i=0; i<girls.length; i++) {
                let girl_class = 0;
                try {
                    let girl_pose = parseInt(JSON.parse(girls[i].children[0].children[0].attributes["data-new-girl-tooltip"].nodeValue).position_img.replace(/[^\d]/g, ""), 10);
                    if (girl_pose < 5) girl_class = 1;
                    else if (girl_pose > 4 && girl_pose < 9) girl_class = 2;
                    else girl_class = 3;
                    $($('#pop #pop_info .pop_right_part .grid_view .not_selected')[i]).find('.girl_action').append($('<img class="classGirl" src="' + window.IMAGES_URL + '/pictures/misc/items_icons/' + girl_class + '.png">'));
                } catch {}
            }

            sheet.insertRule('.classGirl {'
                             + 'position: relative;'
                             + 'height: 17px !important;'
                             + 'width: 17px !important;'
                             + 'top: -98px;'
                             + 'left: 25px;'
                             + 'border: none;}'
                            );

            let button2 = document.querySelector('#rewards_popup .popup_buttons button.blue_button_L');
            button2.addEventListener('click', function(){
                displayClassGirl();
            });
        }
    }

    function popTimer() {
        let current_date_sec = Math.floor(new Date().getTime()/1000);
        const nb_Pop = localStorage.getItem("HHS.nb_Pop") || 0;
        let popDate = [];
        let popTime = [];
        let time_remaining = 0;
        let pop_percent = 100;
        let pop_can_start = false;

        if (nb_Pop > 0) {
            for (let i=0; i<nb_Pop; i++){
                if (localStorage.getItem("HHS.pop_" + (i+1) + "_can_start") == "true") {
                    pop_can_start = true;
                }
                else {
                    let popDate_i = parseInt(localStorage.getItem("HHS.popDate" + (i+1)), 10) || 0;
                    popDate.push(popDate_i);
                    let popTime_i = parseInt(localStorage.getItem("HHS.popTime" + (i+1)), 10) || 0;
                    popTime.push(popTime_i);
                    if (popDate_i == 0) {
                        localStorage.setItem("HHS.popDate" + (i+1), popDate_i);
                    }
                }
            }
            let popDateMin = Math.min(...popDate);
            if (popDateMin == Infinity) {
                popDateMin = current_date_sec;
            }
            time_remaining = popDateMin - current_date_sec || 0;
            let index = popDate.indexOf(popDateMin);
            pop_percent = Math.min(100, ((popTime[index]-(popDate[index]-current_date_sec))/popTime[index])*100);

            $('#scriptPoPTimer').html(" " + labels.in + " <span rel=\"pop_count\">" + convertToTimeFormat(time_remaining) + "</span>");
            $('#pop_bar').css('width', pop_percent + '%');

            if (time_remaining > 0) {
                $('.tier_bar_pop').css('background-image', 'linear-gradient(90deg,#780049,#c80053)');

                document.querySelector('#PoPTimer').setAttribute('hh_title', labels.ends_at + ' <span class="orange" rel="timer">' + new Date(popDateMin*1000).toLocaleTimeString(undefined, options) + '</span><BR>'
                                                                 + labels.date_on + ' ' + new Date(popDateMin*1000).toLocaleDateString());

                if (pop_can_start == true) {
                    $('#scriptPoPTimer').css('color', 'orange');
                }
                else {
                    $('#scriptPoPTimer').css('color', '#8ec3ff');
                }
            }
            else {
                $('.tier_bar_pop').css('background-image', 'linear-gradient(to top,#008ed5 0,#05719c 100%)');
            }
        }
    }

    //Add previous/next arrows in Places of Power to navigate easily between them
    function popShortcuts() {
        let currentPop = $('.pop_thumb_selected')[0].attributes.pop_id.nodeValue;
        let popList = [];
        let popAll = document.getElementsByClassName("pop_thumb");
        for (let i=0; i<popAll.length; i++) {
            let className = popAll[i].className;
            if (!className.includes('greyed')) {
                popList.push(popAll[i].attributes.pop_id.nodeValue);
            }
        }
        let currentIndex = popList.indexOf(currentPop);
        let previousPop = (currentIndex == 0) ? popList[popList.length - 1] : popList[currentIndex-1];
        let nextPop = (currentIndex == popList.length - 1) ? popList[0] : popList[currentIndex+1];

        $('.pop_right_part').prepend('<a href="' + transformNutakuURL('/activities.html?tab=pop&index=' + previousPop) + '" class="back_button" id="previous_pop"></a>');

        $('.pop_right_part a:nth-child(1)').after('<a href="' + transformNutakuURL('/activities.html?tab=pop&index=' + nextPop) + '" class="back_button" id="next_pop"></a>');


        //CSS
        sheet.insertRule('#previous_pop {'
                         + 'position: absolute;'
                         + 'background-image: url(https://cdn-icons-png.flaticon.com/64/2879/2879564.png) !important;'
                         + 'background-size: 38px;'
                         + 'background-position: center;'
                         + 'background-repeat: no-repeat;}'
                        );

        sheet.insertRule(`${mediaDesktop} {`
                         + '#previous_pop {'
                         + 'bottom: 4px;'
                         + 'right: 301px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#previous_pop {'
                         + 'bottom: 0px;'
                         + 'right: 317px;}}'
                        );

        sheet.insertRule('#next_pop {'
                         + 'position: absolute;'
                         + 'background-image: url(https://cdn-icons-png.flaticon.com/64/2879/2879593.png) !important;'
                         + 'background-size: 38px;'
                         + 'background-position: center;'
                         + 'background-repeat: no-repeat;}'
                        );

        sheet.insertRule(`${mediaDesktop} {`
                         + '#next_pop {'
                         + 'bottom: 4px;'
                         + 'right: 14px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#next_pop {'
                         + 'bottom: 0px;'
                         + 'right: 15px;}}'
                        );

        sheet.insertRule('button[rel=pop_finish] {'
                         + 'margin-right: 16px;}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + 'button[rel=pop_finish] {'
                         + 'margin-top: -22px !important;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + 'button[rel=pop_auto_assign] {'
                         + 'height: auto !important;'
                         + 'min-height: 56px;'
                         + 'max-width: 210px;}}'
                        );

        sheet.insertRule(`${mediaDesktop} {`
                         + 'button[rel=pop_auto_assign] {'
                         + 'height: auto !important;'
                         + 'min-height: 40px;'
                         + 'max-width: 210px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#pop .pop_right_part .grid_view {'
                         + 'height: 320px !important;}}'
                        );

        sheet.insertRule(`${mediaDesktop} {`
                         + '#pop .pop_right_part .grid_view {'
                         + 'height: 330px !important;}}'
                        );

        sheet.insertRule('#pop .pop_rewards_container.pop_rewards_page {'
                         + 'margin-top: 15px;}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#pop .pop_central_part .pop_remaining {'
                         + 'margin-top: 0px !important;}}'
                        );

        sheet.insertRule(`${mediaDesktop} {`
                         + '#pop .pop_central_part .pop_remaining {'
                         + 'margin-top: 0px !important;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#pop_info .pop_left_part .shards_bar_wrapper.shards_bar_page {'
                         + 'margin-top: 380px !important;}}'
                        );

        sheet.insertRule('#pop .pop_rewards_container .pop_rewards .reward_wrap > div {'
                         + 'margin-right: 35px !important;}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#pop .pop_central_part > button[rel="pop_action"] {'
                         + 'margin-top: 0px !important;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#pop .pop_central_part > button[rel="pop_claim"] {'
                         + 'margin-top: 0px !important;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#pop .pop_central_part .pop_remaining_state {'
                         + 'top: -15px !important;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#pop .pop_central_part > .hh_bar {'
                         + 'margin-top: 17px !important;}}'
                        );
    }

    function leagueBattles(){
        let time = Math.floor(new Date().getTime()/1000);
        let attempts = parseInt(window.Hero.energies.challenge.amount, 10);
        const max_attempts = parseInt(window.Hero.energies.challenge.max_regen_amount, 10);
        const time_for_new_battle = parseInt(window.Hero.energies.challenge.seconds_per_point, 10);
        let league_next_battle_in = parseInt(window.Hero.energies.challenge.next_refresh_ts, 10);
        let league_time_full = time_now + league_next_battle_in + Math.max(0, (max_attempts-attempts-1))*time_for_new_battle;
        let remaining_full_time = league_time_full-time;
        let remaining_next_battle = remaining_full_time%time_for_new_battle;

        if ((attempts < max_attempts) && (CurrentPage.indexOf('leagues') == -1)) {
            attempts = max_attempts - Math.max(0, Math.ceil(remaining_full_time/time_for_new_battle));
        }
        let league_percent = (Math.min(attempts, max_attempts)/max_attempts)*100;
        $('#league_bar').css('width', league_percent + '%');
        $('#scriptLeagueAttempts').text(attempts);

        if(attempts < max_attempts) {
            $('#scriptLeagueTimer').html(" +1 " + labels.in + " <span rel=\"count\">" + convertToTimeFormat(remaining_next_battle) + "</span>");

            document.querySelector('.league_icn').setAttribute('hh_title', '<h5 class="">' + labels.league + '</h5>'
                                                               + labels.full_in + ' <span class="orange" rel="timer">' + convertToTimeFormat(remaining_full_time) + '</span><BR>'
                                                               + labels.ends_at + ' <span class="orange" rel="timer">' + new Date(league_time_full*1000).toLocaleTimeString(undefined, options) + '</span><BR>'
                                                               + labels.date_on + ' ' + new Date(league_time_full*1000).toLocaleDateString());

            $('.tier_bar_league').css('background-image', 'linear-gradient(90deg,#780049,#c80053)');
        }
        else {
            $('#scriptLeagueTimer').empty();

            document.querySelector('.league_icn').setAttribute('hh_title', '<h5 class="">' + labels.league + '</h5>'
                                                               + '<span class="orange" rel="timer">' + labels.full + '</span>');

            $('.tier_bar_league').css('background-image', 'linear-gradient(to top,#008ed5 0,#05719c 100%)');
        }
    }

    function seasonBattles(){
        let time = Math.floor(new Date().getTime()/1000);
        let timestamp_last_kiss = parseInt(window.Hero.energies.kiss.update_ts, 10);
        let current_kisses = parseInt(window.Hero.energies.kiss.amount, 10);
        const max_kisses_number = parseInt(window.Hero.energies.kiss.max_regen_amount, 10);
        const time_for_new_kiss = parseInt(window.Hero.energies.kiss.seconds_per_point, 10);
        let new_kiss_in = parseInt(window.Hero.energies.kiss.next_refresh_ts, 10);
        let full_time_remaining = new_kiss_in + Math.max(0, (max_kisses_number-current_kisses-1))*time_for_new_kiss;
        let season_date_full = time_now + full_time_remaining;
        let season_time_remaining = season_date_full - time;
        let current_date = Math.floor(new Date().getTime()/1000);
        let all_kisses = current_kisses;
        let time_passed_sec = current_date - timestamp_last_kiss;

        if (current_kisses < max_kisses_number) {
            all_kisses = max_kisses_number - Math.max(0, Math.ceil((season_date_full - current_date)/time_for_new_kiss));
        }

        let kisses_percent = (Math.min(all_kisses, max_kisses_number)/max_kisses_number)*100;
        $('#kisses_bar').css('width', kisses_percent + '%');

        $('#scriptSeasonAttempts').text(all_kisses);

        if (all_kisses < max_kisses_number) {
            $('#scriptSeasonTimer').html(" +1 " + labels.in + " <span rel=\"season_count\">" + convertToTimeFormat(Math.floor(time_for_new_kiss - (time_passed_sec%time_for_new_kiss))) + "</span>");

            document.querySelector('.season_icn').setAttribute('hh_title', '<h5 class="">' + labels.season + '</h5>'
                                                               + labels.full_in + ' <span class="orange" rel="timer">' + convertToTimeFormat(season_time_remaining) + '</span><BR>'
                                                               + labels.ends_at + ' <span class="orange" rel="timer">' + new Date((time_now + full_time_remaining)*1000).toLocaleTimeString(undefined, options) + '</span><BR>'
                                                               + labels.date_on + ' ' + new Date((time_now + full_time_remaining)*1000).toLocaleDateString());

            $('.tier_bar_season').css('background-image', 'linear-gradient(90deg,#780049,#c80053)');
        }
        else {
            $('#scriptSeasonTimer').empty();

            document.querySelector('.season_icn').setAttribute('hh_title', '<h5 class="">' + labels.season + '</h5>'
                                                               + '<span class="orange" rel="timer">' + labels.full + '</span>');

            $('.tier_bar_season').css('background-image', 'linear-gradient(to top,#008ed5 0,#05719c 100%)');
        }
    }

    function pantheonBattles() {
        let time = Math.floor(new Date().getTime()/1000);
        let timestamp_last_worship = parseInt(window.Hero.energies.worship.update_ts, 10);
        let current_worships = parseInt(window.Hero.energies.worship.amount, 10);
        const max_worships_number = parseInt(window.Hero.energies.worship.max_regen_amount, 10);
        const time_for_new_worship = parseInt(window.Hero.energies.worship.seconds_per_point, 10);
        let new_worship_in = parseInt(window.Hero.energies.worship.next_refresh_ts, 10);
        let full_time_remaining = new_worship_in + Math.max(0, (max_worships_number-current_worships-1))*time_for_new_worship;
        let pantheon_date_full = time_now + full_time_remaining;
        let pantheon_time_remaining = pantheon_date_full - time;
        let current_date = Math.floor(new Date().getTime()/1000);
        let all_worships = current_worships;
        let time_passed_sec = current_date - timestamp_last_worship;

        if (current_worships < max_worships_number) {
            all_worships = max_worships_number - Math.max(0, Math.ceil((pantheon_date_full - current_date)/time_for_new_worship));
        }

        let worships_percent = (Math.min(all_worships, max_worships_number)/max_worships_number)*100;
        $('#worship_bar').css('width', worships_percent + '%');

        $('#scriptPantheonAttempts').text(all_worships);

        if (all_worships < max_worships_number) {
            $('#scriptPantheonTimer').html(" +1 " + labels.in + " <span rel=\"pantheon_count\">" + convertToTimeFormat(Math.floor(time_for_new_worship - (time_passed_sec%time_for_new_worship))) + "</span>");

            document.querySelector('.pantheon_icn').setAttribute('hh_title', '<h5 class="">' + labels.pantheon + '</h5>'
                                                                 + labels.full_in + ' <span class="orange" rel="timer">' + convertToTimeFormat(pantheon_time_remaining) + '</span><BR>'
                                                                 + labels.ends_at + ' <span class="orange" rel="timer">' + new Date((time_now + full_time_remaining)*1000).toLocaleTimeString(undefined, options) + '</span><BR>'
                                                                 + labels.date_on + ' ' + new Date((time_now + full_time_remaining)*1000).toLocaleDateString());

            $('.tier_bar_pantheon').css('background-image', 'linear-gradient(90deg,#780049,#c80053)');
        }
        else {
            $('#scriptPantheonTimer').empty();

            document.querySelector('.pantheon_icn').setAttribute('hh_title', '<h5 class="">' + labels.pantheon + '</h5>'
                                                                 + '<span class="orange" rel="timer">' + labels.full + '</span>');

            $('.tier_bar_pantheon').css('background-image', 'linear-gradient(to top,#008ed5 0,#05719c 100%)');
        }
    }

    function home() {
        //Check if the player have access to the league or if the league exists
        if ($('a[href$="leagues.html"]').length == 0) localStorage.setItem("HHS.LeagueExists", 0);
        else localStorage.setItem("HHS.LeagueExists", 1);

        if ($('#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-button .h_container').length == 0) localStorage.setItem("HHS.SeasonExists", 0);
        else localStorage.setItem("HHS.SeasonExists", 1);

        //Missions timer
        let next_missions_remaining_date = 0;
        if (window.missions_datas.reward == false && window.missions_datas.remaining_time == null) {
            next_missions_remaining_date = parseInt(localStorage.getItem("HHS.nextMissionsDate"), 10);

            if (time_now*1000 < next_missions_remaining_date) {
                $('#home_missions_bar1 .mission-timer-container .timer span[rel="expires"]').remove();
                $('#home_missions_bar1 .mission-timer-container .timer').append('<div style="width: 77px; font-size: 13px !important; color: rgb(255, 255, 255); text-decoration: none;"><span id="missionsTimer1" style="text-align: left;">' + calculateTime(next_missions_remaining_date) + '</span></div>');
                $('#home_missions_bar2 .mission-timer-container .timer span[rel="expires"]').remove();
                $('#home_missions_bar2 .mission-timer-container .timer').append('<div style="width: 77px; font-size: 13px !important; color: rgb(255, 255, 255); text-decoration: none;"><span id="missionsTimer2" style="text-align: left;">' + calculateTime(next_missions_remaining_date) + '</span></div>');
            }
        }
        else if (window.missions_datas.reward == true && window.missions_datas.remaining_time == null) {
            $('#home_missions_bar1 .mission-timer-container .timer span[rel="expires"]').remove();
            $('#home_missions_bar1 .mission-timer-container .timer').append('<div style="width: 77px; font-size: 13px !important; color: rgb(255, 255, 255); text-decoration: none;"><span id="missionsTimer1" style="text-align: left;">' + calculateTime(time_now) + '</span></div>');
            $('#home_missions_bar2 .mission-timer-container .timer span[rel="expires"]').remove();
            $('#home_missions_bar2 .mission-timer-container .timer').append('<div style="width: 77px; font-size: 13px !important; color: rgb(255, 255, 255); text-decoration: none;"><span id="missionsTimer2" style="text-align: left;">' + calculateTime(time_now) + '</span></div>');
        }


        //Market timer
        if($('#homepage .main-container .left-side-container a[rel="shop"] .notif-position .additional-menu-data .timer-box .timerClock_icn').length == 0) {
            let market = $('#homepage .main-container .left-side-container a[rel="shop"] .notif-position .additional-menu-data .timer-box');
            market.append('<div class="timer"><span class="timerClock_icn"></span>'
                          + '<span rel="expires">0s</span></div>');
            $('#homepage .main-container .left-side-container a[rel="shop"] .notif-position .additional-menu-data .timer').css('display', 'flex');
        }

        if ($('.script-booster-status .slot:not(.mythic):not(.empty)').length > 0) $('#homepage a[rel=shop]').find('.expired_notification_icn').remove();

        //Pachinko timer
        let pachinkoTime = localStorage.getItem("HHS.pachinkoTime");
        let pachinko = $('a[href$="pachinko.html"]>.notif-position>span');
        pachinko.append('<div id="home_pachinko_bar">'
                        +'<div class="pachinko-timer-container">'
                        + '<span class="timerClock_icn"></span>'
                        + '<div class="text"><span id="scriptPachinkoTimer">' + calculateTime(pachinkoTime) + '</span></div>'
                        + '</div></div>');

        //Champions timer
        let championsTime = (parseInt(localStorage.getItem("HHS.championsTime"), 10) > time_now*1000) ? parseInt(localStorage.getItem("HHS.championsTime"), 10) : (parseInt($('.champion-timer').attr('timer'), 10)*1000 || parseInt($('#champion-timer').attr('timer'), 10)*1000 || 0);
        if (championsTime > time_now*1000){
            let champions = $('a[rel="sex-god-path"]>.notif-position>span');
            $('.champion-timer').remove();
            $('#champion-timer').remove();

            champions.append('<div id="home_champions_bar">'
                             +'<div class="champions-timer-container">'
                             + '<span class="timerClock_icn"></span>'
                             + '<div class="text"><span id="scriptChampionsTimer">' + calculateTime(championsTime) + '</span></div>'
                             + '</div></div>');

            if (lang != "en") {
                champions.css('height', '81px');
            }
        }

        //PoV timer
        let povTime = (localStorage.getItem("HHS.PovTime") == "NaN") ? 0 : localStorage.getItem("HHS.PovTime");
        if (window.Hero.infos.level >= 30) {
            let pov = $('a[rel="path-of-valor"]>.notif-position>.pov-widget>.h_container');
            pov.append('<div id="home_pov_bar">'
                       + '<div class="pov-timer-container">'
                       + '<span class="timerClock_icn"></span>'
                       + '<div class="text"><span id="scriptPovTime">' + calculateTime(povTime*1000) + '</span></div>'
                       + '</div></div>');
        }

        //PoG timer
        let pogTime = (localStorage.getItem("HHS.PogTime") == "NaN") ? 0 : localStorage.getItem("HHS.PogTime");
        if (window.Hero.infos.level >= 30) {
            let pog = $('a[rel="path-of-glory"]>.notif-position>.pov-widget>.h_container');
            pog.append('<div id="home_pog_bar">'
                       + '<div class="pog-timer-container">'
                       + '<span class="timerClock_icn"></span>'
                       + '<div class="text"><span id="scriptPogTime">' + calculateTime(pogTime*1000) + '</span></div>'
                       + '</div></div>');
        }

        //Season timer
        let seasonTime = (localStorage.getItem("HHS.SeasonTime") == "NaN") ? 0 : localStorage.getItem("HHS.SeasonTime");
        let season = $('a[rel="season"]>.notif-position>.seasons_button>.h_container');
        season.after('<div id="home_season_bar">'
                     + '<div class="season-timer-container">'
                     + '<span class="timerClock_icn"></span>'
                     + '<div class="text"><span id="scriptSeasonTime">' + calculateTime(seasonTime*1000) + '</span></div>'
                     + '</div></div>');

        //Add sub-menus for Champions
        let championsMenu_map = '<a class="champions_menu champions_map" href="' + transformNutakuURL('/champions-map.html') + '">' + window.GT.design.Champions + '</a>';
        if (window.Hero.infos.questing.id_world > 3 || (window.Hero.infos.questing.id_world == 3 && window.Hero.infos.questing.id_quest > 5)) {
            $('a[rel="sex-god-path"]').append(championsMenu_map);
        }

        if (window.HH_UNIVERSE == 'hentai' || window.HH_UNIVERSE == 'nutaku' || window.HH_UNIVERSE == 'test_h' || window.HH_UNIVERSE == 'hh_eroges' || window.HH_UNIVERSE == 'gay' || window.HH_UNIVERSE == 'gh_nutaku' || window.HH_UNIVERSE == 'gh_eroges') {
            let championsMenu_Romero = '<a class="champions_menu champion1" href="' + transformNutakuURL('/champions/1') + '">Romero</a>';
            let championsMenu_Whaty = '<a class="champions_menu champion2" href="' + transformNutakuURL('/champions/2') + '">Whaty</a>';
            let championsMenu_Matsuda = '<a class="champions_menu champion3" href="' + transformNutakuURL('/champions/3') + '">Matsuda</a>';
            let championsMenu_Ryu = '<a class="champions_menu champion4" href="' + transformNutakuURL('/champions/4') + '">Ryu</a>';
            let championsMenu_Visor = '<a class="champions_menu champion5" href="' + transformNutakuURL('/champions/5') + '">Visor</a>';
            let championsMenu_Alban = '<a class="champions_menu champion6" href="' + transformNutakuURL('/champions/6') + '">Alban</a>';

            if (window.Hero.infos.questing.id_world > 3 || (window.Hero.infos.questing.id_world == 3 && window.Hero.infos.questing.id_quest > 5)) {
                $('a[rel="sex-god-path"]').append(championsMenu_Romero);
                $('a[rel="sex-god-path"]').append(championsMenu_Whaty);
                $('a[rel="sex-god-path"]').append(championsMenu_Matsuda);
                $('a[rel="sex-god-path"]').append(championsMenu_Ryu);
                $('a[rel="sex-god-path"]').append(championsMenu_Visor);
                $('a[rel="sex-god-path"]').append(championsMenu_Alban);
            }
        }

        if (window.Hero.energies.worship != undefined) {
            let championsMenu_pantheon = '<a class="champions_menu pantheon" href="' + transformNutakuURL('/pantheon.html') + '">' + window.GT.design.pantheon + '</a>';
            if (window.Hero.infos.level >= 15) {
                $('a[rel="sex-god-path"]').append(championsMenu_pantheon);
            }
        }

        if (window.HH_UNIVERSE != 'horny_s' && window.HH_UNIVERSE != "dotcom_startrans" && window.HH_UNIVERSE != 'nutaku_startrans' && window.HH_UNIVERSE != "dotcom_stargay" && window.HH_UNIVERSE != 'nutaku_stargay') {
            let championsMenu_labyrinth = '<a class="champions_menu labyrinth" href="' + transformNutakuURL('/labyrinth-entrance.html') + '">' + window.GT.design.labyrinth + '</a>';
            $('a[rel="sex-god-path"]').append(championsMenu_labyrinth);
        }

        //Club champion shortcut
        let clubChampion = '<a class="clubChampion" href="' + transformNutakuURL('/club-champion.html') + '">' + labels.Club_champion + '</a>';
        $('a[rel="clubs"]').append(clubChampion);

        //Add sub-menus for Activities
        let dailyGoalsMenu = '<a class="daily_goals_menu" href="' + transformNutakuURL('/activities.html?tab=daily_goals') + '">' + window.GT.design.daily_goals + '</a>';
        let missionsMenu = '<a class="missions_menu" href="' + transformNutakuURL('/activities.html?tab=missions') + '">' + window.GT.design.missions + '</a>';
        let contestsMenu = '<a class="contests_menu" href="' + transformNutakuURL('/activities.html?tab=contests') + '">' + window.GT.design.contests + '</a>';
        let popMenu = '<a class="pop_menu" href="' + transformNutakuURL('/activities.html?tab=pop') + '">' + labels.pop + '</a>';
        if (window.HH_UNIVERSE != 'horny_s') {
            $('a[rel="activities"]').append(dailyGoalsMenu);
        }
        $('a[rel="activities"]').append(missionsMenu);
        $('a[rel="activities"]').append(contestsMenu);
        if (window.HH_UNIVERSE != 'horny_s') {
            $('a[rel="activities"]').append(popMenu);
        }

        //Add sub-menus for Market
        let marketMenu_equipments = '<a class="market_menu equipments" href="' + transformNutakuURL('/shop.html?type=armor') + '">' + labels.Equipments + '</a>';
        let marketMenu_boosters = '<a class="market_menu boosters" href="' + transformNutakuURL('/shop?type=booster') + '">' + labels.Boosters + '</a>';
        let marketMenu_books = '<a class="market_menu books" href="' + transformNutakuURL('/shop?type=potion') + '">' + labels.Books + '</a>';
        let marketMenu_gifts = '<a class="market_menu gifts" href="' + transformNutakuURL('/shop?type=gift') + '">' + labels.Gifts + '</a>';
        $('a[rel="shop"]').append(marketMenu_equipments);
        $('a[rel="shop"]').append(marketMenu_boosters);
        $('a[rel="shop"]').append(marketMenu_books);
        $('a[rel="shop"]').append(marketMenu_gifts);

        //Quests shortcuts
        let currentQuest = '<a class="current_quest" href="' + transformNutakuURL(window.Hero.infos.questing.current_url) + '">' + window.GT.design.current_quest + '</a>';
        let sideQuests = '<a class="side_quests" href="' + transformNutakuURL('/side-quests.html') + '">' + labels.Side_quests + '</a>';
        $('a[rel="map"]').append(currentQuest);
        if (window.Hero.infos.questing.id_world > 1) {
            $('a[rel="map"]').append(sideQuests);
        }
        $('.continue-quest-container').remove();

        //Phone messages
        if ($('a.messenger-link').length > 0) {
            if (window.Hero.energies.reply.amount < window.Hero.energies.reply.max_regen_amount) {
                let phone_messages_end_date = window.server_now_ts + window.Hero.energies.reply.recharge_time;
                $('a.messenger-link').append('<span class=script_phone_messages>' + window.Hero.energies.reply.amount + ' / ' + window.Hero.energies.reply.max_regen_amount + '<BR>'
                                             + '+1 ' + labels.in + ' ' + convertToTimeFormatMinutes(window.Hero.energies.reply.next_refresh_ts) + '</span>');
            }
            else {
                $('a.messenger-link').append('<span class=script_phone_messages>' + window.Hero.energies.reply.amount + ' / ' + window.Hero.energies.reply.max_regen_amount + '<BR>'
                                             + labels.full + '</span>');
            }
        }


        setInterval(function(){$('#scriptPachinkoTimer').text(calculateTime(pachinkoTime));
                               $('#scriptChampionsTimer').text(calculateTime(championsTime));
                               $('#scriptPovTime').text(calculateTime(povTime*1000));
                               $('#scriptPogTime').text(calculateTime(pogTime*1000));
                               $('#scriptSeasonTime').text(calculateTime(seasonTime*1000));
                               if (window.missions_datas.reward == false && window.missions_datas.remaining_time == null) {
                                   $('#missionsTimer1').text(calculateTime(next_missions_remaining_date));
                                   $('#missionsTimer2').text(calculateTime(next_missions_remaining_date));
                               }
                              }, 1000);
    }

    function pachinko() {
        let pachinkoTimeMin = Math.min(window.pachinkoVar.next_equipment_game, window.pachinkoVar.next_great_game, window.pachinkoVar.next_mythic_game);
        let pachinkoTime = window.server_now_ts*1000 + pachinkoTimeMin*1000;
        localStorage.setItem("HHS.pachinkoTime", pachinkoTime);

        if ($('#playzone-replace-info > div.btns-section > button.blue_button_L:nth-child(1)').length && ($('.playing-zone')[0].attributes[1].value == "great" || $('.playing-zone')[0].attributes[1].value == "equipment" || $('.playing-zone')[0].attributes[1].value == "mythic")) {
            let button = document.querySelector('#playzone-replace-info > div.btns-section > button.blue_button_L:nth-child(1)');
            button.addEventListener('click', () => {
                if (button.attributes["data-free"].value == "true") {
                    setTimeout(() => {
                        pachinkoTimeMin = Math.min(window.pachinkoVar.next_equipment_game, window.pachinkoVar.next_great_game, window.pachinkoVar.next_mythic_game);
                        pachinkoTime = window.server_now_ts*1000 + pachinkoTimeMin*1000;
                        localStorage.setItem("HHS.pachinkoTime", pachinkoTime);
                    }, 4*timeout)
                }
            });
        }

        let observer = new MutationObserver(function(mutations) {
            mutations.forEach(function() {
                if ($('.playing-zone')[0].attributes[1].value != "great" && $('.playing-zone')[0].attributes[1].value != "equipment" && $('.playing-zone')[0].attributes[1].value != "mythic") {
                    return;
                }
                if ($('#playzone-replace-info > div.btns-section > button.blue_button_L:nth-child(1)').length) {
                    let button = document.querySelector('#playzone-replace-info > div.btns-section > button.blue_button_L:nth-child(1)');
                    button.addEventListener('click', () => {
                        if (button.attributes["data-free"].value == "true") {
                            setTimeout(() => {
                                pachinkoTimeMin = Math.min(window.pachinkoVar.next_equipment_game, window.pachinkoVar.next_great_game, window.pachinkoVar.next_mythic_game);
                                pachinkoTime = window.server_now_ts*1000 + pachinkoTimeMin*1000;
                                localStorage.setItem("HHS.pachinkoTime", pachinkoTime);
                            }, 4*timeout)
                        }
                    });
                }
            })
        })
        observer.observe($('.playing-zone')[0], {childList: false, subtree: false, attributes: true})
    }

    function activities() {
        let next_missions_remaining_time = $('#missions .new-missions-timer.timer').attr('data-time-stamp');
        localStorage.setItem("HHS.nextMissionsDate", (time_now + parseInt(next_missions_remaining_time, 10))*1000);
    }

    function champions(){
        if (CurrentPage == "/champions-map.html") {
            let time_min_champions = time_now + 15*60 + 1;
            for (let i = 0; i < 6; i++){
                let time_champion = (time_now + parseInt($('a.champion-lair[href$="champions/' + (i+1) + '"] > div.champion-lair-name.map-label-link > div').attr('data-time'), 10)) || time_min_champions;
                time_min_champions = Math.min(time_min_champions, parseInt(time_champion, 10));
            }
            if (time_min_champions == time_now + 15*60 + 1) {
                localStorage.setItem("HHS.championsTime", time_now*1000);
            }
            else {
                localStorage.setItem("HHS.championsTime", time_min_champions*1000);
            }
        }
        else {
            let current_timer = parseInt($('.champions-bottom__rest .rest-timer.timer').attr('data-time-stamp'), 10);
            let current_min = parseInt(localStorage.getItem("HHS.championsTime"), 10);

            if (current_min < time_now*1000) {
                current_min = (time_now + 15*60 + 1)*1000;
            }
            if ((current_timer*1000) < current_min) {
                localStorage.setItem("HHS.championsTime", (time_now + current_timer)*1000);
            }

            if ($('button.champions-bottom__start-battle').length > 0) {
                let button = document.querySelector('.champions-bottom__wrapper .champions-bottom__footer .champions-bottom__buttons-wrapper button.champions-bottom__start-battle');
                button.addEventListener('click', function(){
                    let champion_timer = new Date().getTime() + (15*60)*1000;
                    let champion_min = parseInt(localStorage.getItem("HHS.championsTime"), 10);
                    if (champion_timer < champion_min || champion_min < new Date().getTime()) {
                        localStorage.setItem("HHS.championsTime", champion_timer);
                    }
                });
            }
        }
    }

    function pov() {
        let povTimer = parseInt($('.pov-timer.timer').attr('data-time-stamp'), 10) || parseInt($('.potions-paths-timer.timer').attr('data-time-stamp'), 10);
        let pov_end_time = time_now + povTimer;
        localStorage.setItem("HHS.PovTime", pov_end_time);
    }

    function pog() {
        let pogTimer = parseInt($('.potions-paths-timer.timer').attr('data-time-stamp'), 10);
        let pog_end_time = time_now + pogTimer;
        localStorage.setItem("HHS.PogTime", pog_end_time);
    }

    function season() {
        let seasonTimer = window.season_sec_untill_event_end;
        let season_end_time = time_now + seasonTimer;
        localStorage.setItem("HHS.SeasonTime", season_end_time);
    }

    function addBoosterStatus() {
        const CIRCULAR_THRESHOLDS = {
            1: 'green',
            0.5: 'yellow',
            0.2: 'red'
        };

        this.activeBoosters = {};

        const boosterStatus = JSON.parse(localStorage.getItem('HHS.booster_status')) || DEFAULT_BOOSTERS;

        boosterStatus.normal = boosterStatus.normal.filter(({endAt}) => endAt > window.server_now_ts)

        Object.keys(boosterStatus).forEach(key => {
            if (boosterStatus[key].length < MAX_BOOSTERS[key]) {
                // fill the rest with empty
                boosterStatus[key] = [...boosterStatus[key], ...Array(MAX_BOOSTERS[key]-boosterStatus[key].length).fill({empty:true})]
            }
        })

        $('.script-booster-status').remove();

        const $boosterStatusHTML = $('<a class="script-booster-status" href="' + transformNutakuURL('/shop.html?type=player-stats&subtab=booster') + '"></a>')

        const buildNormalSlot = (data) => {
            const {empty, id_item, ico, identifier, rarity, endAt} = {...data, ...data.item}
            if (empty) {
                return '<div class="slot empty"></div>'
            }
            data.expiry = endAt - (Math.floor(new Date().getTime()/1000));
            data.expiration = endAt - (Math.floor(new Date().getTime()/1000));
            const formattedDate = new Date(endAt * 1000).toLocaleTimeString(undefined, options).replace(/(\d)/g, (x)=>`${x}<i></i>`)
            return $(`
                <div class="slot ${rarity}" booster-item-tooltip="" id_item="${id_item}" data-d="${JSON.stringify(data).replace(/"/g, '&quot;')}" additional-tooltip-info="${JSON.stringify({additionalText: `<span class="script-tooltip"></span>${labels.ends_at + ' ' + formattedDate}`}).replace(/"/g, '&quot;')}">
                    <img src="${ico || `${window.IMAGES_URL}/pictures/items/${identifier}.png`}"/>
                </div>`)
        }

        const buildMythicSlot = (data) => {
            const {empty, id_item, ico, identifier} = {...data, ...data.item}
            if (empty) {
                return '<div class="slot mythic empty"></div>'
            }
            return $(`
                <div class="slot mythic" booster-item-tooltip="" id_item="${id_item}" data-d="${JSON.stringify(data).replace(/"/g, '&quot;')}" additional-tooltip-info="${JSON.stringify({additionalText: '<span class="script-tooltip"></span>'}).replace(/"/g, '&quot;')}">
                    <img src="${ico || `${window.IMAGES_URL}/pictures/items/${identifier}.png`}"/>
                </div>
            `)
        }

        const buildProgressWrapper = (current, max, useTimer) => {
            const percentage = Math.min(current/max, 1)
            const firstHalf = Math.min(percentage, 0.5) * 2
            const secondHalf = Math.max(percentage - 0.5, 0) * 2

            let colorClass = ''
            let flashingClass = ''

            if (percentage > 0) {
                Object.entries(CIRCULAR_THRESHOLDS).forEach(([threshold, className]) => {
                    if (percentage <= threshold) {
                        colorClass = className
                    }
                })

                if (percentage <= 0.0035) {
                    flashingClass = 'flashing'
                }
            }

            const $wrapper = $(`
                <div class="circular-progress">
                    <div class="circle">
                        <div class="circle-bar left ${flashingClass}">
                            <div class="progress ${colorClass}" style="transform: rotate(${180 * secondHalf}deg)"></div>
                        </div>
                        <div class="circle-bar right ${flashingClass}">
                            <div class="progress ${colorClass}" style="transform: rotate(${180 * firstHalf}deg)"></div>
                        </div>
                        ${useTimer ? '<div class="dummy-timer-target" style="display: none;"></div>' : ''}
                    </div>
                </div>
            `)
            return $wrapper
        }

        const buildSlotAndAddTooltip = (buildSlot, data, replaceEmpty) => {
            const {empty, id_member_booster_equipped, usages_remaining, endAt, item} = data
            const {rarity, default_usages, duration} = item || {}
            const $slot = buildSlot(data)
            let current = 0
            let max = 1
            let useTimer = false
            const isMythic = rarity == 'mythic'

            if (!empty) {
                if (isMythic) {
                    current = usages_remaining
                    max = default_usages
                } else {
                    let normalisedDuration = duration == 1440 ? 86400 : duration
                    current = endAt - window.server_now_ts
                    max = normalisedDuration
                    useTimer = true
                }
            }

            const $progressWrapper = buildProgressWrapper(current, max, useTimer)
            $progressWrapper.prepend($slot)

            if (replaceEmpty) {
                $boosterStatusHTML.find(`.circular-progress:has(.empty${isMythic? '.mythic':':not(.mythic)'})`).first().replaceWith($progressWrapper)
            } else {
                $boosterStatusHTML.append($progressWrapper)
            }

            if (!empty && isMythic) {
                const id_m_i = id_member_booster_equipped
                this.activeBoosters[id_m_i] = $progressWrapper
            }
        }

        boosterStatus.normal.forEach(data => {
            buildSlotAndAddTooltip(buildNormalSlot, data)
        })

        boosterStatus.mythic.forEach(data => {
            buildSlotAndAddTooltip(buildMythicSlot, data)
        })

        $('header .currency').before($boosterStatusHTML)

        $(document).on('boosters:equipped', (event, {id_item, isMythic, new_id}) => {
            const boosterStatus = JSON.parse(localStorage.getItem('HHS.booster_status')) || DEFAULT_BOOSTERS

            const newBoosterData = boosterStatus[isMythic ? 'mythic' : 'normal'].find(data=>data.id_item == id_item&&(new_id && data.id_member_booster_equipped == new_id))

            if (newBoosterData) {
                const $slotToReplace = $boosterStatusHTML.find(`.slot.empty${isMythic ? '.mythic' : ':not(.mythic)'}`)
                if ($slotToReplace.length) {
                    buildSlotAndAddTooltip(isMythic ? buildMythicSlot : buildNormalSlot, newBoosterData, true)
                } else {
                    // wat
                    console.log('somehow equipped a new equip but have no empty slot????')
                }
            } else {
                console.log('can\'t find data in LS for new booster with id', new_id, 'and itemid', id_item)
            }
        })

        $(document).on('boosters:updated-mythic', () => {
            const boosterStatus = JSON.parse(localStorage.getItem('HHS.booster_status')) || {normal: [], mythic: []}

            const boostersByIdmi = {}
            boosterStatus.mythic.forEach(function(data) {
                boostersByIdmi[data.id_member_booster_equipped] = data
            })

            Object.entries(this.activeBoosters).forEach(([id_m_i, $elem]) => {
                const updatedData = boostersByIdmi[id_m_i]

                if (!updatedData) {
                    // Booster has expired
                    $elem.find('.slot').attr('class', 'slot mythic empty').empty().attr('data-d', '').attr('tooltip-id', '').attr('id_item', '')
                    $elem.find('.progress').css('transform', 'rotate(0deg)')
                } else {
                    const {item: {default_usages}, usages_remaining} = updatedData
                    const percentage = Math.min(usages_remaining/default_usages, 1)
                    const firstHalf = Math.min(percentage, 0.5) * 2
                    const secondHalf = Math.max(percentage - 0.5, 0) * 2
                    let colorClass = 'green'

                    if (percentage > 0) {
                        Object.entries(CIRCULAR_THRESHOLDS).forEach(([threshold, className]) => {
                            if (percentage <= threshold) {
                                colorClass = className
                            }
                        })
                    }

                    const $left = $elem.find('.left .progress')
                    const $right = $elem.find('.right .progress')
                    $left.css('transform', `rotate(${180 * secondHalf}deg)`).attr('class', `progress ${colorClass}`)
                    $right.css('transform', `rotate(${180 * firstHalf}deg)`).attr('class', `progress ${colorClass}`)
                    const $slot = $elem.find('.slot')
                    $slot.attr('data-d', JSON.stringify(updatedData))
                    $slot.data('d', updatedData)
                }
            })
        })

        new MutationObserver(() => {
            // Nasty hack. Wish there was a better way of setting a custom class on a tooltip
            $('.hh_tooltip_new:has(.script-tooltip)').addClass('script-booster-status-item')
        }).observe(document.body, {childList: true})

        //CSS
        sheet.insertRule('.script-booster-status {'
                         + 'z-index:15;'
                         + 'display: grid;'
                         + 'grid-gap: 3px;'
                         + 'grid-template-columns: repeat(9, 1fr);}'
                        );

        sheet.insertRule(`${mediaDesktop} {`
                         + '.script-booster-status {'
                         + 'position: fixed;'
                         + 'top: 37px;'
                         + 'left: 10px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '.script-booster-status {'
                         + 'position: fixed;'
                         + 'top: 57px;'
                         + 'left: 20px;}}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress {'
                         + 'position: relative;'
                         + 'height: 24px;'
                         + 'width: 24px;}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .green {'
                         + 'background-color: #01d10b;}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .yellow {'
                         + 'background-color: #ffc400;}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .red {'
                         + 'background-color: #ff0000;}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .slot {'
                         + 'position: absolute;'
                         + 'height: 20px;'
                         + 'width: 20px;'
                         + 'top: 2px;'
                         + 'left: 2px;'
                         + 'z-index: 6;}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .slot.empty {'
                         + 'cursor: inherit !important;}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .empty + .circle {'
                         + 'box-shadow: none;}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .empty + .circle .circle-bar {'
                         + 'background-color: transparent;}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .circle {'
                         + 'height: 100%;'
                         + 'width: 100%;'
                         + 'box-shadow: 0px 0px 5px #000, 0px 0px 4px #000, 0px 0px 3px #000, 0px 0px 2px #000;}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .circle-bar {'
                         + 'position: absolute;'
                         + 'height: 100%;'
                         + 'width: 100%;'
                         + 'background-color: #000000bf;'
                         + 'clip-path: polygon(0% 0%, 0% 100%, 50% 100%, 50% 0%);'
                         + 'overflow: hidden;}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .circle-bar.flashing {'
                         + 'animation-name: flashing-background;'
                         + 'animation-duration: 3s;'
                         + 'animation-iteration-count: infinite;}'
                        );

        sheet.insertRule('@keyframes flashing-background {'
                         + '0% {background-color: #000000bf;}'
                         + '50% {background-color: #ff0000;}'
                         + '100% {background-color: #000000bf;}}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .circle-bar .progress {'
                         + 'position: absolute;'
                         + 'height: 200%;'
                         + 'width: 200%;'
                         + 'top: -50%;'
                         + 'left: -50%;'
                         + 'clip-path: polygon(50% -50%, 150% -50%, 150% 150%, 50% 150%);}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .circle-bar.right {'
                         + 'transform: rotate(180deg);'
                         + 'z-index: 3;}'
                        );

        sheet.insertRule('.script-booster-status .circular-progress .circle-bar.left .progress {'
                         + 'z-index: 1;}'
                        );

        sheet.insertRule('.script-booster-status-item .season_rewards_tier_info, .script-booster-status-item .item-price {'
                         + 'display: none;}'
                        );

        sheet.insertRule('.script-booster-status {'
                         + 'grid-template-columns: 1fr 1fr 1fr;}'
                        );

        sheet.insertRule('.script-booster-status > .circular-progress > .slot {'
                         + 'border-width: 0px !important;}'
                        );
    }

    function collectBoostersFromMarket() {
        setTimeout(function() {
            const activeSlots = $('#equiped .booster .slot:not(.empty):not(.mythic)').map((i, el)=> $(el).data('d')).toArray()
            const activeMythicSlots = $('#equiped .booster .slot:not(.empty).mythic').map((i, el)=> $(el).data('d')).toArray()

            const boosterStatus = {
                normal: activeSlots.map((data) => ({...data, endAt: window.server_now_ts + data.expiration})),
                mythic: activeMythicSlots,
            }

            localStorage.setItem('HHS.booster_status', JSON.stringify(boosterStatus));
        }, timeout)
    }

    function getClubStatus() {
        if (window.location.pathname.includes('clubs') && window.membersList) {
            const {upgradesInformation: {upgrades}, membersList} = window;
            const clubStatus = {
                upgrades,
                memberIds: membersList.map(({id_member}) => id_member)
            };

            localStorage.setItem('HHS.club_status', JSON.stringify(clubStatus));
        }
    }

    function getClubXPBonus() {
        const clubStatus = JSON.parse(localStorage.getItem('HHS.club_status'));

        if (clubStatus) {
            return clubStatus.upgrades.experience_gain.bonus;
        } else if (window.Chat_vars && window.Chat_vars.CLUB_ID) {
            return 0.1;
        } else {
            return 0;
        }
    }

    function collectBoostersFromHeroUpdate() {
        const originalHeroUpdate = window.Hero.update.bind(window.Hero)
        const hookedUpdate = (field, value, add) => {
            if (field == 'xp') {
                const boosterStatus = JSON.parse(localStorage.getItem('HHS.booster_status')) || DEFAULT_BOOSTERS

                const travelMemories = boosterStatus.mythic.find(({item: {identifier}}) => identifier == 'MB6')

                if (travelMemories) {
                    const {cur: oldValue, level} = window.Hero.infos.Xp

                    let atmBonus = 0.05
                    if (level < 300) {
                        atmBonus = 0.2
                    }
                    const clubBonus = getClubXPBonus()

                    const diff = value - oldValue
                    const extra = Math.ceil(Math.floor(diff/(1+clubBonus+atmBonus))*atmBonus)

                    travelMemories.usages_remaining -= extra

                    boosterStatus.mythic = boosterStatus.mythic.filter(({usages_remaining}) => usages_remaining > 0)
                    localStorage.setItem('HHS.booster_status', JSON.stringify(boosterStatus));
                    $(document).trigger('boosters:updated-mythic')
                }
            }

            return originalHeroUpdate(field, value, add)
        }
        window.Hero.update = hookedUpdate
    }

    function collectBoostersFromAjaxResponses () {
        $(document).ajaxComplete(function(evt, xhr, opt) {
            if(opt && opt.data && opt.data.search && ~opt.data.search(/(action|class)/)) {
                setTimeout(function() {
                    if(!xhr || !xhr.responseText || !xhr.responseText.length) {
                        return
                    }
                    const boosterStatus = JSON.parse(localStorage.getItem('HHS.booster_status')) || DEFAULT_BOOSTERS

                    const response = JSON.parse(xhr.responseText);

                    if(!response || !response.success) return;

                    const searchParams = new URLSearchParams(opt.data)
                    const mappedParams = ['action', 'class', 'type', 'id_item', 'number_of_battles', 'battles_amount'].map(key => ({[key]: searchParams.get(key)})).reduce((a,b)=>Object.assign(a,b),{})
                    const {action, class: className, type, id_item, number_of_battles, battles_amount} = mappedParams
                    const {success, equipped_booster} = response

                    if (!success) {
                        return
                    }

                    if (action == 'market_equip_booster' && type == 'booster') {
                        const idItemParsed = parseInt(id_item)
                        //const isMythic = idItemParsed >= 632 && idItemParsed <= 638
                        const isMythic = idItemParsed >= 632

                        const boosterData = equipped_booster

                        if (boosterData) {
                            const clonedData = {...boosterData}

                            if (isMythic) {
                                boosterStatus.mythic.push(clonedData)
                            } else {
                                boosterStatus.normal.push({...clonedData, endAt: clonedData.lifetime})
                            }

                            localStorage.setItem('HHS.booster_status', JSON.stringify(boosterStatus));
                            $(document).trigger('boosters:equipped', {id_item, isMythic, new_id: clonedData.id_member_booster_equipped})
                        }
                        return
                    }

                    let mythicUpdated = false

                    let sandalwood, allMastery, leagueMastery, seasonMastery, headband, watch, cinnamon, perfume;
                    boosterStatus.mythic.forEach((booster) => {
                        if (booster.item != undefined || booster.item != null) {
                            switch (booster.item.identifier) {
                                case 'MB1':
                                    sandalwood = booster;
                                    break;
                                case 'MB2':
                                    allMastery = booster;
                                    break;
                                case 'MB3':
                                    headband = booster;
                                    break;
                                case 'MB4':
                                    watch = booster;
                                    break;
                                case 'MB5':
                                    cinnamon = booster;
                                    break;
                                case 'MB7':
                                    perfume = booster;
                                    break;
                                case 'MB8':
                                    leagueMastery = booster;
                                    break;
                                case 'MB9':
                                    seasonMastery = booster;
                                    break;
                            }
                        }
                    })

                    if (sandalwood && action == 'do_battles_trolls') {
                        const isMultibattle = parseInt(number_of_battles) > 1
                        const {rewards} = response
                        if (rewards && rewards.data && rewards.data.shards) {
                            let drops = 0
                            rewards.data.shards.forEach(({previous_value, value}) => {
                                if (isMultibattle) {
                                    // Can't reliably determine how many drops, assume MD where each drop would be 1 shard.
                                    const shardsDropped = value - previous_value
                                    drops += Math.floor(shardsDropped/2)
                                } else {
                                    drops++
                                }
                            })
                            sandalwood.usages_remaining -= drops
                            mythicUpdated = true
                        }
                    }

                    if (allMastery && (action == 'do_battles_leagues' || action == 'do_battles_seasons')) {
                        allMastery.usages_remaining -= parseInt(number_of_battles)
                        mythicUpdated = true
                    }

                    if (leagueMastery && (action == 'do_battles_leagues')) {
                        leagueMastery.usages_remaining -= parseInt(number_of_battles)
                        mythicUpdated = true
                    }

                    if (seasonMastery && (action == 'do_battles_seasons')) {
                        seasonMastery.usages_remaining -= parseInt(number_of_battles)
                        mythicUpdated = true
                    }

                    if (headband && (action == 'do_battles_pantheon' || action == 'do_battles_trolls')) {
                        headband.usages_remaining -= parseInt(number_of_battles)
                        mythicUpdated = true
                    }

                    if (watch && className == 'TeamBattle') {
                        watch.usages_remaining -= parseInt(battles_amount)
                        mythicUpdated = true
                    }

                    if (cinnamon && action == 'do_battles_seasons') {
                        cinnamon.usages_remaining -= parseInt(number_of_battles)
                        mythicUpdated = true
                    }

                    if (perfume && action == 'start' && className == 'TempPlaceOfPower') {
                        perfume.usages_remaining--
                        mythicUpdated = true
                    }

                    boosterStatus.mythic = boosterStatus.mythic.filter(({usages_remaining}) => usages_remaining > 0)

                    localStorage.setItem('HHS.booster_status', JSON.stringify(boosterStatus));

                    if (mythicUpdated) {
                        $(document).trigger('boosters:updated-mythic')
                    }
                }, timeout);
            }
        })
    }

    //CSS
    sheet.insertRule('a.messenger-link > .script_phone_messages {'
                     + 'color: rgb(255, 255, 255);'
                     + 'position: absolute;'
                     + 'width: 100px;'
                     + 'right: -18px;'
                     + 'top: 14px;'
                     + 'font-size: 14px;'
                     + 'text-align: center;'
                     + 'text-shadow: rgb(0, 0, 0) 1px 1px 0px, rgb(0, 0, 0) -1px 1px 0px, rgb(0, 0, 0) -1px -1px 0px, rgb(0, 0, 0) 1px -1px 0px;}'
                    );

    sheet.insertRule('.champions_menu, .clubChampion {'
                     + 'position: absolute;'
                     + 'z-index: 35;'
                     + 'display: flex;'
                     + 'flex-direction: column;'
                     + 'width: 100px;'
                     + 'border-radius: 3px;'
                     + 'background-color: rgba(32, 3, 7, 0.75);'
                     + 'box-shadow: 0 0 0 1px #ffb827;'
                     + 'opacity: 0;'
                     + 'visibility: hidden;'
                     + 'font-size: 14px;'
                     + 'font-weight: 400;'
                     + 'letter-spacing: .22px;'
                     + 'color: #ffb827;'
                     + 'font-family: \'Carter One\', \'Alegreya Sans\', cursive !important;'
                     + 'text-decoration: none;'
                     + 'justify-content: center;'
                     + 'transition: opacity 200ms, visibility 200ms;'
                     + 'text-align: center;}'
                    );

    sheet.insertRule('#hh_gay .champions_menu, #hh_gay .clubChampion {'
                     + 'box-shadow: 0 0 0 1px #69e5ff !important;'
                     + 'color: #69e5ff !important;}'
                    );

    sheet.insertRule('#hh_star .champions_menu, #hh_star .clubChampion {'
                     + 'box-shadow: 0 0 0 1px #ff9174 !important;'
                     + 'color: #ff9174 !important;}'
                    );

    sheet.insertRule('#hh_comix .champions_menu, #hh_comix .clubChampion {'
                     + 'font-family: Montserrat !important;'
                     + 'font-weight: 700 !important;'
                     + 'box-shadow: 0 0 0 1px #ffca47 !important;'
                     + 'color: #ffca47 !important;}'
                    );
    
    let championsHeightDesktop = (parseInt($('.sex-god-path-btn').css('height'), 10) - 2);

    sheet.insertRule('.champions_map, .pantheon, .labyrinth {'
                     + 'height: ' + championsHeightDesktop + 'px;'
                     + 'top: 1px;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] a:hover, a[rel="clubs"] a:hover {'
                     + 'text-decoration: underline !important;}'
                    );

    sheet.insertRule('a[rel="clubs"] > .clubChampion {'
                     + 'width: 130px !important;'
                     + 'height: 52px;'
                     + 'top: 1px;'
                     + 'margin-left: 130px;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] > .champions_map, .champion1, .champion4 {'
                     + 'margin-left: 130px;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] > .pantheon, .champion2, .champion5 {'
                     + 'margin-left: 230px;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] > .labyrinth, .champion3, .champion6 {'
                     + 'margin-left: 330px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.champion1, .champion2, .champion3, .champion4, .champion5, .champion6 {'
                     + 'z-index: 10 !important;'
                     + 'height: 26px;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.champion1, .champion2, .champion3, .champion4, .champion5, .champion6 {'
                     + 'z-index: 10 !important;'
                     + 'height: 52px;}'
                    );

    let subChampionsMenuTopDesktop1 = parseInt($('.sex-god-path-btn').css('height'), 10) + 24;
    let subChampionsMenuTopDesktop2 = subChampionsMenuTopDesktop1 + 26;
    let subChampionsMenuTopMobile1 = parseInt($('.sex-god-path-btn').css('height'), 10) + 52;
    let subChampionsMenuTopMobile2 = subChampionsMenuTopMobile1 + 52;


    sheet.insertRule(`${mediaDesktop} {`
                     + '.champion1, .champion2, .champion3 {'
                     + 'margin-top: -' + subChampionsMenuTopDesktop2 + 'px;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.champion1, .champion2, .champion3 {'
                     + 'margin-top: -' + subChampionsMenuTopMobile2 + 'px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.champion4, .champion5, .champion6 {'
                     + 'margin-top: -' + subChampionsMenuTopDesktop1 + 'px;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.champion4, .champion5, .champion6 {'
                     + 'margin-top: -' + subChampionsMenuTopMobile1 + 'px;}'
                    );

    sheet.insertRule('a[rel="clubs"]:hover > .clubChampion, a[rel="sex-god-path"]:hover > .champions_map, a[rel="sex-god-path"]:hover > .pantheon, a[rel="sex-god-path"]:hover > .labyrinth {'
                     + 'opacity: 1;'
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"]:hover > .champion1, a[rel="sex-god-path"]:hover > .champion2, a[rel="sex-god-path"]:hover > .champion3, a[rel="sex-god-path"]:hover > .champion4, a[rel="sex-god-path"]:hover > .champion5, a[rel="sex-god-path"]:hover > .champion6 {'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('.market_menu, .current_quest, .side_quests {'
                     + 'position: absolute;'
                     + 'z-index: 35;'
                     + 'display: flex;'
                     + 'flex-direction: column;'
                     + 'top: 1px;'
                     + 'text-decoration: none;'
                     + 'border-radius: 3px;'
                     + 'background-color: rgba(32, 3, 7, 0.75);'
                     + 'box-shadow: 0 0 0 1px #ffb827;'
                     + 'opacity: 0;'
                     + 'visibility: hidden;'
                     + 'font-size: 14px;'
                     + 'font-weight: 400;'
                     + 'letter-spacing: .22px;'
                     + 'color: #ffb827;'
                     + 'font-family: \'Carter One\', \'Alegreya Sans\', cursive !important;'
                     + 'justify-content: center;'
                     + 'transition: opacity 200ms, visibility 200ms;'
                     + 'text-align: center;}'
                    );

    sheet.insertRule('#hh_gay .market_menu, #hh_gay .current_quest, #hh_gay .side_quests {'
                     + 'box-shadow: 0 0 0 1px #69e5ff !important;'
                     + 'color: #69e5ff !important;}'
                    );

    sheet.insertRule('#hh_star .market_menu, #hh_star .current_quest, #hh_star .side_quests {'
                     + 'box-shadow: 0 0 0 1px #ff9174 !important;'
                     + 'color: #ff9174 !important;}'
                    );

    sheet.insertRule('#hh_comix .market_menu, #hh_comix .current_quest, #hh_comix .side_quests {'
                     + 'font-family: Montserrat !important;'
                     + 'font-weight: 700 !important;'
                     + 'box-shadow: 0 0 0 1px #ffca47 !important;'
                     + 'color: #ffca47 !important;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.market_menu, .current_quest, .side_quests {'
                     + 'width: 130px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.equipments {'
                     + 'width: 130px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.boosters {'
                     + 'width: 120px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.books, .gifts {'
                     + 'width: 90px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.current_quest, .side_quests {'
                     + 'width: 130px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.market_menu, .current_quest, .side_quests {'
                     + 'height: 26px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.market_menu, .current_quest, .side_quests {'
                     + 'height: 52px;}}'
                    );

    sheet.insertRule('a[rel="shop"] a:hover {'
                     + 'text-decoration: underline;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="shop"] > .equipments {'
                     + 'margin-left: 130px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="shop"] > .boosters {'
                     + 'margin-left: 260.5px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="shop"] > .books {'
                     + 'margin-top: 26px;'
                     + 'margin-left: 130px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="shop"] > .gifts {'
                     + 'margin-top: 26px;'
                     + 'margin-left: 260.5px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="shop"] > .equipments {'
                     + 'margin-left: 130px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="shop"] > .boosters {'
                     + 'margin-left: 260px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="shop"] > .books {'
                     + 'margin-left: 380px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="shop"] > .gifts {'
                     + 'margin-left: 470px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="shop"]:hover > .equipments {'
                     + 'margin-left: 130px;'
                     + 'opacity: 1; '
                     + 'visibility: visible;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="shop"]:hover > .boosters {'
                     + 'margin-left: 260px;'
                     + 'opacity: 1; '
                     + 'visibility: visible;}}'
                    );

    sheet.insertRule('a[rel="shop"]:hover > .equipments, a[rel="shop"]:hover > .boosters, a[rel="shop"]:hover > .books, a[rel="shop"]:hover > .gifts {'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="shop"]:hover > .books {'
                     + 'margin-top: 26px;'
                     + 'margin-left: 130px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="shop"]:hover > .gifts {'
                     + 'margin-top: 26px;'
                     + 'margin-left: 260px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="shop"]:hover > .equipments {'
                     + 'margin-left: 130px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="shop"]:hover > .boosters {'
                     + 'margin-left: 260px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="shop"]:hover > .books {'
                     + 'margin-left: 381px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="shop"]:hover > .gifts {'
                     + 'margin-left: 472px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="map"] > .notif-position > span {'
                     + 'height: 28px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="map"] .button-notification-icon {'
                     + 'top: 1px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="map"] > .new_notif {'
                     + 'top: 0px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="harem"] > .notif-position > span {'
                     + 'height: 28px !important;}}'
                    );

    sheet.insertRule('a[rel="map"] a:hover {'
                     + 'text-decoration: underline;}'
                    );

    sheet.insertRule('a[rel="map"] > .current_quest {'
                     + 'width: 150px !important;'
                     + 'margin-left: 130px;}'
                    );

    sheet.insertRule('a[rel="map"] > .side_quests {'
                     + 'width: 150px !important;'
                     + 'margin-left: 280px;}'
                    );

    sheet.insertRule('a[rel="map"]:hover > .current_quest {'
                     + 'width: 150px !important;'
                     + 'margin-left: 130px;'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('a[rel="map"]:hover > .side_quests {'
                     + 'width: 150px !important;'
                     + 'margin-left: 280px;'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('.daily_goals_menu, .missions_menu, .contests_menu, .pop_menu {'
                     + 'position: absolute;'
                     + 'z-index: 35;'
                     + 'top: 1px;'
                     + 'display: flex;'
                     + 'flex-direction: column;'
                     + 'border-radius: 3px;'
                     + 'text-decoration: none;'
                     + 'background-color: rgba(32, 3, 7, 0.75);'
                     + 'box-shadow: 0 0 0 1px #ffb827;'
                     + 'opacity: 0;'
                     + 'visibility: hidden;'
                     + 'font-size: 14px;'
                     + 'font-weight: 400;'
                     + 'letter-spacing: .22px;'
                     + 'color: #ffb827;'
                     + 'font-family: \'Carter One\', \'Alegreya Sans\', cursive !important;'
                     + 'justify-content: center;'
                     + 'transition: opacity 200ms, visibility 200ms;'
                     + 'text-align: center;}'
                    );

    sheet.insertRule('#hh_gay .daily_goals_menu, #hh_gay .missions_menu, #hh_gay .contests_menu, #hh_gay .pop_menu {'
                     + 'box-shadow: 0 0 0 1px #69e5ff !important;'
                     + 'color: #69e5ff !important;}'
                    );

    sheet.insertRule('#hh_star .daily_goals_menu, #hh_star .missions_menu, #hh_star .contests_menu, #hh_star .pop_menu {'
                     + 'box-shadow: 0 0 0 1px #ff9174 !important;'
                     + 'color: #ff9174 !important;}'
                    );

    sheet.insertRule('#hh_comix .daily_goals_menu, #hh_comix .missions_menu, #hh_comix .contests_menu, #hh_comix .pop_menu {'
                     + 'font-family: Montserrat !important;'
                     + 'font-weight: 700 !important;'
                     + 'box-shadow: 0 0 0 1px #ffca47 !important;'
                     + 'color: #ffca47 !important;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.daily_goals_menu, .missions_menu, .contests_menu, .pop_menu {'
                     + 'width: 160px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.daily_goals_menu {'
                     + 'width: 120px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.missions_menu {'
                     + 'width: 90px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.contests_menu {'
                     + 'width: 110px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.pop_menu {'
                     + 'width: 80px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.daily_goals_menu, .missions_menu, .contests_menu, .pop_menu {'
                     + 'height: 26px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.daily_goals_menu, .missions_menu, .contests_menu, .pop_menu {'
                     + 'height: 52px;}}'
                    );

    sheet.insertRule('a[rel="activities"] a:hover {'
                     + 'text-decoration: underline;}'
                    );

    sheet.insertRule('a[rel="activities"] > .daily_goals_menu {'
                     + 'margin-left: 130px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="activities"] > .missions_menu {'
                     + 'margin-left: 290px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="activities"] > .missions_menu {'
                     + 'margin-left: 250px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="activities"] > .contests_menu {'
                     + 'margin-top: 26px;'
                     + 'margin-left: 130px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="activities"] > .pop_menu {'
                     + 'margin-top: 26px;'
                     + 'margin-left: 290px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="activities"] > .contests_menu {'
                     + 'margin-left: 340px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="activities"] > .pop_menu {'
                     + 'margin-left: 450px;}}'
                    );

    sheet.insertRule('#hh_sexy a[rel="activities"] > .missions_menu {'
                     + 'margin-left: 130px !important;}'
                    );

    sheet.insertRule('#hh_sexy a[rel="activities"] > .contests_menu {'
                     + 'margin-left: 290px !important;}'
                    );

    sheet.insertRule('a[rel="activities"]:hover > .daily_goals_menu {'
                     + 'margin-left: 130px;'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="activities"]:hover > .missions_menu {'
                     + 'margin-left: 291px;'
                     + 'opacity: 1; '
                     + 'visibility: visible;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="activities"]:hover > .missions_menu {'
                     + 'margin-left: 251px;'
                     + 'opacity: 1; '
                     + 'visibility: visible;}}'
                    );

    sheet.insertRule('a[rel="activities"]:hover > .contests_menu, a[rel="activities"]:hover > .pop_menu {'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="activities"]:hover > .contests_menu {'
                     + 'margin-top: 26px;'
                     + 'margin-left: 130px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="activities"]:hover > .pop_menu {'
                     + 'margin-top: 26px;'
                     + 'margin-left: 291px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="activities"]:hover > .contests_menu {'
                     + 'margin-left: 342px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="activities"]:hover > .pop_menu {'
                     + 'margin-left: 453px;}}'
                    );

    sheet.insertRule('#hh_sexy a[rel="activities"]:hover > .missions_menu {'
                     + 'margin-left: 130px !important;}'
                    );

    sheet.insertRule('#hh_sexy a[rel="activities"]:hover > .contests_menu {'
                     + 'margin-left: 280px !important;}'
                    );

    sheet.insertRule('#home_pachinko_bar, #home_champions_bar {'
                     + 'display: flex;'
                     + 'flex-direction: column;'
                     + 'width: 100%;'
                     + 'margin-top: -5px;'
                     + 'font-size: 11px;}'
                    );

    sheet.insertRule('.pachinko-timer-container, .champions-timer-container, .pov-timer-container, .season-timer-container, .pog-timer-container {'
                     + 'display: flex;'
                     + 'flex-direction: row;'
                     + 'justify-content: left;'
                     + 'align-items: center;}'
                    );

    sheet.insertRule('#home_pachinko_bar .pachinko-timer-container .timerClock_icn, #home_champions_bar .champions-timer-container .timerClock_icn {'
                     + 'width: 50px;'
                     + 'background-size: 28px;}'
                    );

    sheet.insertRule('#home_pachinko_bar .text, #home_champions_bar .text, #home_missions_bar1 .text, #home_missions_bar2 .text {'
                     + 'width: 140px;'
                     + 'text-align: left;'
                     + 'margin-left: 7px;'
                     + 'font-size: 13px !important;'
                     + 'color: #fff;'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('a[rel="pachinko"] .notif-position span {'
                     + 'flex-direction: column;}'
                    );

    sheet.insertRule('a[rel="pachinko"] .notif-position span p {'
                     + 'margin-top: 0;'
                     + 'margin-bottom: 0;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] .notif-position span {'
                     + 'flex-direction: column;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] .notif-position span p {'
                     + 'margin-top: 0;'
                     + 'margin-bottom: 0;}'
                    );

    sheet.insertRule('#home_pov_bar, #home_pog_bar {'
                     + 'width: 97px;'
                     + 'margin-left: -5px;'
                     + 'margin-top: -26px;}'
                    );

    sheet.insertRule('#hh_comix #home_pov_bar, #hh_comix #home_season_bar, #hh_comix #home_pog_bar {'
                     + 'width: 100% !important;}'
                    );

    sheet.insertRule('#home_season_bar {'
                     + 'width: 228px;'
                     + 'margin-left: -5px;'
                     + 'margin-top: -5px;}'
                    );

    sheet.insertRule('#home_pov_bar .pov-timer-container .timerClock_icn, #home_season_bar .season-timer-container .timerClock_icn, #home_pog_bar .pog-timer-container .timerClock_icn {'
                     + 'width: 32px;'
                     + 'background-size: 20px;}'
                    );

    sheet.insertRule('#home_pov_bar .text {'
                     + 'font-size: 10px !important;'
                     + 'color: #fff;'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('#home_season_bar .text {'
                     + 'font-size: 10px !important;'
                     + 'color: #fff;'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('#home_pog_bar .text {'
                     + 'font-size: 10px !important;'
                     + 'color: #fff;'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('#homepage .pov-widget .tier_bar_container, #homepage .pog-widget .tier_bar_container {'
                     + 'margin-top: -4px;}'
                    );

    sheet.insertRule('#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .pov-button > a[rel="path-of-valor"] > .notif-position .pov-widget  {'
                     + 'height: 64px !important;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.league_counter {'
                     + 'position: absolute; '
                     + 'z-index: 4; '
                     + 'width: 75%; '
                     + 'height: 20px; '
                     + 'margin: 40px 0 0 10px; '
                     + 'border-radius: 8px 10px 10px 8px; '
                     + 'background-color: rgba(0,0,0,.8); '
                     + 'box-shadow: 0 0 0 1px rgba(255,255,255,0.73); '
                     + 'font-size: 14px; '
                     + 'font-weight: 400; '
                     + 'letter-spacing: .22px; '
                     + 'color: #fff; '
                     + 'border: 3px; '
                     + 'text-align: center;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.league_counter {'
                     + 'position: absolute; '
                     + 'z-index: 4; '
                     + 'width: 75%; '
                     + 'height: 20px; '
                     + 'margin: 80px 0 0 10px; '
                     + 'border-radius: 8px 10px 10px 8px; '
                     + 'background-color: rgba(0,0,0,.8); '
                     + 'box-shadow: 0 0 0 1px rgba(255,255,255,0.73); '
                     + 'font-size: 14px; '
                     + 'font-weight: 400; '
                     + 'letter-spacing: .22px; '
                     + 'color: #fff; '
                     + 'border: 3px; '
                     + 'text-align: center;}}'
                    );

    sheet.insertRule('#hh_comix .league_counter {'
                     + 'font-family: Montserrat !important;'
                     + 'font-weight: 700 !important;}'
                    );

    sheet.insertRule('.league_counter a {'
                     + 'font-family: \'Carter One\', \'Alegreya Sans\', cursive !important; '
                     + 'color: rgb(255, 255, 255); '
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#LeagueTimer {'
                     + 'width: 150px;'
                     + 'top: 0px;'
                     + 'left: 276px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#LeagueTimer {'
                     + 'width: 150px;'
                     + 'top: -10px;'
                     + 'left: 285px;}}'
                    );

    sheet.insertRule('#LeagueTimer a {'
                     + 'color: rgb(255, 255, 255);'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('#LeagueTimer a:hover {'
                     + 'color: rgb(255, 247, 204);}'
                    );

    sheet.insertRule ('#scriptLeagueTimer {'
                      + 'font-size: 11px;'
                      + 'color: #8ec3ff;}'
                     );

    sheet.insertRule('#league_bar {'
                     + 'border-radius: 8px 10px 10px 8px;'
                     + 'width: 100%;'
                     + 'height: 100%;}'
                    );

    sheet.insertRule('.league_icn{'
                     + 'display:block;'
                     + 'width:29px;'
                     + 'height:31px;'
                     + 'background-image:url("' + window.IMAGES_URL + '/pictures/design/league_points.png");'
                     + 'background-size:25px;'
                     + 'background-position:center;'
                     + 'background-repeat:no-repeat;'
                     + 'margin:0;'
                     + 'padding:0;'
                     + 'position:absolute;'
                     + 'margin: -5px 0 0 -20px; '
                     + 'z-index:36}');

    sheet.insertRule(`${mediaDesktop} {`
                     + '.scriptSeasonInfo {'
                     + 'display: block; '
                     + 'position: absolute; '
                     + 'z-index: 4; '
                     + 'width: 90%; '
                     + 'height: 20px; '
                     + 'margin: 40px 0 0 220px; '
                     + 'border-radius: 8px 10px 10px 8px; '
                     + 'background-color: rgba(0,0,0,.8); '
                     + 'box-shadow: 0 0 0 1px rgba(255,255,255,0.73); '
                     + 'font-size: 14px; '
                     + 'font-weight: 400; '
                     + 'letter-spacing: .22px; '
                     + 'color: #fff; '
                     + 'text-align: center;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.scriptSeasonInfo {'
                     + 'display: block; '
                     + 'position: absolute; '
                     + 'z-index: 4; '
                     + 'width: 90%; '
                     + 'height: 20px; '
                     + 'margin: 80px 0 0 190px; '
                     + 'border-radius: 8px 10px 10px 8px; '
                     + 'background-color: rgba(0,0,0,.8); '
                     + 'box-shadow: 0 0 0 1px rgba(255,255,255,0.73); '
                     + 'font-size: 14px; '
                     + 'font-weight: 400; '
                     + 'letter-spacing: .22px; '
                     + 'color: #fff; '
                     + 'text-align: center;}}'
                    );

    sheet.insertRule('#hh_comix .scriptSeasonInfo {'
                     + 'font-family: Montserrat !important;'
                     + 'font-weight: 700 !important;}'
                    );

    sheet.insertRule('.scriptSeasonInfo a {'
                     + 'font-family: \'Carter One\', \'Alegreya Sans\', cursive !important; '
                     + 'color: rgb(255, 255, 255); '
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#FightSeason {'
                     + 'width: 150px;'
                     + 'top: 0px;'
                     + 'left: 252px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#FightSeason {'
                     + 'width: 150px;'
                     + 'top: -10px;'
                     + 'left: 290px;}}'
                    );

    sheet.insertRule('#FightSeason a {'
                     + 'color: rgb(255, 255, 255);'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('#FightSeason a:hover {'
                     + 'color: rgb(255, 247, 204);} '
                    );

    sheet.insertRule ('#scriptSeasonTimer {'
                      + 'font-size: 11px; '
                      + 'color: #8ec3ff;}'
                     );

    sheet.insertRule('#kisses_bar {'
                     + 'border-radius: 8px 10px 10px 8px; '
                     + 'width: 100%; '
                     + 'height: 100%;} '
                    );

    sheet.insertRule('.season_icn{'
                     + 'display:block;'
                     + 'width:29px;'
                     + 'height:31px;'
                     + 'background-image:url("' + window.IMAGES_URL + '/pictures/design/ic_kiss.png");'
                     + 'background-size:25px;'
                     + 'background-position:center;'
                     + 'background-repeat:no-repeat;'
                     + 'margin:0;'
                     + 'padding:0;'
                     + 'position:absolute;'
                     + 'margin: -5px 0 0 -20px; '
                     + 'z-index: 36}');

    sheet.insertRule(`${mediaDesktop} {`
                     + '.scriptPantheonInfo {'
                     + 'display: block; '
                     + 'position: absolute; '
                     + 'z-index: 4; '
                     + 'width: 90%; '
                     + 'height: 20px; '
                     + 'margin: 85px 0 0 10px; '
                     + 'border-radius: 8px 10px 10px 8px; '
                     + 'background-color: rgba(0,0,0,.8); '
                     + 'box-shadow: 0 0 0 1px rgba(255,255,255,0.73); '
                     + 'font-size: 14px; '
                     + 'font-weight: 400; '
                     + 'letter-spacing: .22px; '
                     + 'color: #fff; '
                     + 'text-align: center;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.scriptPantheonInfo {'
                     + 'display: block; '
                     + 'position: absolute; '
                     + 'z-index: 4; '
                     + 'width: 90%; '
                     + 'height: 20px; '
                     + 'margin: 60px 0 0 34px; '
                     + 'border-radius: 8px 10px 10px 8px; '
                     + 'background-color: rgba(0,0,0,.8); '
                     + 'box-shadow: 0 0 0 1px rgba(255,255,255,0.73); '
                     + 'font-size: 14px; '
                     + 'font-weight: 400; '
                     + 'letter-spacing: .22px; '
                     + 'color: #fff; '
                     + 'text-align: center;}}'
                    );

    sheet.insertRule('#hh_comix .scriptPantheonInfo {'
                     + 'font-family: Montserrat !important;'
                     + 'font-weight: 700 !important;}'
                    );

    sheet.insertRule('.scriptPantheonInfo a {'
                     + 'font-family: \'Carter One\', \'Alegreya Sans\', cursive !important;'
                     + 'color: rgb(255, 255, 255);'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#FightPantheon {'
                     + 'width: 150px;'
                     + 'top: -45px;'
                     + 'left: 650px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#FightPantheon {'
                     + 'width: 150px;'
                     + 'top: 10px;'
                     + 'left: 630px;}}'
                    );

    sheet.insertRule('#FightPantheon a {'
                     + 'color: rgb(255, 255, 255);'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('#FightPantheon a:hover {'
                     + 'color: rgb(255, 247, 204);}'
                    );

    sheet.insertRule ('#scriptPantheonTimer {'
                      + 'font-size: 11px;'
                      + 'color: #8ec3ff;}'
                     );

    sheet.insertRule('#worship_bar {'
                     + 'border-radius: 8px 10px 10px 8px;'
                     + 'width: 100%;'
                     + 'height: 100%;}'
                    );

    sheet.insertRule('.pantheon_icn{'
                     + 'display:block;'
                     + 'width:29px;'
                     + 'height:31px;'
                     + 'background-image:url("' + window.IMAGES_URL + '/pictures/design/ic_worship.svg");'
                     + 'background-size:25px;'
                     + 'background-position:center;'
                     + 'background-repeat:no-repeat;'
                     + 'margin:0;'
                     + 'padding:0;'
                     + 'position:absolute;'
                     + 'margin: -5px 0 0 -20px;'
                     + 'z-index: 36}');

    sheet.insertRule(`${mediaDesktop} {`
                     + '.pop_timer {'
                     + 'position: absolute;'
                     + 'z-index: 4;'
                     + 'width: 90%;'
                     + 'height: 20px;'
                     + 'margin: 40px 0 0 400px;'
                     + 'border-radius: 8px 10px 10px 8px;'
                     + 'background-color: rgba(0,0,0,.8);'
                     + 'box-shadow: 0 0 0 1px rgba(255,255,255,0.73);'
                     + 'font-size: 14px;'
                     + 'font-weight: 400;'
                     + 'letter-spacing: .22px;'
                     + 'color: #fff;'
                     + 'text-align: center;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.pop_timer {'
                     + 'position: absolute;'
                     + 'z-index: 4;'
                     + 'width: 90%;'
                     + 'height: 20px;'
                     + 'margin: 80px 0 0 350px;'
                     + 'border-radius: 8px 10px 10px 8px;'
                     + 'background-color: rgba(0,0,0,.8);'
                     + 'box-shadow: 0 0 0 1px rgba(255,255,255,0.73);'
                     + 'font-size: 14px;'
                     + 'font-weight: 400;'
                     + 'letter-spacing: .22px;'
                     + 'color: #fff;'
                     + 'text-align: center;}}'
                    );

    sheet.insertRule('#hh_comix .pop_timer {'
                     + 'font-family: Montserrat !important;'
                     + 'font-weight: 700 !important;}'
                    );

    sheet.insertRule('.pop_timer a {'
                     + 'font-family: \'Carter One\', \'Alegreya Sans\', cursive !important;'
                     + 'color: rgb(255, 255, 255);'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#PoPTimer {'
                     + 'width: 150px;'
                     + 'top:0px;'
                     + 'left: 429px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#PoPTimer {'
                     + 'width: 150px;'
                     + 'top: -10px;'
                     + 'left: 477px;}}'
                    );

    sheet.insertRule('#PoPTimer a {'
                     + 'color: rgb(255, 255, 255); '
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule('#PoPTimer a:hover {'
                     + 'color: rgb(255, 247, 204);} '
                    );

    sheet.insertRule ('#scriptPoPTimer {'
                      + 'font-size: 11px;}'
                     );

    sheet.insertRule('#pop_bar {'
                     + 'border-radius: 8px 10px 10px 8px; '
                     + 'width: 100%; '
                     + 'height: 100%;} '
                    );

    sheet.insertRule('.club-wrapper span[sort_by] {'
                     + 'display: block;}'
                    );

    sheet.insertRule('.club-wrapper > .club-container .club_champions_panel .club_champions_participants_container table tbody tr td:nth-child(2), '
                     + '.club-wrapper > .club-container .club_champions_panel .club_champions_participants_container table thead th:nth-child(2) {'
                     + 'width: 40%;}'
                    );

    sheet.insertRule('.club-wrapper > .club-container .club_champions_panel .club_champions_participants_container table tbody tr td:nth-child(4), '
                     + '.club-wrapper > .club-container .club_champions_panel .club_champions_participants_container table thead th:nth-child(4) {'
                     + 'width: 30%;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.page-champions .personal-bars__attacker, .page-champions .personal-bars__defender {'
                     + 'top: -20px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.page-club_champion .personal-bars__attacker, .page-club_champion .personal-bars__defender {'
                     + 'top: -15px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.champions-top__inner-wrapper {'
                     + 'top: 4px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.section__battle-header {'
                     + 'top: 15px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.section__battle-header {'
                     + 'top: 25px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.special-ability-pending {'
                     + 'top: 75px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.special-ability-pending {'
                     + 'top: 100px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.trollPts_icn {'
                     + 'position: absolute;'
                     + 'top: 9px;'
                     + 'left: 10px;'
                     + 'z-index: 99;'
                     + 'display: block;'
                     + 'width: 29px;'
                     + 'height: 31px;'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/ic_topbar_energy_fight.png");'
                     + 'background-size: 25px;'
                     + 'background-position: center;'
                     + 'background-repeat: no-repeat;'
                     + 'margin: 0;'
                     + 'padding: 0;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.trollPts_icn {'
                     + 'position: absolute;'
                     + 'top: 28px;'
                     + 'left: 10px;'
                     + 'z-index: 99;'
                     + 'display: block;'
                     + 'width: 30px;'
                     + 'height: 33px;'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/ic_topbar_energy_fight.png");'
                     + 'background-size: 25px;'
                     + 'background-position: center;'
                     + 'background-repeat: no-repeat;'
                     + 'margin: 0;'
                     + 'padding: 0;}}'
                    );

    sheet.insertRule('#fight_energy_bar .trollTooltip {'
                     + 'width: 190px; '
                     + 'top: 32px; '
                     + 'margin-left: -80px;}'
                    );

    sheet.insertRule('#fight_energy_bar .trollPts_icn:hover .trollTooltip {'
                     + 'color: gray; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#fight_energy_bar .trollPts_icn:hover #troll_title {'
                     + 'color: white; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#fight_energy_bar .trollPts_icn:hover #troll_time_remaining {'
                     + 'color: orange; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#quest_energy_bar .bar-wrapper .over a {'
                     + 'display: flex;'
                     + 'color: white;'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#quest_energy_bar .bar-wrapper .over a {'
                     + 'flex-direction: row;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#quest_energy_bar .bar-wrapper .over a {'
                     + 'flex-direction: column;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#quest_energy_bar .energy_counter_bar .bar-wrapper .over [rel="count_txt"] {'
                     + 'position: relative;'
                     + 'top: 2px;'
                     + 'left: 5px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.energy_icn {'
                     + 'position: absolute;'
                     + 'top: 9px;'
                     + 'left: 21px;'
                     + 'z-index: 36;'
                     + 'display: block;'
                     + 'width: 21px;'
                     + 'height: 30px;'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/ic_topbar_energy_quest.png");'
                     + 'background-size: 21px;'
                     + 'background-position: center;'
                     + 'background-repeat: no-repeat;'
                     + 'margin: 0;'
                     + 'padding: 0;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.energy_icn {'
                     + 'position: absolute;'
                     + 'top: 28px;'
                     + 'left: 13px;'
                     + 'z-index: 36;'
                     + 'display: block;'
                     + 'width: 30px;'
                     + 'height: 33px;'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/ic_topbar_energy_quest.png");'
                     + 'background-size: 25px;'
                     + 'background-position: center;'
                     + 'background-repeat: no-repeat;'
                     + 'margin: 0;'
                     + 'padding: 0;}}'
                    );

    sheet.insertRule('#quest_energy_bar .energyTooltip {'
                     + 'width: 190px; '
                     + 'top: 32px; '
                     + 'margin-left: -82px;}'
                    );

    sheet.insertRule('#quest_energy_bar .energy_icn:hover .energyTooltip {'
                     + 'color: gray; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#quest_energy_bar .energy_icn:hover #energy_title {'
                     + 'color: white; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#quest_energy_bar .energy_icn:hover #energy_time_remaining {'
                     + 'color: orange; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#club_whole .club-wrapper > .club-container.club_dashboard > h2 {'
                     + 'top: 5px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#club_whole .club-wrapper > .club-container.club_dashboard > h2 {'
                     + 'top: 15px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.page-pachinko #content-unscaled {'
                     + 'margin-top: 7px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.page-pachinko #content-unscaled {'
                     + 'margin-top: 13px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#season-arena .opponents_choose_text_container {'
                     + 'margin-top:10px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#season-arena .season_arena_opponent_container {'
                     + 'margin-top: -15px !important;'
                     + 'height:400px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#season-arena .opponent_perform_button_container {'
                     + 'margin-top:-15px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#new_battle .new-battle-hero-container.new-battle-player>div:nth-child(1) {'
                     + 'margin-top: 35px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.hero-name-level-container {'
                     + 'margin-top: 30px;}}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] .round_blue_button.champions {'
                     + 'position: absolute;'
                     + 'z-index: 100;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="sex-god-path"] .round_blue_button.champions {'
                     + 'top: 11px;'
                     + 'left: 147px;'
                     + 'width: 30px;'
                     + 'height: 30px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="sex-god-path"] .round_blue_button.champions {'
                     + 'top: 7px;'
                     + 'left: 140px;'
                     + 'width: 40px;'
                     + 'height: 40px;}}'
                    );

    sheet.insertRule('.champions_flat_icn {'
                     + 'margin-top: 3px;'
                     + 'background-image: url("' + window.IMAGES_URL + '/design/menu/ic_champions.svg");'
                     + 'background-position: center;'
                     + 'background-repeat: no-repeat;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.champions_flat_icn {'
                     + 'height: 21px;'
                     + 'width: 18px;'
                     + 'background-size: 17px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.champions_flat_icn {'
                     + 'height: 23px;'
                     + 'width: 19px;'
                     + 'background-size: 19px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .main-container .left-side-container {'
                     + 'margin-top: 20px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .social_links {'
                     + 'z-index: 2;'
                     + 'margin-top: 467px;'
                     + 'margin-left: 558px;}}'
                    );

    sheet.insertRule('#seasons_main_container, .pantheon_border_gradient, #season-arena .season_arena_block.opponent .hero_stats, #season-arena .season_arena_block.opponent .hero_team, #season-arena .season_arena_block.opponent .personal_info {'
                     + 'z-index: 0 !important;}'
                    );

    sheet.insertRule('#waifu-page, #shops, #activities, #club_whole, #league, .pantheon_bgr, #harem_whole, .help-screen-container, .pov-background-panel, #personal_forms .settings-container, .seasonal-event-panel, .girl-leveler-panel {'
                     + 'z-index: 1 !important;}'
                    );

    sheet.insertRule('.settings-container h3.headline-page {'
                     + 'margin-top: 17px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#shops #my-hero-tab-container p.content-title {'
                     + 'position: relative;'
                     + 'top: 11px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#shops p.left-side-title, #shops p.right-side-title {'
                     + 'position: relative;'
                     + 'top: 10px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#shops p.menu-title {'
                     + 'margin-top: -3px !important;}}'
                    );

    sheet.insertRule('.seasonal-event-panel .overlayed-title {'
                     + 'margin-top: -0.9rem !important;}'
                    );

    sheet.insertRule('#homepage .main-container .left-side-container > a > .notif-position .additional-menu-data p, #homepage .main-container .left-side-container span[rel="expires"] {'
                     + 'font-size: 13px !important;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#harem_left h3 {'
                     + 'position: relative;'
                     + 'top: 3px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                    + '#harem_left > .harem-top-controls {'
                    + 'z-index: 10;}}'
                   );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#harem_left .general_girls_console {'
                     + 'position: relative;'
                     + 'top: 5px;'
                     + 'margin-bottom: 5px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#leagues .page-title {'
                     + 'margin-top: 26px;}}'
                    );

    if (CurrentPage.indexOf('troll-pre-battle') != -1) {
        if (localStorage.getItem('HHPlusPlusConfig')) {
            if (JSON.parse(localStorage.getItem('HHPlusPlusConfig')).core_villainBreadcrumbs) {
                sheet.insertRule('#breadcrumbs {'
                                 + 'margin-top: 15px;}'
                                );

                sheet.insertRule('#pre-battle .player-panel {'
                                 + 'margin-top: 4px;}'
                                );
            }
        }
    }

    sheet.insertRule(`${mediaDesktop} {`
                     + 'header a.hh_logo, header .square-avatar-wrapper[rel="avatar"] {'
                     + 'width: 30px !important;'
                     + 'height: 30px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'header a.hh_logo {'
                     + 'margin-right: 0.8rem !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'header a#chat_btn {'
                     + 'width: 30px !important;'
                     + 'height: 30px !important;'
                     + 'margin-right: 20px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.chat_mix_icn {'
                     + 'background-size: 30px !important;'
                     + 'width: 30px !important;'
                     + 'height: 30px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'header .square-avatar-wrapper[rel="avatar"] img:not(.button-notification-new) {'
                     + 'width: 24px !important;'
                     + 'height: 24px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'header plus {'
                     + 'width: 32px !important;'
                     + 'height: 32px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'header plus[type="energy_quest"], header plus[type="energy_fight"] {'
                     + 'top: 6px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'header #show-hero-resources, header #blessings-button {'
                     + 'width: 32px !important;'
                     + 'height: 32px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'header {'
                     + 'margin-top: -10px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'header a.hh_logo, header .square-avatar-wrapper[rel="avatar"] {'
                     + 'width: 50px !important;'
                     + 'height: 50px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'header a.hh_logo, header a#chat_btn, header #quest_energy_bar, header .currency  {'
                     + 'margin-right: 15px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'header #fight_energy_bar, header #show-hero-resources  {'
                     + 'margin-right: 10px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'header a#chat_btn {'
                     + 'width: 50px !important;'
                     + 'height: 50px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.chat_mix_icn {'
                     + 'background-size: 50px !important;'
                     + 'width: 50px !important;'
                     + 'height: 50px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'header .square-avatar-wrapper[rel="avatar"] img:not(.button-notification-new) {'
                     + 'width: 44px !important;'
                     + 'height: 44px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'header div[rel="xp"] {'
                     + 'margin-right: 20px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'header plus {'
                     + 'width: 50px !important;'
                     + 'height: 50px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.page-hero_pages section .back {'
                     + 'top: -77px !important;'
                     + 'width: 47px !important;'
                     + 'height: 47px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.page-hero_pages section .back span {'
                     + 'background-size: 25px !important;'
                     + 'background-repeat: no-repeat;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'header plus[type="energy_quest"], header plus[type="energy_fight"] {'
                     + 'top: 16px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'header div.currency plus {'
                     + 'top: 4px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'header #show-hero-resources, header #blessings-button {'
                     + 'width: 50px !important;'
                     + 'height: 50px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'header #show-hero-resources, header #blessings-button {'
                     + 'margin-top: 13px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#contains_all > nav > [rel="open"] {'
                     + 'top: 5px !important;'
                     + 'width: 50px !important;'
                     + 'height: 50px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#shops {'
                     + 'margin-top: 0px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#breadcrumbs > a:last-of-type {'
                     + 'top: 5px !important;'
                     + 'left: 3px !important;'
                     + 'width: 48px !important;'
                     + 'height: 48px !important}}'
                    );

    sheet.insertRule('#harem_whole #filtering_girls > h3 {'
                     + 'position: relative;'
                     + 'top: 2px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.mega-event-panel .mega-event-container .overlayed-section .page-title .overlayed-title {'
                     + 'margin-top: -1rem !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.promo_profile_discount_text {'
                     + 'margin-left: 50px !important; '
                     + 'margin-top: -58px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.promo_profile_discount_text {'
                     + 'position : absolute !important;'
                     + 'top: -4px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.promo_quest_discount_text {'
                     + 'margin-left: -44px !important; '
                     + 'margin-top: -58px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.promo_quest_discount_text {'
                     + 'position : absolute !important;'
                     + 'left: 292px !important;'
                     + 'top: -3px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.promo_fight_discount_text {'
                     + 'margin-left: -66px !important; '
                     + 'margin-top: -58px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.promo_fight_discount_text {'
                     + 'position : absolute !important;'
                     + 'left: 479px !important;'
                     + 'top: -3px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.labyrinth-splash-page .page-title {'
                     + 'margin-top: 10px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hero_club .club-main-container .top-row .page-title {'
                     + 'margin-top: 6px;}}'
                    );
}

/* ==============
	SEASON STATS
   ============== */

function moduleSeasonStats() {
    const resetUTCHour = 12;
    let seasonDateEndData = localStorage.getItem('HHS.SeasonDateEnd') || JSON.stringify({day: 0, month: 0, year: 0, hour: 0});
    let seasonDateEnd = JSON.parse(seasonDateEndData);
    let currentDay = new Date().getUTCDate();
    let currentMonth = new Date().getUTCMonth();
    let currentYear = new Date().getUTCFullYear();
    let currentHour = new Date().getUTCHours();
    if (seasonDateEnd.hour == 0) {
        seasonDateEnd.day = 1;
        if ((currentDay == 1) && (currentHour < 12)) seasonDateEnd.month = currentMonth;
        else seasonDateEnd.month = (currentMonth + 1)%12;
        seasonDateEnd.year = currentYear;
        if (seasonDateEnd.month == 0) seasonDateEnd.year += 1;
        seasonDateEnd.hour = (seasonDateEnd.month > 2 && seasonDateEnd.month < 10) ? (resetUTCHour - 1) : resetUTCHour;
        localStorage.setItem('HHS.SeasonDateEnd', JSON.stringify(seasonDateEnd));
    }
    if ((currentMonth == seasonDateEnd.month) && (currentDay >= seasonDateEnd.day) && (currentHour >= seasonDateEnd.hour)) {
        localStorage.setItem('HHS.oldSeasonStats', localStorage.getItem('HHS.SeasonStats'));
        localStorage.removeItem('HHS.SeasonStats');
        seasonDateEnd.day = 1;
        seasonDateEnd.month = (currentMonth + 1)%12;
        seasonDateEnd.year = (seasonDateEnd.month == 0) ? (seasonDateEnd.year + 1) : seasonDateEnd.year;
        seasonDateEnd.hour = (seasonDateEnd.month > 2 && seasonDateEnd.month < 10) ? (resetUTCHour - 1) : resetUTCHour;
        localStorage.setItem('HHS.SeasonDateEnd', JSON.stringify(seasonDateEnd));
    }
    else if ((currentMonth == seasonDateEnd.month) && (currentDay > seasonDateEnd.day)) {
        localStorage.setItem('HHS.oldSeasonStats', localStorage.getItem('HHS.SeasonStats'));
        localStorage.removeItem('HHS.SeasonStats');
        seasonDateEnd.day = 1;
        seasonDateEnd.month = (currentMonth + 1)%12;
        seasonDateEnd.year = (seasonDateEnd.month == 0) ? (seasonDateEnd.year + 1) : seasonDateEnd.year;
        seasonDateEnd.hour = (seasonDateEnd.month > 2 && seasonDateEnd.month < 10) ? (resetUTCHour - 1) : resetUTCHour;
        localStorage.setItem('HHS.SeasonDateEnd', JSON.stringify(seasonDateEnd));
    }
    else if ((currentMonth > seasonDateEnd.month) && (currentYear == seasonDateEnd.year)) {
        localStorage.setItem('HHS.oldSeasonStats', localStorage.getItem('HHS.SeasonStats'));
        localStorage.removeItem('HHS.SeasonStats');
        seasonDateEnd.day = 1;
        seasonDateEnd.month = (currentMonth + 1)%12;
        seasonDateEnd.year = (seasonDateEnd.month == 0) ? (seasonDateEnd.year + 1) : seasonDateEnd.year;
        seasonDateEnd.hour = (seasonDateEnd.month > 2 && seasonDateEnd.month < 10) ? (resetUTCHour - 1) : resetUTCHour;
        localStorage.setItem('HHS.SeasonDateEnd', JSON.stringify(seasonDateEnd));
    }
    else if (currentYear > seasonDateEnd.year) {
        localStorage.setItem('HHS.oldSeasonStats', localStorage.getItem('HHS.SeasonStats'));
        localStorage.removeItem('HHS.SeasonStats');
        seasonDateEnd.day = 1;
        seasonDateEnd.month = (currentMonth + 1)%12;
        seasonDateEnd.year = (seasonDateEnd.month == 0) ? (currentYear + 1) : currentYear;
        seasonDateEnd.hour = (seasonDateEnd.month > 2 && seasonDateEnd.month < 10) ? (resetUTCHour - 1) : resetUTCHour;
        localStorage.setItem('HHS.SeasonDateEnd', JSON.stringify(seasonDateEnd));
    }

    let seasonStatsData = localStorage.getItem('HHS.SeasonStats') || JSON.stringify({fights: 0, victories: 0, losses: 0, won_mojo: 0, lost_mojo: 0, won_mojo_avg: 0, lost_mojo_avg: 0, mojo_avg: 0});
    let seasonStats = JSON.parse(seasonStatsData);
    localStorage.setItem('HHS.SeasonStats', JSON.stringify(seasonStats));
    let fights = seasonStats.fights;
    let victories = seasonStats.victories;
    let losses = seasonStats.losses;
    let won_mojo = seasonStats.won_mojo;
    let lost_mojo = seasonStats.lost_mojo;
    let won_mojo_avg = seasonStats.won_mojo_avg;
    let lost_mojo_avg = seasonStats.lost_mojo_avg;
    let mojo_avg = seasonStats.mojo_avg;

    let oldSeasonStatsData = localStorage.getItem('HHS.oldSeasonStats') || JSON.stringify({fights: 0, victories: 0, losses: 0, won_mojo: 0, lost_mojo: 0, won_mojo_avg: 0, lost_mojo_avg: 0, mojo_avg: 0});
    let oldSeasonStats = JSON.parse(oldSeasonStatsData);
    localStorage.setItem('HHS.oldSeasonStats', JSON.stringify(oldSeasonStats));
    let old_fights = oldSeasonStats.fights;
    let old_victories = oldSeasonStats.victories;
    let old_losses = oldSeasonStats.losses;
    let old_won_mojo = oldSeasonStats.won_mojo;
    let old_lost_mojo = oldSeasonStats.lost_mojo;
    let old_won_mojo_avg = oldSeasonStats.won_mojo_avg;
    let old_lost_mojo_avg = oldSeasonStats.lost_mojo_avg;
    let old_mojo_avg = oldSeasonStats.mojo_avg;

    if (CurrentPage.indexOf('season-battle') != -1) {
        $(document).ajaxComplete(function(evt, xhr, opt) {
            const searchParams = new URLSearchParams(opt.data)
            if(searchParams.get('action') == 'do_battles_seasons') {
                if(!xhr.responseText.length) return;

                const response = JSON.parse(xhr.responseText);

                if(!response || !response.success) return;

                fights +=1;

                if (response.rewards.data.rewards[0].type == "victory_points") {
                    victories += 1;
                    won_mojo += localeStringToNumber(response.rewards.data.rewards[0].value);
                    won_mojo_avg = Math.floor(won_mojo/victories*100)/100;
                    mojo_avg = Math.floor((won_mojo-lost_mojo)/fights*100)/100;
                }
                else {
                    losses += 1;
                    lost_mojo += localeStringToNumber(response.rewards.data.rewards[1].value.substring(1));
                    lost_mojo_avg = Math.floor(lost_mojo/losses*100)/100;
                    mojo_avg = Math.floor((won_mojo-lost_mojo)/fights*100)/100;
                }

                seasonStats.fights = fights;
                seasonStats.victories = victories;
                seasonStats.won_mojo = won_mojo;
                seasonStats.won_mojo_avg = won_mojo_avg;
                seasonStats.losses = losses;
                seasonStats.lost_mojo = lost_mojo;
                seasonStats.lost_mojo_avg = lost_mojo_avg;
                seasonStats.mojo_avg = mojo_avg;
                localStorage.setItem('HHS.SeasonStats', JSON.stringify(seasonStats));
            }
        })
    }

    if (CurrentPage.indexOf('season-arena') == -1) {
        $('div#seasons_tab_title').append('<span class="scriptSeasonStats" style="color: #8ec3ff; margin-left: 54px; font-size: 16px">Stats'
                                          + '<span class="scriptSeasonStatsTooltip">' + labels.fights + ' : ' + fights
                                          + '<BR>' + labels.victories + ' : ' + nThousand(victories)
                                          + ' / ' + labels.defeats + ' : ' + nThousand(losses)
                                          + '<BR><BR>' + labels.won_mojo + ' : ' + nThousand(won_mojo)
                                          + '<BR>' + labels.lost_mojo + ' : ' + nThousand(lost_mojo)
                                          + '<BR><BR>' + labels.won_mojo_avg + ' : ' + won_mojo_avg
                                          + '<BR>' + labels.lost_mojo_avg + ' : ' + lost_mojo_avg
                                          + '<BR>' + labels.mojo_avg + ' : ' + mojo_avg + '<BR>_______________________'
                                          + '<BR>' + labels.last_season
                                          + '<br />'
                                          + '<BR>' + labels.fights + ' : ' + old_fights
                                          + '<BR>' + labels.victories + ' : ' + nThousand(old_victories)
                                          + ' / ' + labels.defeats + ' : ' + nThousand(old_losses)
                                          + '<BR><BR>' + labels.won_mojo + ' : ' + nThousand(old_won_mojo)
                                          + '<BR>' + labels.lost_mojo + ' : ' + nThousand(old_lost_mojo)
                                          + '<BR><BR>' + labels.won_mojo_avg + ' : ' + old_won_mojo_avg
                                          + '<BR>' + labels.lost_mojo_avg + ' : ' + old_lost_mojo_avg
                                          + '<BR>' + labels.mojo_avg + ' : ' + old_mojo_avg + '</span>'
                                          + '</span>');
    }

    if (CurrentPage.indexOf('season-arena') != -1) {
        $('#season-arena .player_team_block.battle_hero .personal_info').append('<div class="scriptSeasonStatsArena" style="color: #8ec3ff; margin-left: 15px; margin-top: 28px; font-size: 16px">Stats'
                                                                                + '<span class="scriptSeasonStatsTooltipArena">' + labels.fights + ' : ' + fights
                                                                                + '<BR>' + labels.victories + ' : ' + nThousand(victories)
                                                                                + ' / ' + labels.defeats + ' : ' + nThousand(losses)
                                                                                + '<BR><BR>' + labels.won_mojo + ' : ' + nThousand(won_mojo)
                                                                                + '<BR>' + labels.lost_mojo + ' : ' + nThousand(lost_mojo)
                                                                                + '<BR><BR>' + labels.won_mojo_avg + ' : ' + won_mojo_avg
                                                                                + '<BR>' + labels.lost_mojo_avg + ' : ' + lost_mojo_avg
                                                                                + '<BR>' + labels.mojo_avg + ' : ' + mojo_avg + '<BR>_______________________'
                                                                                + '<BR>' + labels.last_season
                                                                                + '<br />'
                                                                                + '<BR>' + labels.fights + ' : ' + old_fights
                                                                                + '<BR>' + labels.victories + ' : ' + nThousand(old_victories)
                                                                                + ' / ' + labels.defeats + ' : ' + nThousand(old_losses)
                                                                                + '<BR><BR>' + labels.won_mojo + ' : ' + nThousand(old_won_mojo)
                                                                                + '<BR>' + labels.lost_mojo + ' : ' + nThousand(old_lost_mojo)
                                                                                + '<BR><BR>' + labels.won_mojo_avg + ' : ' + old_won_mojo_avg
                                                                                + '<BR>' + labels.lost_mojo_avg + ' : ' + old_lost_mojo_avg
                                                                                + '<BR>' + labels.mojo_avg + ' : ' + old_mojo_avg
                                                                                + '</span>'
                                                                                + '</div>');
    }

    //CSS
    sheet.insertRule('.scriptSeasonStatsTooltip {'
                     + 'visibility: hidden; '
                     + 'font-size: 12px; '
                     + 'background-color: black; '
                     + 'color: #fff; '
                     + 'text-align: center; '
                     + 'padding: 3px 5px 3px 5px; '
                     + 'border: 2px solid #905312; '
                     + 'border-radius: 6px; '
                     + 'background-color: rgba(32,3,7,.9); '
                     + 'position: absolute; '
                     + 'margin-top: 35px; '
                     + 'margin-left: -112px; '
                     + 'width: 90%; '
                     + 'z-index: 100;}'
                    );

    sheet.insertRule('.scriptSeasonStatsTooltip::after {'
                     + 'content: " "; '
                     + 'position: absolute; '
                     + 'bottom: 100%; '
                     + 'left: 50%; '
                     + 'margin-top:  3px; '
                     + 'margin-left:  -10px; '
                     + 'border-width: 10px; '
                     + 'border-style: solid; '
                     + 'border-color: transparent transparent #905312 transparent;}'
                    );

    sheet.insertRule('.scriptSeasonStats:hover .scriptSeasonStatsTooltip {'
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('.scriptSeasonStatsTooltipArena {'
                     + 'visibility: hidden; '
                     + 'font-size: 12px; '
                     + 'background-color: black; '
                     + 'color: #fff; '
                     + 'text-align: center; '
                     + 'padding: 3px 5px 3px 5px; '
                     + 'border: 2px solid #905312; '
                     + 'border-radius: 6px; '
                     + 'background-color: rgba(32,3,7,.9); '
                     + 'position: absolute; '
                     + 'margin-top: 30px; '
                     + 'margin-left: -112px; '
                     + 'width: max-content; '
                     + 'z-index: 100;}'
                    );

    sheet.insertRule('.scriptSeasonStatsTooltipArena::after {'
                     + 'content: " "; '
                     + 'position: absolute; '
                     + 'bottom: 100%; '
                     + 'left: 50%; '
                     + 'margin-left:  -10px; '
                     + 'border-width: 10px; '
                     + 'border-style: solid; '
                     + 'border-color: transparent transparent #905312 transparent;}'
                    );

    sheet.insertRule('.scriptSeasonStatsArena:hover .scriptSeasonStatsTooltipArena {'
                     + 'visibility: visible;}'
                    );
}

/* ==================================
	PACHINKO NAMES (Credit : Shinya)
   ================================== */

function modulePachinkoNames() {
    if ($('#pachinko_whole').length){
        const jsonMapData = localStorage.getItem('HHS.HHPNMap');
        const jsonShardsMapData = localStorage.getItem('HHS.HHPNShardsMap') || '[]';
        if (!jsonMapData) {
            return
        }
        const localizationMap = new Map(JSON.parse(jsonMapData).concat(JSON.parse(jsonShardsMapData)));
        const targetNode = document.getElementById('pachinko_whole');
        const config = { attributes: true, childList: true, subtree: true };

        const callback = function(mutationsList, observer){
            let text = $('#playzone-replace-info');
            if (text.find('.HHMI-INFO').length != 0 && text.find('.HHMI-INFO1').length != 0) {
                return
            } else if (text.find('.HHMI-INFO').length == 0 && $('#playzone-replace-info').find('.girl_shards').length) {
                const rewards = $('#playzone-replace-info').find('.girl_shards').attr('data-rewards')
                const regex = /id_girl\":\d+/g;
                const found = rewards.match(regex);

                let girls1 = displayWikiGirlsNames(found);

                if (found.length > 10){
                    text = text.find('.game-rewards');
                    text.css("fontSize", "11px");
                    text.css("line-height", "13px");
                    text.css("margin-top", "61px");

                    text.append('<div class="HHMI-INFO">' + labels.available_girls + girls1 + '</div>');

                    text = text.find('.HHMI-INFO');
                    text.css("height", "52px");
                    text.css("width", "410px");
                    text.css("position", "relative");
                    text.css("top", "-96px");
                    text.css("left", "-60px");
                    text.css("text-align", "center");
                    text.css("overflow-y", "scroll");
                }

                else if (found.length > 3){
                    text = text.find('.game-rewards');
                    text.css("fontSize", "11px");
                    text.css("line-height", "15px");
                    text.css("margin-top", "55px");

                    text.append('<div class="HHMI-INFO">' + labels.available_girls + girls1 + '</div>');

                    text = text.find('.HHMI-INFO');
                    text.css("height", "60px");
                    text.css("width", "390px");
                    text.css("position", "relative");
                    text.css("top", "-90px");
                    text.css("left", "-55px");
                    text.css("text-align", "center");
                }

                else {
                    text = text.find('.game-rewards');
                    text.css("fontSize", "11.5px");
                    text.css("margin-top", "55px");

                    text.append('<div class="HHMI-INFO">' + labels.available_girls + girls1 + '</div>');

                    text = text.find('.HHMI-INFO');
                    text.css("width", "390px");
                    text.css("position", "relative");
                    text.css("top", "-85px");
                    text.css("left", "-55px");
                    text.css("text-align", "center");
                }
            }
            if (text.find('.HHMI-INFO1').length == 0 && $('#playzone-replace-info').find('.pachinko-pool-girl').length) {
                const rewards = $('#playzone-replace-info').find('.pachinko-pool-girl').attr('data-rewards')
                const regex = /id_girl\":\d+/g;
                const found = rewards.match(regex);

                let girls2 = displayHaremGirlsNames(found);

                text = text.find('.pachinko_img');
                text.css("fontSize", "11.5px");

                text.append('<div class="HHMI-INFO1">' + window.GT.design.mythic_pachinko_current_selection + ': ' + girls2 + '</div>');

                text = text.find('.HHMI-INFO1');
                text.css("width", "283px");
                text.css("position", "absolute");
                text.css("top", "9px");
                text.css("left", "48px");
                text.css("text-align", "center");
            }
        };

        const observer = new MutationObserver(callback);
        observer.observe(targetNode, config);

        function displayHaremGirlsNames(found) {
            let girls = "";
            for (let i = 0, j = found.length; i < j; i++) {
                const raw = found[i];
                const id = parseInt(raw.match(/\d+/g), 10);
                const name = localizationMap.get(id) ? localizationMap.get(id).name : 'Unknown';
                let girlName = name.replaceAll("’", "-").replaceAll("/", "-");
                if (id == 145462484) girlName = girlName.concat('-', 'Usagi');

                let element = (girlName != 'Unknown') ? '<a href="' + transformNutakuURL('/harem/' + id) + '"> ' + name + ' </a>' : name;

                if (girls != ""){
                    girls += ", " + element;
                } else {
                    girls += element;
                }
            }
            return girls;
        }

        function displayWikiGirlsNames(found) {
            let girls = "";
            for (let i = 0, j = found.length; i < j; i++){
                const raw = found[i];
                const id = parseInt(raw.match(/\d+/g), 10);
                const name = localizationMap.get(id) ? localizationMap.get(id).name : 'Unknown';
                let girlName = name.replaceAll("’", "-").replaceAll("/", "-");
                if (id == 145462484) girlName = girlName.concat('-', 'Usagi');
                let element;

                if (window.HH_UNIVERSE == 'gay' || window.HH_UNIVERSE == 'gh_nutaku' || window.HH_UNIVERSE == 'gh_eroges') {
                    element = (girlName != 'Unknown') ? '<a href="https://harem-battle.club/wiki/Gay-Harem/GH:' + name + '" target="_blank"> ' + name + ' </a>' : name;
                }
                else if (lang == 'fr' && (window.HH_UNIVERSE == 'hentai' || window.HH_UNIVERSE == 'nutaku' || window.HH_UNIVERSE == 'test_h' || window.HH_UNIVERSE == 'hh_eroges')) {
                    element = (girlName != 'Unknown') ? '<a href="http://hentaiheroes.go.yj.fr/?id=' + id + '" target="_blank"> ' + name + ' </a>' : name;
                }
                else if (window.HH_UNIVERSE == 'hentai' || window.HH_UNIVERSE == 'nutaku' || window.HH_UNIVERSE == 'test_h' || window.HH_UNIVERSE == 'hh_eroges') {
                    element = (girlName != 'Unknown') ? '<a href="https://harem-battle.club/wiki/Harem-Heroes/HH:' + girlName + '" target="_blank"> ' + name + ' </a>' : name;
                }
                else {
                    element = (girlName != 'Unknown') ? '<a href="' + transformNutakuURL('/harem/' + id) + '"> ' + name + ' </a>' : name;
                }

                if (girls != ""){
                    girls += ", " + element;
                } else {
                    girls += element;
                }
            }

            return girls;
        }
    }

    //CSS
    sheet.insertRule('#playzone-replace-info a {'
                     + 'text-decoration: none;'
                     + 'text-shadow: rgb(0, 0, 0) 1px 1px 0px, rgb(0, 0, 0) -1px 1px 0px, rgb(0, 0, 0) -1px -1px 0px, rgb(0, 0, 0) 1px -1px 0px;'
                     + 'color: #fa8072;}'
                    );

    sheet.insertRule('#playzone-replace-info .cover, #playzone-replace-info .cover .pachinko_img img {'
                     + 'height: 275px !important;}'
                    );

    sheet.insertRule('#playzone-replace-info .cover h2 {'
                     + 'top: -10px !important;}'
                    );

    sheet.insertRule('#playzone-replace-info .cover h3.shadow-text {'
                     + 'top: 193px !important;}'
                    );

    if (window.HH_UNIVERSE == 'comix_c' || window.HH_UNIVERSE == 'nutaku_c') {
        sheet.insertRule('#playzone-replace-info .cover p {'
                         + 'position: relative;'
                         + 'font-size: 14px !important;'
                         + 'top: -18px !important;}'
                        );
    }
    else {
        sheet.insertRule('#playzone-replace-info .cover p {'
                         + 'position: relative;'
                         + 'top: -10px !important;}'
                        );
    }

    sheet.insertRule('#playzone-replace-info .game-rewards {'
                     + 'margin-top: 10px;'
                     + 'height: 40px !important;}'
                    );

    sheet.insertRule('#playzone-replace-info .btns-section {'
                     + 'margin-top: 10px;}'
                    );

    sheet.insertRule('#playzone-replace-info .graduation {'
                     + 'font-size: 10px !important;}'
                    );
}

//CSS rules to improve the display of the missions
function moduleMissionsBackground() {
    sheet.insertRule('#missions .missions_wrap .mission_object.mission_entry.common {'
                     + 'background: #ffffff20;}'
                    );

    sheet.insertRule('#missions .missions_wrap .mission_object.mission_entry.rare {'
                     + 'background: #32bc4f30;}'
                    );

    sheet.insertRule('#missions .missions_wrap .mission_object.mission_entry.epic {'
                     + 'background: #ffb24440;}'
                    );

    sheet.insertRule('#missions .missions_wrap .mission_object.mission_entry.legendary {'
                     + 'background: #6ebeff40;}'
                    );
}

//CSS rule to not display the collect money animation
function moduleCollectMoneyAnimation() {
    sheet.insertRule('.collect_img {'
                     + 'display: none !important;}'
                    );
}

//Change the defaut tab in Activities to Missions
function moduleActivitiesTabChoice() {
    $('#homepage').find('[rel=activities]')[0].href = transformNutakuURL("/activities.html?tab=missions");
}

//Change items order on home screen
function moduleCustomizedHomeScreen() {
    if ($('a[rel="clubs"]').length) $('#homepage .main-container .left-side-container .quest-container').after($('a[rel="clubs"]'));
    $('#homepage .main-container .left-side-container .quest-container').after($('a[rel="sex-god-path"]'));
    $('#homepage .main-container .left-side-container .quest-container').after($('a[rel="pachinko"]'));
    $('#homepage .main-container .left-side-container .quest-container').after($('a[rel="leaderboard"]'));
    $('#homepage .main-container .left-side-container .quest-container').after($('a[rel="shop"]'));
    $('#homepage .main-container .left-side-container .quest-container').after($('a[rel="harem"]'));
    $('#homepage .main-container .left-side-container .quest-container').after($('a[rel="activities"]'));

    $('a[rel="map"] > .notif-position > span:nth-child(1) > p:nth-child(1)').after('<img class="script-home-icon" src="https://hh2.hh-content.com/pictures/design/menu/map.svg" style="left: 0px;">');
    $('a[rel="activities"] > .notif-position > span:nth-child(1) > p:nth-child(1)').after('<img class="script-home-icon" src="https://hh2.hh-content.com/design/menu/missions.svg" style="right: 0px;">');
    $('a[rel="harem"] > .notif-position > span:nth-child(1) > p:nth-child(1)').after('<img class="script-home-icon" src="https://hh2.hh-content.com/pictures/design/harem.svg" style="left: 0px;">');
    $('a[rel="shop"] > .notif-position > span:nth-child(1) > p:nth-child(1)').after('<img class="script-home-icon" src="https://hh2.hh-content.com/design/menu/shop.svg" style="right: 0px;">');
    $('a[rel="leaderboard"] > .notif-position > span:nth-child(1) > p:nth-child(1)').after('<img class="script-home-icon" src="https://hh2.hh-content.com/design/menu/leaderboard.svg" style="right: 0px;">');
    $('a[rel="pachinko"] > .notif-position > span:nth-child(1) > p:nth-child(1)').after('<img class="script-home-icon" src="https://hh2.hh-content.com/pictures/design/menu/pachinko.svg" style="right: 0px;">');
    $('a[rel="sex-god-path"] > .notif-position > span:nth-child(1) > p:nth-child(1)').after('<img class="script-home-icon" src="https://hh2.hh-content.com/design/menu/ic_champions.svg" style="left: 0px;">');
    $('a[rel="clubs"] > .notif-position > span:nth-child(1) > p:nth-child(1)').after('<img class="script-home-icon" src="https://hh2.hh-content.com/pictures/design/clubs.svg" style="right: 0px;">');

    $('.event-cards-container').append($('.mega-event'));

    //CSS
    sheet.insertRule('#homepage .main-container .left-side-container .quest-container > a > .notif-position > span, #homepage .main-container .left-side-container > a > .notif-position > span, .event-widget .event-thumbnail .bar-wrapper, #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .pov-button > a[rel="path-of-valor"] > .notif-position .pov-widget, #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-button > a > .notif-position > span, #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .pov-button > a[rel="path-of-glory"] > .notif-position .pov-widget {'
                     + 'background-color: rgba(32, 3, 7, 0.75) !important;}'
                    );

    sheet.insertRule('#homepage .bundles {'
                     + 'height: 3.3rem !important;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .bundles {'
                     + 'position: fixed;'
                     + 'bottom: 36px;'
                     + 'right: 12px;'
                     + 'width: 90px !important;'
                     + 'background-color: transparent !important;'
                     + 'border: none !important;'
                     + 'box-shadow: none !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .bundles {'
                     + 'position: fixed;'
                     + 'bottom: 30px;'
                     + 'right: 6px;'
                     + 'width: 90px !important;'
                     + 'background-color: transparent !important;'
                     + 'border: none !important;'
                     + 'box-shadow: none !important;}}'
                    );

    sheet.insertRule('#homepage .bundles .chest-img-container{'
                     + 'top: 4px;'
                     + 'left: 9px;'
                     + 'transform: scale(0.5);'
                     + 'transition-property: transform;'
                     + 'transition-duration: 250ms;'
                     + 'transition-timing-function: ease;'
                     + 'transition-delay: 0s;}'
                    );

    sheet.insertRule('#homepage .bundles .chest-img-container:hover {'
                     + 'transform: scale(0.6) !important;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .bundles .chest-container {'
                     + 'width: 85px;'
                     + 'height: 53px;'
                     + 'position: relative;'
                     + 'top: 0px;'
                     + 'right: 2px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .bundles .chest-container {'
                     + 'width: 85px;'
                     + 'height: 53px;'
                     + 'position: relative;'
                     + 'top: 0px;'
                     + 'right: -2px;}}'
                    );

    sheet.insertRule('#homepage .bundles .timer-box {'
                     + 'position: relative;'
                     + 'z-index: 1;'
                     + 'width: max-content;'
                     + 'text-shadow: 1px 1px 0 #369400,-1px 1px 0 #369400,-1px -1px 0 #369400,1px -1px 0 #369400;'
                     + 'transition-property: transform;'
                     + 'transition-duration: 250ms;'
                     + 'transition-timing-function: ease;'
                     + 'transition-delay: 0s;'
                     + 'transform: scale(0.6);}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .bundles .timer-box {'
                     + 'top: -10px;'
                     + 'left: 16px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .bundles .timer-box {'
                     + 'top: -7px;'
                     + 'left: 13px;}}'
                    );

    sheet.insertRule('#homepage #home_missions_bar2 .text {'
                     + 'text-shadow: none;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage #home_missions_bar2 .text {'
                     + 'font-size: 13px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage #collect_all {'
                     + 'height: 3.3rem !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage #collect_all {'
                     + 'height: 3.3rem !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage #collect_all_container .collect-infos {'
                     + 'margin-top: -5px;'
                     + 'font-size: 15px !important;'
                     + 'line-height: 13px !important;}}'
                    );

    sheet.insertRule('#seasons_main_container {'
                     + 'z-index: 0 !important;}'
                    );

    sheet.insertRule('.blur-effect {'
                     + 'filter: none !important;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .season-pov-container, #homepage .event-cards-container {'
                     + 'position: absolute;'
                     + 'bottom: 81px;'
                     + 'right: -8px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .season-pov-container, #homepage .event-cards-container {'
                     + 'position: absolute;'
                     + 'bottom: 81px;'
                     + 'right: -18px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .event-widget-container {'
                     + 'position: relative;'
                     + 'bottom: 128px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .event-widget-container {'
                     + 'position: relative;'
                     + 'bottom: 128px;}}'
                    );

    sheet.insertRule('#homepage .event-container .collect-button {'
                     + 'height: 3.3rem !important;'
                     + 'margin-left: 10px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .bottom-container .info-container {'
                     + 'z-index: 2;'
                     + 'position: absolute;'
                     + 'bottom: 0px;'
                     + 'right: 15px;'
                     + 'transform: scale(0.7);}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .bottom-container .info-container {'
                     + 'z-index: 2;'
                     + 'position: absolute;'
                     + 'right: 0px;'
                     + 'bottom: 2px;'
                     + 'transform: scale(0.68);}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_comix #homepage .bottom-container .info-container, #hh_star #homepage .bottom-container .info-container, #hh_startrans #homepage .bottom-container .info-container {'
                     + 'right: 45px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_comix #homepage .bottom-container .info-container, #hh_star #homepage .bottom-container .info-container, #hh_startrans #homepage .bottom-container .info-container {'
                     + 'right: 35px !important;}}'
                    );

    sheet.insertRule('#homepage #mc-selector {'
                     + 'max-width: 95px;'
                     + 'align-items: center;}'
                    );

    sheet.insertRule('#homepage #mc-selector .expired-text {'
                     + 'z-index: 1;}'
                    );

    sheet.insertRule('#homepage .main-container .middle-container .bottom-container .box-container .waifu-buttons-container {'
                     + 'position: fixed;'
                     + 'top: 450px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .main-container .middle-container .bottom-container .box-container .waifu-buttons-container {'
                     + 'right: 411px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .main-container .middle-container .bottom-container .box-container .waifu-buttons-container {'
                     + 'right: 401px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .social_links {'
                     + 'z-index: 2;'
                     + 'transform: scale(0.7);'
                     + 'margin-top: 461px;'
                     + 'margin-left: 555px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .social_links_mobile {'
                     + 'z-index: 2;'
                     + 'transform: scale(0.7);'
                     + 'margin-top: 463px !important;'
                     + 'margin-left: 600px !important;}}'
                    );

    sheet.insertRule('#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .event-widget-container .event-widget {'
                     + 'position: absolute !important;'
                     + 'width: 227px;'
                     + 'bottom: -126px;'
                     + 'margin-left: -15px;}'
                    );

    sheet.insertRule('#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .mega-event {'
                     + 'margin-left: 10px;'
                     + 'width: 230px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .main-container .left-side-container > a[rel="harem"] > .button-notification-icon {'
                     + 'top: 1px !important;}}'
                    );

    sheet.insertRule('.script-home-icon {'
                     + 'position: absolute;'
                     + 'top: 0px;'
                     + 'height: 100%;'
                     + 'max-height: 54px;'
                     + 'opacity: 0.3;}'
                    );

    sheet.insertRule('.seasons_button, #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .pov-button > a[rel="path-of-glory"] > .notif-position .pov-widget, #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .pov-button > a[rel="path-of-valor"] > .notif-position .pov-widget {'
                     + 'margin-left: 10px;}'
                    );

    sheet.insertRule('#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .pov-button > a[rel="path-of-glory"] > .notif-position .pov-widget {'
                     + 'height: 64px !important;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .main-container .middle-container .waifu-and-right-side-container .waifu-container img {'
                     + 'height: 509px !important;'
                     + 'width: 204px !important;'
                     + 'margin-left: 100px;'
                     + 'margin-top: 24px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .main-container .middle-container .waifu-and-right-side-container .waifu-container .animated-girl-display {'
                     + 'top: -15rem !important;'
                     + '-webkit-transform: translate3d(0,0,0) scale(.41) !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .main-container .middle-container .waifu-and-right-side-container .waifu-container img {'
                     + 'height: 481px !important;'
                     + 'width: 193px !important;'
                     + 'margin-left: 105px;'
                     + 'margin-top: 30px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .main-container .middle-container .waifu-and-right-side-container .waifu-container .animated-girl-display {'
                     + 'top: -19.5rem !important;'
                     + '-webkit-transform: translate3d(0,0,0) scale(.39) !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .pov-button > a > .button-notification-icon, #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-button > a > .button-notification-icon {'
                     + 'left: 221px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .pov-button > a > .button-notification-icon, #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-button > a > .button-notification-icon {'
                     + 'left: 219px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.event-widget .event-timer .button-notification-icon.button-notification-reward {'
                     + 'top: -21px;'
                     + 'right: 11px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.event-widget .event-timer .button-notification-icon.button-notification-reward {'
                     + 'top: -12px;'
                     + 'right: 7px !important;}}'
                    );

    sheet.insertRule('#homepage .promo_discount span {'
                     + 'right: 0px !important;}'
                    );

    sheet.insertRule('#homepage .main-container .left-side-container > a[rel="leaderboard"] > .notif-position .additional-menu-data > img {'
                     + 'margin-left: -3px;}'
                    );

    sheet.insertRule('#homepage .main-container .left-side-container > a[rel="leaderboard"] > .notif-position .additional-menu-data > p.league-rank {'
                     + 'margin-top: 6px;'
                     + 'margin-left: 4px;}'
                    );

    sheet.insertRule('#homepage .mega-event .button-notification-icon {'
                     + 'top: -6px !important;'
                     + 'right: -8px !important;}'
                    );
}

//Hide claimed rewards in Season, PoV, PoG, PoA, DP and mega-events
function moduleHideClaimedRewards() {
    //PoV and PoG rewards
    if(CurrentPage == "/path-of-valor.html" || CurrentPage == "/path-of-glory.html") {
        const POV_REM_PER_GROUP = 0.3 + 3.6; // margin-top + height
        const POV_PX_PER_GROUP = POV_REM_PER_GROUP * 16;
        let hidden = false;
        let $groupsToHide = $('.potions-paths-tier:not(.unclaimed):has(.claimed-slot)');
        let $groupsRemaining = $('.potions-paths-tier.unclaimed');
        let claimedCount = $groupsToHide.length;
        let unclaimedCount = $groupsRemaining.length;
        const heightPattern = /height: ?(?<existingLength>[0-9.a-z%]+);?/;
        let existingLengthStr;
        let newLength;
        const $progressBar = $('.potions-paths-progress-bar .potions-paths-progress-bar-current');
        const styleAttr = $progressBar.attr('style');

        const assertHidden = () => {
            $groupsToHide = $('.potions-paths-tier:not(.unclaimed):has(.claimed-slot)');
            $groupsRemaining = $('.potions-paths-tier.unclaimed');
            claimedCount = $groupsToHide.length;
            unclaimedCount = $groupsRemaining.length;

            if (claimedCount == 0) {
                // nothing to do
                return
            }

            $groupsToHide.addClass('script-hide-claimed');
            progressBarLength();
            hidden = true;
            if (styleAttr) $progressBar.attr('style', styleAttr.replace(heightPattern, `height:${newLength};`));
        }

        const assertShown = () => {
            $('.script-hide-claimed').removeClass('script-hide-claimed')
            hidden = false
            if (styleAttr) $progressBar.attr('style', styleAttr.replace(heightPattern, `height:${existingLengthStr};`))
        }
        
        const progressBarLength = () => {
            if (styleAttr) {
                const matches = styleAttr.match(heightPattern);
                if (matches && matches.groups) existingLengthStr = matches.groups.existingLength;
                if (existingLengthStr) {
                    newLength = existingLengthStr;
                    if (existingLengthStr.endsWith('px')) {
                        const existingLength = parseInt(existingLengthStr);
                        newLength = Math.round(existingLength - (claimedCount * POV_PX_PER_GROUP)) + 'px';
                    } else if (existingLengthStr.endsWith('rem')) {
                        const existingLength = parseFloat(existingLengthStr);
                        newLength = existingLength - (claimedCount * POV_REM_PER_GROUP) + 'rem';
                    }
                }
            }
        }

        progressBarLength();
        assertHidden();
        $('.potions-paths-progress-bar-section').stop(true).animate({
            scrollTop: Math.max(0, (unclaimedCount * POV_PX_PER_GROUP) - 150)
        }, 100)

        const toggle = () => {
            if (hidden) assertShown();
            else assertHidden();
        }

        $('.girl-preview').click(toggle);
    }

    //Season rewards
    if(CurrentPage == "/season.html") {
        const SEASON_TIER_WIDTH = 69.6;
        let hidden = false;

        const fixWidth = () => {
            const $row = $('.rewards_seasons_row');
            $row.css('width', 'max-content');
        }
        const assertHidden = (shouldScroll) => {
            const $tiers = $('.rewards_pair');
            const {season_tiers, season_has_pass, season_tier} = window;

            let unclaimedCount = 0;
            let rewardsHidden = false;

            $tiers.each((i, el) => {
                const {free_reward_picked, pass_reward_picked, tier} = season_tiers[i];
                if (free_reward_picked == '1' && (!season_has_pass || pass_reward_picked == '1')) {
                    $(el).addClass('script-hide-claimed');
                    rewardsHidden = true;
                } else if (parseInt(tier) <= season_tier) unclaimedCount++;
            })

            hidden = rewardsHidden;

            fixWidth();

            const $rowScroll = $('.rewards_container_seasons');
            $rowScroll.getNiceScroll().resize();

            if (shouldScroll) {
                const left = SEASON_TIER_WIDTH * unclaimedCount;
                $rowScroll.getNiceScroll(0).doScrollLeft(Math.max(0, left - 600), timeout);
            }
        }
        const assertShown = () => {
            $('.script-hide-claimed').removeClass('script-hide-claimed');
            hidden = false;
            fixWidth();
            const $rowScroll = $('.rewards_container_seasons');
            $rowScroll.getNiceScroll().resize();
        }

        const $rowScroll = $('.rewards_container_seasons');
        if ($rowScroll.length && $rowScroll.getNiceScroll(0).doScrollLeft) assertHidden(true);
        else {
            const observer = new MutationObserver(() => {
                const $rowScroll = $('.rewards_container_seasons');
                if ($rowScroll.length && $rowScroll.getNiceScroll(0).doScrollLeft) {
                    observer.disconnect();
                    assertHidden(true);
                }
            })
            observer.observe(document.getElementById('seasons_tab_container'), {childList: true, subtree: true});
        }

        $(document).ajaxComplete(function(evt, xhr, opt) {
            const searchParams = new URLSearchParams(opt.data)
            if(searchParams.get('action') == 'claim') {
                if(!xhr.responseText.length) return;

                const response = JSON.parse(xhr.responseText)

                if(!response || !response.success) return;

                // key is free/pass_<tier>
                const key = searchParams.get('key');

                const keyPattern = /(?<type>free|pass)_(?<tier>[0-9]+)/;
                const matches = key.match(keyPattern);

                let type, tier;

                if (matches && matches.groups) ({type, tier} = matches.groups);

                const {season_tiers} = window;

                const tierToUpdate = season_tiers.find(({tier: check})=>tier == check);

                if (tierToUpdate) tierToUpdate[`${type}_reward_picked`] = '1';

                if (hidden) assertHidden(false);
            }
        })

        const toggle = () => {
            if (hidden) assertShown();
            else assertHidden(false);
        }
        $('#girls_holder').click(toggle);
    }


    //PoA and DP events
    if(CurrentPage == "/event.html") {
        //PoA event
        if($('a.active[href*="?tab=path_event_"]').length) {
            setTimeout(function() {
                const bonusRewardsUnlocked = (!$('#nc-poa-tape-blocker').length == 1);
                const $rowScroll = $('.scroll-area.poa');
                const width_px = 75;
                
                let init = true;
                let rewards_unclaimed = 0;
                let rewards_hidden = 0;

                const assertHidden = (shouldScroll) => {
                    rewards_hidden = 0;
                    rewards_unclaimed = 0;

                    $('.nc-poa-reward-pair').each((i, el) => {
                        const $free = $(el).find('.nc-poa-free-reward');
                        const $pass = $(el).find('.nc-poa-locked-reward');
                        if ( $free.hasClass('claimed') && ( $pass.hasClass('claimed') || !bonusRewardsUnlocked)) {
                            $(el).addClass('script-hide-claimed');
                            rewards_hidden += 1;
                        }
                        if ($free.hasClass('claimable') || $pass.hasClass('claimable')) rewards_unclaimed += 1;
                    })

                    function hideClaimedRewards() {
                        let scroll_left_px = parseInt(width_px * Math.max(0, (rewards_unclaimed - 7)), 10);
                        try {$rowScroll.getNiceScroll(0).doScrollLeft(scroll_left_px, timeout);} catch(err) {}
                    }
    
                    if (shouldScroll) {
                        if (init) {
                            setTimeout(function() {
                                hideClaimedRewards();
                                init = false;
                            }, timeout);
                        }
                        else hideClaimedRewards();
                    }
                }

                const assertShown = (shouldScroll) => {
                    $('.nc-poa-reward-pair').removeClass('script-hide-claimed');

                    if (shouldScroll) {
                        let scroll_right_px = parseInt((rewards_unclaimed + rewards_hidden - 7) * width_px, 10);
                        fixScroll();
                        try {$rowScroll.getNiceScroll(0).doScrollLeft(scroll_right_px, timeout);} catch(err) {}
                    }
                }

                const fixScroll = () => {$rowScroll.getNiceScroll().resize();}

                const toggle = () => {
                    if ($('.script-hide-claimed').length) assertShown(true);
                    else assertHidden(true);
                    fixScroll();
                }

                assertHidden(true);
                $('#poa-content .girls').click(()=>{toggle()});

                //CSS
                sheet.insertRule('#events .nc-panel-body .nc-poa-reward-pair {'
                                 +'margin: 0 !important;}'
                                );
                
                fixScroll();
            }, timeout);
        }

        //DP event
        if($('a.active[href*="?tab=dp_event_"]').length) {
            setTimeout(function() {
                const bonusRewardsUnlocked = (!$('#nc-poa-tape-blocker').length == 1);
                const $rowScroll = $('.player-progression-container');
                const start_px = 40;
                const width_px = 96;
                
                let rewards_unclaimed = 0;
                let rewards_hidden = 0;
                let progress_bar_width = 0;
                let progress_bar_width_hidden = 0;
                let init = true;

                const assertHidden = (shouldScroll) => {
                    $('.tiers-progression .tier-container').each((i, el) => {
                        const $free = $(el).find('.free-slot');
                        const $pass = $(el).find('.paid-slot');

                        if ($free.hasClass('claimed') && ($pass.hasClass('claimed') || !bonusRewardsUnlocked)) $(el).addClass('script-hide-claimed');
                    })

                    rewards_unclaimed = $('button.purple_button_L.button_glow.display-block').length;
                    rewards_hidden = $('.script-hide-claimed').length;
                    progress_bar_width = parseInt(start_px + (rewards_unclaimed + rewards_hidden - 1) * width_px, 10);
                    progress_bar_width_hidden = parseInt(start_px + (rewards_unclaimed - 1) * width_px, 10);
                    $('.dp-progress-bar-current').css('width', progress_bar_width_hidden + 'px');

                    function hideClaimedRewards() {
                        let scroll_left_px = parseInt(width_px * Math.max(0, (rewards_unclaimed - 4)), 10);
                        try{$rowScroll.getNiceScroll(0).doScrollLeft(scroll_left_px, timeout);} catch(err) {}
                    }

                    if (shouldScroll) {
                        if (init) {
                            setTimeout(function() {
                                hideClaimedRewards();
                                init = false;
                            }, 4*timeout);
                            setTimeout(() => {fixScroll()}, 4.5*timeout)
                        }
                        else hideClaimedRewards();
                    }
                }

                const assertShown = (shouldScroll) => {
                    $('.tiers-progression .tier-container').removeClass('script-hide-claimed');
                    $('.dp-progress-bar-current').css('width', progress_bar_width + 'px');

                    if (shouldScroll) {
                        let scroll_right_px = parseInt((rewards_unclaimed + rewards_hidden - 4) * width_px, 10);
                        fixScroll();
                        try{$rowScroll.getNiceScroll(0).doScrollLeft(scroll_right_px, timeout);} catch(err) {}
                    }
                }

                const fixScroll = () => {$rowScroll.getNiceScroll().resize();}

                const toggle = () => {
                    if ($('.script-hide-claimed').length) assertShown(true);
                    else assertHidden(true);
                    fixScroll();
                }

                assertHidden(true);
                $('#dp-content .right-container').click(()=>{toggle()});
            }, timeout);

            //CSS
            sheet.insertRule('#dp-content .left-container .tiers-container .player-progression-container .tiers-progression .tier-container {'
                             + 'width: 3.5rem !important;}'
                            );

            sheet.insertRule('#dp-content .left-container .tiers-container {'
                             + 'width: 63rem !important;}'
                            );

            sheet.insertRule('#dp-content .left-container .tiers-container .player-progression-container, #dp-content .left-container .tiers-container .player-progression-container #nc-poa-tape-blocker {'
                             + 'z-index: 10;'
                             + 'width: 57rem !important;}'
                            );

            fixScroll();
        }
    }

    //Hero rewards
    if(CurrentPage == "/member-progression.html") {
        const HERO_TIER_WIDTH = 104;
        const start_px = 70;
        const start_scroll = 25;
        const scroll_width = 16.59;
        const scroll_width_hidden = 27;
        const $rowScroll = $('.main-container .tiers-container');

        let rewards_unclaimed = 0;
        let rewards_hidden = 0;
        let progress_bar_width = 0;
        let progress_bar_width_hidden = 0;
        let init = true;

        const assertHidden = (shouldScroll) => {
            $('.tiers-container .tiers .tier').each((i, el) => {
                if ( $(el).hasClass('claimed')) $(el).addClass('script-hide-claimed');
            })

            rewards_unclaimed = $('.tier').length - ($('.tier.available').length + $('.tier.claimed').length);
            rewards_hidden = $('.script-hide-claimed').length;
            progress_bar_width = parseInt(start_px + (rewards_unclaimed + rewards_hidden - 1) * HERO_TIER_WIDTH, 10);
            progress_bar_width_hidden = parseInt(start_px + (rewards_unclaimed - 1) * HERO_TIER_WIDTH, 10);
            $('.progress-bar-current').css('width', progress_bar_width_hidden + 'px');

            function hideClaimedRewards() {
                let left = parseInt(start_scroll + scroll_width_hidden * Math.max(0, (rewards_unclaimed - 5)), 10);
                try {$rowScroll.getNiceScroll(0).doScrollLeft(parseInt(left/13, 10)*50, timeout);} catch(err) {}
            }

            if (shouldScroll) {
                if (init) {
                    setTimeout(function() {
                        hideClaimedRewards();
                        init = false;
                    }, 4*timeout);
                    setTimeout(() => {fixScroll()}, 4.5*timeout);
                }
                else hideClaimedRewards();
            }
        }

        const assertShown = (shouldScroll) => {
            $('.tiers-container .tiers .tier').removeClass('script-hide-claimed');
            $('.progress-bar-current').css('width', progress_bar_width + 'px');

            if (shouldScroll) {
                let right = parseInt(start_scroll + (rewards_unclaimed + rewards_hidden - 5) * scroll_width, 10);
                fixScroll();
                try {$rowScroll.getNiceScroll(0).doScrollLeft(parseInt(right/8)*50, timeout);} catch(err) {}
            }
        }

        const fixScroll = () => {$rowScroll.getNiceScroll().resize();}

        const toggle = () => {
            if ($('.script-hide-claimed').length) assertShown(true);
            else assertHidden(true);
            fixScroll();
        }

        assertHidden(true);
        $('.page-girl').click(()=>{toggle()});

        //CSS
        sheet.insertRule('#ascrail2000-hr {'
                         + 'left: 33px !important;}'
                        );
    }

    //Mega-events (Lusty Race, Hot Assembly, Seasonal Event)
    if(CurrentPage == "/seasonal.html") {
        const $rowScroll = $('.mega-progress-bar-section');
        
        let init = true;

        //Lusty Race
        if ($('.mega-tiers-section .mega-tier-container.double-tier').length) {
            const bonusRewardsUnlocked = (!$('#get_mega_pass_kobans_btn').length == 1);
            const start_px = 50;
            const width_px = 77;

            const assertHidden = (shouldScroll) => {
                let rewards_unclaimed = $('.mega-claim-reward.double-claim').length;

                $('.mega-tier-container.double-tier').each((i, el) => {
                    const $free = $(el).find('.free-slot');
                    const $pass = $(el).find('.pass-slot');
                    if ($free.hasClass('claimed') && ( $pass.hasClass('paid-claimed') || !bonusRewardsUnlocked)) $(el).addClass('script-hide-claimed');
                })

                let progress_bar_width_hidden = start_px + (rewards_unclaimed - 1) * width_px
                $('.mega-progress-bar-current').css('width', progress_bar_width_hidden + 'px');

                function hideClaimedRewards() {
                    let scroll_left_px = parseInt(width_px * Math.max(0, (rewards_unclaimed - 5)), 10);
                    try {$rowScroll.getNiceScroll(0).doScrollLeft(scroll_left_px, timeout);} catch(err) {}
                }

                if (shouldScroll) {
                    if (init) {
                        setTimeout(function() {
                            hideClaimedRewards();
                            init = false;
                        }, 4*timeout);
                        setTimeout(() => {fixScroll();}, 4.5*timeout);
                    }
                    else hideClaimedRewards();
                }
            }

            const assertShown = (shouldScroll) => {
                let rewards_unclaimed = $('.mega-claim-reward.double-claim').length;
                let rewards_claimed = $('.mega-tier.free-slot.claimed.claimed-slot').length;
                $('.mega-tier-container.double-tier').removeClass('script-hide-claimed');

                let progress_bar_width = start_px + (rewards_unclaimed + rewards_claimed - 1) * width_px;
                $('.mega-progress-bar-current').css('width', progress_bar_width + 'px');

                if (shouldScroll) {
                    let scroll_right_px = parseInt((rewards_unclaimed + rewards_claimed - 3) * width_px, 10);
                    fixScroll();
                    try {$rowScroll.getNiceScroll(0).doScrollLeft(scroll_right_px, timeout);} catch(err) {}
                }
            }

            const fixScroll = () => {$rowScroll.getNiceScroll().resize();}

            const toggle = () => {
                if ($('.script-hide-claimed').length) assertShown(true);
                else assertHidden(true);
                fixScroll();
            }

            assertHidden(true);
            $('#home_tab_container .girls-reward-container').click(()=>{toggle()});

            //CSS
            sheet.insertRule('.mega-event-panel .mega-event-container .tabs-section #home_tab_container .bottom-container .right-part-container .mega-tiers-section .mega-progress-bar-section .mega-progress-bar-tiers .double-tier {'
                             + 'width: ' + width_px + 'px !important;}'
                            );
        }
        //Seasonal event and Hot Assembly
        else {
            const width_px_Tweaks = 104.03;
            const start_px_Tweaks = 52;
            const width_px = 92;
            const start_px = 70;

            let rewards_unclaimed = 0;
            let rewards_hidden = 0;
            let scroll_width = 0;
            let scroll_width_hidden = 0;
            let init = true;

            const assertHidden = (shouldScroll) => {
                $('.mega-tier-container').each((i, el) => {
                    const $reward = $(el).find('.mega-tier');
                    if ($reward.hasClass('claimed')) $(el).addClass('script-hide-claimed');
                })

                $rowScroll.getNiceScroll().resize();

                rewards_unclaimed = $('.mega-tier').length - ($('.mega-tier.available').length + $('.mega-tier.claimed').length);
                rewards_hidden = $('.script-hide-claimed').length;

                if (!localStorage.getItem('HHPlusPlusConfig')) {
                    scroll_width = parseInt(start_px + (rewards_unclaimed + rewards_hidden - 1) * width_px, 10);
                    scroll_width_hidden = parseInt(start_px + (rewards_unclaimed - 1) * width_px, 10);

                    //CSS
                    sheet.insertRule('.mega-event-panel .mega-event-container .tabs-section #home_tab_container .bottom-container .right-part-container .mega-tiers-section .mega-progress-bar-section .mega-progress-bar-tiers .mega-tier-container {'
                                     + 'width: ' + width_px + 'px !important;}'
                                    );
                }
                else {
                    if (JSON.parse(localStorage.getItem('HHPlusPlusConfig')).st_seasonalEventTweaks) {
                        scroll_width = parseInt(start_px_Tweaks + (rewards_unclaimed + rewards_hidden - 1) * width_px_Tweaks, 10);
                        scroll_width_hidden = parseInt(start_px_Tweaks + (rewards_unclaimed - 1) * width_px_Tweaks, 10);
                    }
                    else {
                        scroll_width = parseInt(start_px + (rewards_unclaimed + rewards_hidden - 1) * width_px, 10);
                        scroll_width_hidden = parseInt(start_px + (rewards_unclaimed - 1) * width_px, 10);

                        //CSS
                        sheet.insertRule('.mega-event-panel .mega-event-container .tabs-section #home_tab_container .bottom-container .right-part-container .mega-tiers-section .mega-progress-bar-section .mega-progress-bar-tiers .mega-tier-container {'
                                         + 'width: ' + width_px + 'px !important;}'
                                        );
                    }
                }
                $('.mega-progress-bar-current').css('width', scroll_width_hidden + 'px');

                function hideClaimedRewards() {
                    let left = 0;
                    if (!localStorage.getItem('HHPlusPlusConfig'))
                        left = parseInt(width_px * Math.max(0, (rewards_unclaimed - 3)), 10);
                    else {
                        if (JSON.parse(localStorage.getItem('HHPlusPlusConfig')).st_seasonalEventTweaks)
                            left = parseInt(width_px_Tweaks * Math.max(0, (rewards_unclaimed - 4)), 10);
                        else left = parseInt(width_px * Math.max(0, (rewards_unclaimed - 4)), 10);
                    }
                    try {$rowScroll.getNiceScroll(0).doScrollLeft(left, timeout);} catch(err) {}
                }

                if (shouldScroll) {
                    if (init) {
                        setTimeout(function() {
                            hideClaimedRewards();
                            init = false;
                        }, 4*timeout);
                        setTimeout(() => {fixScroll();}, 4.5*timeout);
                    }
                    else hideClaimedRewards();
                }
            }

            const assertShown = (shouldScroll) => {
                $('.mega-tier-container').removeClass('script-hide-claimed');

                $('.mega-progress-bar-current').css('width', scroll_width + 'px');

                if (shouldScroll) {
                    let right = 0;
                    if (!localStorage.getItem('HHPlusPlusConfig'))
                        right = parseInt((rewards_unclaimed + rewards_hidden - 4) * width_px, 10);
                    else {
                        if (JSON.parse(localStorage.getItem('HHPlusPlusConfig')).st_seasonalEventTweaks)
                            right = parseInt((rewards_unclaimed + rewards_hidden - 4) * width_px_Tweaks, 10);
                        else right = parseInt((rewards_unclaimed + rewards_hidden - 4) * width_px, 10);
                    }
                    fixScroll();
                    try {$rowScroll.getNiceScroll(0).doScrollLeft(right, timeout);} catch(err) {}
                }
            }

            const fixScroll = () => {$rowScroll.getNiceScroll().resize();}

            const toggle = () => {
                if ($('.script-hide-claimed').length) assertShown(true);
                else assertHidden(true);
                fixScroll();
            }

            assertHidden(true);
            $('#home_tab_container .girls-reward-container').click(()=>{toggle()});
        }
    }
}

//Force desktop display on mobile
function moduleDesktopDisplay() {
    setTimeout(function() {
        let viewport = document.querySelector("meta[name=viewport]");
        viewport.setAttribute('content', 'width=1026px, user-scalable=0');

        if (CurrentPage.includes('event')) {
            $('#events .scroll-area').css('overflow', 'auto');
            $('#events .scroll-area').css('touch-action', '');
            $('#dp-content .left-container .tiers-container .player-progression-container').css('overflow-x', 'auto');
            $('#dp-content .left-container .tiers-container .player-progression-container').css('touch-action', '');
        }

        else if (CurrentPage.includes('shop')) {
            $('#tabs-switcher .market-menu-switch-tab[type="armor"]')[0].addEventListener("click", function() {
                setTimeout(function() {
                    $('#player-inventory.armor').css('overflow', 'auto');
                    $('#player-inventory.armor').css('touch-action', '');
                }, timeout);
            }, {once: false});

            $('#tabs-switcher .market-menu-switch-tab[type="booster"]')[0].addEventListener("click", function() {
                setTimeout(function() {
                    $('#player-inventory.booster').css('overflow', 'auto');
                    $('#player-inventory.booster').css('touch-action', '');
                }, timeout);
            }, {once: false});

            $('#tabs-switcher .market-menu-switch-tab[type="potion"]')[0].addEventListener("click", function() {
                setTimeout(function() {
                    $('#player-inventory.potion').css('overflow', 'auto');
                    $('#player-inventory.potion').css('touch-action', '');
                }, timeout);
            }, {once: false});

            $('#tabs-switcher .market-menu-switch-tab[type="gift"]')[0].addEventListener("click", function() {
                setTimeout(function() {
                    $('#player-inventory.gift').css('overflow', 'auto');
                    $('#player-inventory.gift').css('touch-action', '');
                }, timeout);
            }, {once: false});
        }

        else if (CurrentPage.includes('girl')) {
            if (window.location.search.includes('experience')) {
                $('#experience .inventory').css('overflow', 'auto');
                $('#experience .inventory').css('touch-action', '');

                $('#gifts_tab')[0].addEventListener("click", function() {
                    setTimeout(function() {
                        $('#affection .inventory').css('overflow', 'auto');
                        $('#affection .inventory').css('touch-action', '');
                    }, timeout);
                }, {once: true});
            }
            else {
                $('#affection .inventory').css('overflow', 'auto');
                $('#affection .inventory').css('touch-action', '');

                $('#books_tab')[0].addEventListener("click", function() {
                    setTimeout(function() {
                        $('#experience .inventory').css('overflow', 'auto');
                        $('#experience .inventory').css('touch-action', '');
                    }, timeout);
                }, {once: true});
            }
        }

        else if (CurrentPage.includes('seasonal')) {
            $('.seasonal-progress-bar-section').css('overflow', 'auto');
            $('.seasonal-progress-bar-section').css('touch-action', '');
        }

        else if (CurrentPage.includes('activities')) {
            $('#missions .missions_wrap').css('overflow', 'auto');
            $('#missions .missions_wrap').css('touch-action', '');
        }

        else if (CurrentPage.includes('member-progression')) {
            $('.tiers-container').css('overflow', 'auto');
            $('.tiers-container').css('touch-action', '');
        }
    }, timeout)
}

//Hide Claim All button in season, PoV and PoG
function moduleHideClaimAllButtons() {
    if(CurrentPage == "/season.html" || CurrentPage == "/path-of-valor.html" || CurrentPage == "/path-of-glory.html" || CurrentPage == "/member-progression.html") {
        sheet.insertRule('button#claim-all {'
                         + 'display: none !important;}'
                        );
    }
}

function moduleHideMultipleLeagueBattlesButton() {
    $('.league_buttons_block').remove();
}

function moduleEventEndIndicator() {
    const THRESHOLD = 24*60*60;

    annotateEventWidget();
    annotatePathEvents();
    annotateSeasonalWidget();

    function annotateEventWidget () {
        const $eventTimers = $('.event-widget .timer')

        $eventTimers.each((i, el) => {
            const $el = $(el);
            const timeleft = $el.data('timeStamp');
            const link = $el.parent().parent().attr('href')

            if (timeleft < THRESHOLD && link != "#") {
                $el.find('p').addClass('script-event-ending-soon');
            }
            else if (timeleft < THRESHOLD && link == "#") {
                $el.find('p').addClass('script-event-starting-soon');
            }
        })
    }

    function annotateSeasonalWidget () {
        const $eventTimers = $('.mega-event .timer')

        $eventTimers.each((i, el) => {
            const $el = $(el);
            const timeleft = $el.data('timeStamp');

            if (timeleft < THRESHOLD) {
                $el.find('p').addClass('script-ending-soon');
            }
        })
    }

    function annotatePathEvents () {
        ['Pov', 'Pog', 'Season'].forEach(type => annotatePathEvent(type));
    }

    function annotatePathEvent (type) {
        const endTime = localStorage.getItem('HHS.' + type + 'Time');
        const {server_now_ts} = window;

        if (endTime && endTime > server_now_ts && endTime - THRESHOLD < server_now_ts) {
            $('#script' + type + 'Time').addClass('script-ending-soon')
        }
    }

    //CSS
    sheet.insertRule('.script-ending-soon {'
                     + 'animation-name: pulsing-seasons-and-path;'
                     + 'animation-duration: 4s;'
                     + 'animation-iteration-count: infinite;}'
                    );

    sheet.insertRule('.script-event-ending-soon {'
                     + 'animation-name: pulsing-events;'
                     + 'animation-duration: 4s;'
                     + 'animation-iteration-count: infinite;}'
                    );

    sheet.insertRule('.script-event-starting-soon {'
                     + 'animation-name: pulsing-starting-events;'
                     + 'animation-duration: 4s;'
                     + 'animation-iteration-count: infinite;}'
                    );

    sheet.insertRule('@keyframes pulsing-events {'
                     + '0% {opacity: 0.8; background-color: rgba(32, 3, 7, 0); color: red;}'
                     + '50% {opacity: 1; background-color: rgba(255, 0, 0, 0.8); color: #8ec3ff;}'
                     + '100% {opacity: 0.8; background-color: rgba(32, 3, 7, 0); color: red;}}'
                    );

    sheet.insertRule('@keyframes pulsing-starting-events {'
                     + '0% {opacity: 0.8; background-color: rgba(32, 3, 7, 0); color: green;}'
                     + '50% {opacity: 1; background-color: rgba(0, 180, 0, 0.8); color: #8ec3ff;}'
                     + '100% {opacity: 0.8; background-color: rgba(32, 3, 7, 0); color: green;}}'
                    );

    sheet.insertRule('@keyframes pulsing-seasons-and-path {'
                     + '0% {opacity: 1; background-color: rgba(32, 3, 7, 0); color: red;}'
                     + '50% {opacity: 1; background-color: rgba(255, 0, 0, 0.8); color: white;}'
                     + '100% {opacity: 1; background-color: rgba(32, 3, 7, 0); color: red;}}'
                    );
}

//Remove confirmation popup window in Pachinko
function moduleRemovePachinkoPopup() {
    class OverriddenPachinkoConfirm {
        constructor(name, options, callback) {
            this.name = name
            this.isConfirm = true
            callback()
            setTimeout(() => {
                window.HHPopupManager.closeLastOpenedPopup()
            }, 1)
        }

        show () {
            // NO-OP
        }

        open () {
            // NO-OP
        }

        close () {
            delete window.HHPopupManager.listOpenedPopups[this.name]
        }
    }

    const removePopup = () => {
        if (window.HHPachinkoConfirm) {
            window.HHPachinkoConfirm = OverriddenPachinkoConfirm;
        } else {
            setTimeout(removePopup, 100);
        }
    }
    removePopup();
}

//Add contests expiration timer in Activities
function moduleContestsExpiryTimer() {
    if (!window.contests.finished) return;

    function displayExpiryTimer() {
        window.contests.finished.forEach(function(contest) {
            let days = Math.floor(21-(parseInt(contest.remaining_time.toString().substring(1))+4200)/3600/24);
            let hours = Math.floor((21-((parseInt(contest.remaining_time.toString().substring(1))+4200)/3600/24) - days) * 24);
            let minutes = Math.floor((((21-((parseInt(contest.remaining_time.toString().substring(1))+4200)/3600/24) - days) * 24) - hours) * 60);

            if (days == 0) $('#contests .contest[id_contest=' + contest.id_contest + ']').children('.contest_header').append('<div class="contest_expiration_timer">' + window.GT.design.expires_in + " : " + hours + labels.hour + " " + minutes + labels.minute + '</div>');
            else $('#contests .contest[id_contest=' + contest.id_contest + ']').children('.contest_header').append('<div class="contest_expiration_timer">' + window.GT.design.expires_in + " : " + days + labels.day + " " + hours + labels.hour + '</div>');
        })
    }

    displayExpiryTimer();
    new MutationObserver(() => {displayExpiryTimer()}).observe($('#contests')[0], {childList: true})

    //CSS
    sheet.insertRule('.contest_expiration_timer {'
                     + 'position: relative;'
                     + 'z-index: 100;'
                     + 'bottom: 107px;'
                     + 'left: 11px;'
                     + 'font-size: 14px;}'
                    );
}

//Stop background switching during Orgy Days event (Credit: Finderkeeper)
function stopOrgyBackgroundSwithcing() {
    if ($("body[ page ]").attr("page") != "map") {
        $("#bg_all").replaceWith( $("#bg_all").clone() );
        $("#bg_all > div > img").not($("#bg_all > div > img")[Math.floor(Math.random()*$("#bg_all > div > img").length)]).remove();
        $("#bg_all > div > img").css("opacity","1");
        $("#bg_all > div > img").css("display","block");
    }
}

//Get data for girls already got
function getHaremGirlsData() {
    if ($('.harem-girl-container').length){
        if (!(localStorage.getItem('HHS.HHPNMap') == null || localStorage.getItem('HHS.HHPNMap') == undefined)) {
            if(JSON.parse(localStorage.getItem('HHS.HHPNMap'))[0].length == 2) localStorage.removeItem('HHS.HHPNMap');
        }

        let girlsData = CurrentPage.includes('waifu') ? window.girlsDataList : window.availableGirls;
        let girlNameDictionary = new Map();

        for (let i = 0; i < girlsData.length; i++) {
            let girl_data = {Affection: {cur: 0},
                            Xp: {cur: 0},
                            awakening_level: 0,
                            avatar: null,
                            class: null,
                            element: null,
                            figure: null,
                            graded: null,
                            id_girl: null,
                            level: null,
                            name: null,
                            nb_grades: null,
                            rarity: null,
                            salary: null,
                            salary_per_hour: null}

            girl_data.Affection.cur = girlsData[i].Affection.cur;
            girl_data.Xp.cur = girlsData[i].Xp.cur;
            girl_data.awakening_level = girlsData[i].awakening_level;
            girl_data.avatar = girlsData[i].avatar.charAt(girlsData[i].avatar.indexOf('ava') + 3)
            girl_data.class = girlsData[i].class;
            girl_data.element = girlsData[i].element;
            girl_data.figure = girlsData[i].figure;
            girl_data.graded = girlsData[i].graded;
            girl_data.id_girl = parseInt(girlsData[i].id_girl, 10);
            girl_data.level = girlsData[i].level;
            girl_data.name = girlsData[i].name;
            girl_data.nb_grades = girlsData[i].nb_grades;
            girl_data.rarity = girlsData[i].rarity;
            girl_data.salary = girlsData[i].salary;
            girl_data.salary_per_hour = girlsData[i].salary_per_hour;

            girlNameDictionary.set(girl_data.id_girl, girl_data);
        }
        if (girlNameDictionary.size > 0){
            let json = JSON.stringify(Array.from(girlNameDictionary.entries()));
            localStorage.setItem('HHS.HHPNMap', json);
        }
    }
}

function getNonHaremGirlsData() {
    const girlShardsDictionary = (!localStorage.getItem('HHS.HHPNShardsMap')) ? new Map(): new Map(JSON.parse(localStorage.getItem('HHS.HHPNShardsMap')));

    new MutationObserver(() => {
        if ($('#harem_left .girls_list .harem-girl').length > 0) {
            for (let i = 0; i < $('#harem_left .girls_list .harem-girl').length; i++) {
                let girl_id = parseInt($($('#harem_left .girls_list .harem-girl')[i]).attr('girl'), 10);
                let girl_shards = girlsDataList[girl_id].shards || 0;
                let girl_name = girlsDataList[girl_id].name;
                if (girl_shards < 100) {
                    let girlData = {id_girl: girl_id,
                                    name: girl_name,
                                    shards: girl_shards}
                    girlShardsDictionary.set(girl_id, girlData);
                }
            }
            localStorage.setItem('HHS.HHPNShardsMap', JSON.stringify(Array.from(girlShardsDictionary.entries())));
        }
    }).observe($('#harem_left .girls_list')[0], {childList: true})
}

//Display the number of shards for girls
function displayGirlsShards() {
    if (CurrentPage.indexOf('troll-') != -1 || CurrentPage.indexOf('clubs') != -1 || CurrentPage.indexOf('pachinko') != -1 || CurrentPage.indexOf('season-') != -1 || CurrentPage.indexOf('leagues') != -1 || CurrentPage.indexOf('labyrinth') != -1) {
        const girlShardsDictionary = (!localStorage.getItem('HHS.HHPNShardsMap')) ? new Map(): new Map(JSON.parse(localStorage.getItem('HHS.HHPNShardsMap')));

        if (CurrentPage.indexOf('troll-pre-battle') != -1 || CurrentPage.indexOf('pachinko') != -1 || CurrentPage.indexOf('season-arena') != -1) {
            displayTrollGirlsShards();
            updateTrollGirlsShards();
        }
        else if (CurrentPage.indexOf('clubs') != -1) {
            displayClubChampionGirlsShards();
            setTimeout(updateClubChampionGirlsShards(), 2000);
        }
        else if (CurrentPage.indexOf('troll-battle') != -1 || CurrentPage.indexOf('season-battle') != -1 || CurrentPage.indexOf('leagues') != -1 || CurrentPage.indexOf('labyrinth') != -1) {
            updateTrollGirlsShards();
        }

        function displayTrollGirlsShards() {
            if(($($('.slot.girl_ico')[0]).attr('data-rewards')) && (CurrentPage.indexOf('troll-pre-battle') != -1)) {
                let girlsData = JSON.parse($($('.slot.girl_ico')[0]).attr('data-rewards'));
                for (let i=0; i < girlsData.length; i++) {
                    let girlId = girlsData[i].id_girl;
                    if (!girlId) return;
                    let shards = girlShardsDictionary.get(girlId) ? girlShardsDictionary.get(girlId).shards : 0;
                    let name = girlShardsDictionary.get(girlId) ? girlShardsDictionary.get(girlId).name : '';
                    $($($('.slot.girl_ico')[0]).find('.girl_ico')[i]).append('<div class="shards_troll" shards="' + shards + '" name="' + name + '">'
                                                                             + '<span class="shard_troll"></span>'
                                                                             + '<p id="shard_number">' + shards + '</p>'
                                                                             + '</div>');

                    sheet.insertRule('.page-troll-pre-battle #shard_number {'
                                     + 'position: absolute;'
                                     + 'bottom: -0.25em;'
                                     + 'left: -4px;'
                                     + 'color: #80058b;'
                                     + 'text-shadow: 1px 1px 0 #fff,-1px 1px 0 #fff,-1px -1px 0 #fff,1px -1px 0 #fff;'
                                     + 'width: 28px;'
                                     + 'text-align: right;'
                                     + 'font-size: 11px !important;}'
                                    );

                    sheet.insertRule('.page-troll-pre-battle .shards_troll .shard_troll {'
                                     + 'background-image: url("' + window.IMAGES_URL + '/shards.png");'
                                     + 'background-repeat: no-repeat;'
                                     + 'background-size: contain;'
                                     + 'position: absolute;'
                                     + 'bottom: -4px;'
                                     + 'margin-left: -1px;'
                                     + 'width: 20px;'
                                     + 'height: 20px;}'
                                    );

                    if (girlsData.length > 1) {
                        sheet.insertRule('.page-troll-pre-battle #shard_number, .page-troll-pre-battle .shards_troll .shard_troll {'
                                         + 'margin-left: 0px;'
                                         + 'margin-bottom: 2px;}'
                                        );
                    }
                    else {
                        sheet.insertRule('.page-troll-pre-battle #shard_number, .page-troll-pre-battle .shards_troll .shard_troll {'
                                         + 'margin-left: 0px;'
                                         + 'margin-bottom: 2px;}'
                                        );
                    }
                }
            }
            else if (($($('.slot.girl_ico')[0]).attr('data-rewards')) && ((window.location.href.indexOf('league-battle') != -1) || (CurrentPage.indexOf('season-arena') != -1))) {
                $('.slot.girl_ico').find('.slot_girl_shards .shards').remove();
                for (let i=0; i < $('.slot.girl_ico').length; i++) {
                    let girlId = JSON.parse($($('.slot.girl_ico')[i]).attr('data-rewards'))[0].id_girl;
                    let shards = girlShardsDictionary.get(girlId) ? girlShardsDictionary.get(girlId).shards : 0;
                    let name = girlShardsDictionary.get(girlId) ? girlShardsDictionary.get(girlId).name : '';
                    $($('.slot.girl_ico').find('.slot_girl_shards .shards')[i]).remove();
                    $($('.slot.girl_ico').find('.slot_girl_shards')[i]).append('<div class="shards_troll" shards="' + shards + '" name="' + name + '">'
                                                                                + '<span class="shard_troll" style="background-image: url(' + window.IMAGES_URL + '/shards.png); background-repeat: no-repeat; background-size: contain; position: absolute; margin-left: -31px; width: 20px; height: 20px;"></span>'
                                                                                + '<p id="shard_number">' + shards + '</p></div>');

                    //CSS
                    sheet.insertRule('.page-troll-pre-battle #shard_number {'
                                     + 'position: absolute;'
                                     + 'bottom: -0.25em;'
                                     + 'left: -5px;'
                                     + 'color: #80058b;'
                                     + 'text-shadow: 1px 1px 0 #fff,-1px 1px 0 #fff,-1px -1px 0 #fff,1px -1px 0 #fff;'
                                     + 'width: 28px;'
                                     + 'text-align: right;'
                                     + 'margin-top: -14px;'
                                     + 'font-size: 12px;}'
                                    );

                    sheet.insertRule('.page-season_arena #shard_number {'
                                     + 'position: absolute;'
                                     + 'bottom: -15px;'
                                     + 'color: #80058b;'
                                     + 'text-shadow: 1px 1px 0 #fff,-1px 1px 0 #fff,-1px -1px 0 #fff,1px -1px 0 #fff;'
                                     + 'width: 24px;'
                                     + 'text-align: right;'
                                     + 'margin-left: -24px;'
                                     + 'font-size: 11px;}'
                                    );
                }
            }

            let observer = new MutationObserver(function(mutations) {
                mutations.forEach(function(mutation) {
                    if ($('.hh_tooltip_new .slot.girl_ico').length == 0) return;

                    else if(($($('.hh_tooltip_new .slot.girl_ico')[0]).find('.girl_ico .shards_troll')).length != 0) return;

                    else {
                        if ($($('.hh_tooltip_new .slot.girl_ico .girl_ico img')[0]).attr('src').indexOf('girls/') == -1) return;

                        else {
                            for (let i=0; i < $('.hh_tooltip_new .slot.girl_ico').length; i++) {
                                let idGirlStr = $($('.hh_tooltip_new .slot.girl_ico img')[i]).attr('src');
                                let indexStart = idGirlStr.indexOf('girls/') + 'girls/'.length;
                                let indexEnd = idGirlStr.indexOf('/ico');
                                let girlId = parseInt(idGirlStr.substring(indexStart, indexEnd), 10);
                                let shards = girlShardsDictionary.get(girlId) ? girlShardsDictionary.get(girlId).shards : 0;
                                let name = girlShardsDictionary.get(girlId) ? girlShardsDictionary.get(girlId).name : '';
                                $($('.hh_tooltip_new .slot.girl_ico .girl_ico .shards_troll')[i]).remove();
                                $($('.hh_tooltip_new .slot.girl_ico .girl_ico')[i]).append('<div class="shards_troll" shards="' + shards + '" name="' + name + '">'
                                                                                           + '<span class="shard_troll_tooltip" style="background-image: url(' + window.IMAGES_URL + '/shards.png); background-repeat: no-repeat; background-size: contain; position: absolute; bottom: -0.25em; top: 24px; margin-left: 2px; width: 15px; height: 15px;"></span>'
                                                                                           + '<p id="shard_number_tooltip" style="position: absolute; bottom: -1px; padding-left: 10px; color: #80058b; text-shadow: 1px 1px 0 #fff,-1px 1px 0 #fff,-1px -1px 0 #fff,1px -1px 0 #fff; width: 28px; text-align: right; margin-left: -6px; font-size: 9px;">'
                                                                                           + '<span>' + shards + '</span>'
                                                                                           + '</p></div>');
                            }

                            sheet.insertRule('#hh_comix .hh_tooltip_new .slot.girl_ico .girl_ico {'
                                             + 'font-weight : bold !important;}'
                                            );
                        }
                    }
                })
            })

            let observer1 = new MutationObserver(function(mutations) {
                mutations.forEach(function(mutation) {
                    if ($('.hh_tooltip_new .slot .girl_ico').length == 0) return;

                    else if(($($('.hh_tooltip_new .slot')[0]).find('.girl_ico .shards_troll')).length != 0) return;

                    else {
                        if ($($('.hh_tooltip_new .slot .girl_ico img')[0]).attr('src').indexOf('girls/') == -1) return;

                        else {
                            for (let i=0; i < $('.hh_tooltip_new .slot').length; i++) {
                                let idGirlStr = $($('.hh_tooltip_new .slot img')[i]).attr('src');
                                let indexStart = idGirlStr.indexOf('girls/') + 'girls/'.length;
                                let indexEnd = idGirlStr.indexOf('/ico');
                                let girlId = parseInt(idGirlStr.substring(indexStart, indexEnd), 10);
                                let shards = girlShardsDictionary.get(girlId) ? girlShardsDictionary.get(girlId).shards : 0;
                                let name = girlShardsDictionary.get(girlId) ? girlShardsDictionary.get(girlId).name : '';
                                $($('.hh_tooltip_new .slot .girl_ico .shards_troll')[i]).remove();
                                $($('.hh_tooltip_new .slot .girl_ico')[i]).append('<div class="shards_troll" shards="' + shards + '" name="' + name + '">'
                                                                                  + '<span class="shard_troll_tooltip" style="background-image: url(' + window.IMAGES_URL + '/shards.png); background-repeat: no-repeat; background-size: contain; position: absolute; bottom: -0.25em; top: 27px; margin-left: 2px; width: 15px; height: 15px;"></span>'
                                                                                  + '<p id="shard_number_tooltip" style="position: absolute; bottom: -0.25em; padding-left: 10px; color: #80058b; text-shadow: 1px 1px 0 #fff,-1px 1px 0 #fff,-1px -1px 0 #fff,1px -1px 0 #fff; width: 28px; text-align: right; margin-top: -10px; margin-left: -6px; font-size: 9px;">'
                                                                                  + '<span>' + shards + '</span>'
                                                                                  + '</p></div>');
                            }

                            sheet.insertRule('#hh_comix .hh_tooltip_new .slot .girl_ico {'
                                             + 'font-weight : bold !important;}'
                                            );
                        }
                    }
                })
            })

            if (CurrentPage.indexOf('troll-pre-battle') != -1) observer.observe($('.page-troll-pre-battle')[0], {childList: true, subtree: true, attributes: false});
            else if (CurrentPage.indexOf('pachinko') != -1) observer1.observe($('.page-pachinko')[0], {childList: true, subtree: true, attributes: false});
        }

        function displayClubChampionGirlsShards() {
            if ($('#club_champions_tab').length == 0) return;

            let clubChampionTab = document.querySelector('#club_champions_tab');
            clubChampionTab.addEventListener('click', function(){
                if(!$('.girl-shards-reward-wrapper').length) return;

                let girls = $('.girl-shards-reward-wrapper');
                for (let i=0; i < girls.length; i++) {
                    let idGirlStr = $('.girl-shards-reward-wrapper:nth-child(' + (i+1) + ') .slot.slot_girl_shards img').attr('src');
                    let indexStart = idGirlStr.indexOf('girls/') + 'girls/'.length;
                    let indexEnd = idGirlStr.indexOf('/ico');
                    let girlId = parseInt(idGirlStr.substring(indexStart, indexEnd), 10);

                    let shards = girlShardsDictionary.get(girlId) ? girlShardsDictionary.get(girlId).shards : 0;
                    let name = girlShardsDictionary.get(girlId) ? girlShardsDictionary.get(girlId).name : '';
                    $('.girl-shards-reward-wrapper:nth-child(' + (i+1) + ') .slot.slot_girl_shards').append('<div class="club_shards" shards="' + shards + '" name="' + name + '">'
                                                                                                            + '<p id="club_shard_number" style="position: absolute; bottom: 14px; padding-left: 10px; color: #80058b; text-shadow: 1px 1px 0 #fff,-1px 1px 0 #fff,-1px -1px 0 #fff,1px -1px 0 #fff;; width: 28px; text-align: right; margin-left: -46px; font-size: 12px;">'
                                                                                                            + '<span>' + shards + '</span>'
                                                                                                            + '<span class="club_shard" style="background-image: url(' + window.IMAGES_URL + '/shards.png); background-repeat: no-repeat; background-size: contain; display: block; position: relative; bottom: 1.75em; margin-left: 15px; width: 25px; height: 25px;"></span>'
                                                                                                            + '</p></div>');
                }
            })
        }

        function updateTrollGirlsShards() {
            $(document).ajaxComplete(function(evt, xhr, opt) {
                if(!opt.data) return;

                if(~opt.data.search(/action=do_battles_(league|seasons|trolls)/i)) {
                    if(!xhr.responseText.length) return;

                    const response = JSON.parse(xhr.responseText);

                    if(!response || !response.success) return;

                    if(!response.rewards.lose) {
                        if(response.rewards.data.shards) {
                            response.rewards.data.shards.forEach(function(shard) {
                                let idGirl = shard.id_girl;
                                let name = shard.name;
                                let newShards = shard.value;
                                let girlData = {id_girl: idGirl,
                                                name: name,
                                                shards: Math.min(newShards, 100)}
                                if (newShards >= 100) girlShardsDictionary.delete(idGirl);
                                else girlShardsDictionary.set(idGirl, girlData);
                            });
                            localStorage.setItem('HHS.HHPNShardsMap', JSON.stringify(Array.from(girlShardsDictionary.entries())));
                        }
                        else return;
                    }
                }
            })
        }

        function updateClubChampionGirlsShards() {
            if ($('.shards_wrapper').length == 0) return;

            for (let i=2; i <= $('.shards_wrapper')[0].children.length; i++) {
                let idGirlStr = $('.slot_girl_shards:nth-child(' + i + ') img').attr('src');
                let indexStart = idGirlStr.indexOf('girls/') + 'girls/'.length;
                let indexEnd = idGirlStr.indexOf('/ico');
                let idGirl = parseInt(idGirlStr.substring(indexStart, indexEnd), 10);
                let name = $('.slot_girl_shards:nth-child(' + i + ') .shards').attr('name');
                let newShards = parseInt($('.slot_girl_shards:nth-child(' + i + ') .shards').attr('shards'), 10);
                let girlData = {id_girl: idGirl,
                                name: name,
                                shards: Math.min(newShards, 100)}
                if (newShards >= 100) girlShardsDictionary.delete(idGirl);
                else girlShardsDictionary.set(idGirl, girlData);
            }
            localStorage.setItem('HHS.HHPNShardsMap', JSON.stringify(Array.from(girlShardsDictionary.entries())));

            $('.club_shards').remove();
            displayClubChampionGirlsShards();
        }
    }
}

//Remove button to access to club champion's positions during cooldown + add some datas about participation of club members
function moduleClubChampionFeatures() {
    if ($('#club_champions_tab').length == 0) return;

    function highlightMembersParticipation() {
        let clubMembers = window.members_list;
        let championPartipants = window.club_champion_data.fight.participants;
        let listChampionParticipantsId = [];
        championPartipants.forEach((participant) => {
            listChampionParticipantsId.push(participant.id_member);
        });
        clubMembers.forEach((member) => {
            if (!listChampionParticipantsId.includes(member.id_member)) {
                Array.from($('#club_members #members .body-row .avatar')).find((el) => $(el).attr('id-member') == member.id_member).parentElement.parentElement.style.color = '#ffa07a';
            }
        });
    }

    let clubChampionTab = document.querySelector('#club_champions_tab');
    clubChampionTab.addEventListener('click', () => {
        if ($('.club_champions_details_container').length) {
            $('button.orange_button_L.btn_skip_team_cooldown').css('display', 'none');
            if (!$('button.orange_button_L.btn_skip_champion_cooldown').length) {
                $('.challenge_container').css('display', 'block');
            }

            let participants = window.club_champion_data.fight.participants;
            let participants_number = participants.length;
            let club_members = window.members_list.length ;

            function calculateParticipation() {
                let championImpress = localeStringToNumber((JSON.parse($('.club_champions_bar_container').attr('champion-healing-tooltip')).impression_info).split('/')[1]);
                let list = $('#club_champions .club-champion-members-challenges .body-row .data-column:nth-child(4) .impression');
                for (let i=0; i<list.length; i++) {
                    let impress = localeStringToNumber($(list[i]).attr('tooltip'));
                    if (impress <= 0) {
                        participants_number--;
                    }
                }
                for (let i=0; i<list.length; i++) {
                    let impress = Math.max(0, localeStringToNumber($(list[i]).attr('tooltip')));
                    let percentage = Math.floor((impress/championImpress)*10000)/100;
                    let shards = Math.ceil(percentage - 0.501) + Math.round(0.6 * Math.sqrt(parseInt(participants_number, 10)));
                    let textImpress = '' + nThousand(localeStringToNumber($($($('.club-champion-members-challenges .body-row')[i]).find('.data-column:nth-child(4) .impression')[0]).attr('tooltip').trim()));

                    let newTextImpress = textImpress.concat(' / ', nThousand(percentage), '%');
                    $($('#club_champions .club-champion-members-challenges .body-row')[i]).find('.data-column:nth-child(4)').empty();
                    $($('#club_champions .club-champion-members-challenges .body-row')[i]).find('.data-column:nth-child(4)').append('<div>' + newTextImpress + '</div>');
                    $($('#club_champions .club-champion-members-challenges .body-row')[i]).find('.data-column:nth-child(4)').append('<div>' + shards + ' <span class="shard"></span></div>');

                    if ($($('#club_champions .club-champion-members-challenges .body-row')[i]).attr('class') == "data-row body-row player-row" && $('.slot_girl_shards .shards p span').length == 2) {
                        $('.slot_girl_shards .shards p span')[0].innerText = parseInt($('.slot_girl_shards .shards p span')[0].innerText, 10) != 100 ? shards : $('.slot_girl_shards .shards p span')[0].innerText;
                        $('.slot_girl_shards .shards p span')[1].innerText = parseInt($('.slot_girl_shards .shards p span')[1].innerText, 10) != 100 ? shards : $('.slot_girl_shards .shards p span')[1].innerText;
                    }
                }
            }

            calculateParticipation();
            addTimeSinceStart();
            fixTimerBar();

            let sortImpression = document.querySelector('.club-champion-members-challenges .head-row .head-column[column=challenge_impression_done]');
            sortImpression.addEventListener('click', function(){
                calculateParticipation();
            });

            let sortChallenges = document.querySelector('.club-champion-members-challenges .head-row .head-column[column=challenge_count]');
            sortChallenges.addEventListener('click', function(){
                calculateParticipation();
            });

            let sortName = document.querySelector('.club-champion-members-challenges .head-row .head-column[column=nickname]');
            sortName.addEventListener('click', function(){
                calculateParticipation();
            });

            let sortLevel = document.querySelector('.club-champion-members-challenges .head-row .head-column[column=level]');
            sortLevel.addEventListener('click', function(){
                calculateParticipation();
            });

            function addTimeSinceStart () {
                const $timerFight = $('.club_champions_timer_fight');
                if (!$timerFight.length || !window.club_champion_data.fight.active) {
                    return;
                }

                const duration = calculateTime(window.club_champion_data.fight.start_time * 1e3, window.server_now_ts * 1e3);

                const durationString = `${duration.daysLeft > 0 ? `${duration.daysLeft}${window.GT.time.d} ` : ''}${duration.hoursLeft > 0 ? `${duration.hoursLeft}${window.GT.time.h} ` : ''}${duration.minutesLeft > 0 ? `${duration.minutesLeft}${window.GT.time.m}` : ''}`.trim();

                $('.club_champions_impression').append(`<span class="club_champion_start">${label('clubChampDuration').replace('{{duration}}', durationString)}</span>`);
            }

            function fixTimerBar () {
                const $clubChampionsBar = $('.club_champions_bar');
                // Fix silly code putting a localised decimal separator as a CSS rule value
                $clubChampionsBar.attr('style', $clubChampionsBar.attr('style').replace(',','.'));
            }

            $('#club_champions .club-champion-members-challenges').prepend('<div class="club-members-participants">Participants: ' + participants_number + ' / ' + club_members + '</div>');

            //CSS
            sheet.insertRule('.club-champion-members-challenges .body-row .data-column:nth-child(4) {'
                             + 'display: flex !important;'
                             + 'flex-direction: column;'
                             + 'line-height: 1.2;'
                             + 'font-size: 0.9rem;}'
                            );

            sheet.insertRule('.club-champion-members-challenges .data-list .data-row .data-column:nth-child(4) {'
                             + 'width: 11rem !important;}'
                            );

            sheet.insertRule('.club-champion-members-challenges .data-list .data-row .data-column:nth-child(3) {'
                             + 'text-align: center;}'
                            );

            sheet.insertRule('.shard {'
                             + 'height: 1rem;'
                             + 'width: 1rem;'
                             + 'display: inline-block;'
                             + 'background-size: 140%;'
                             + 'background-position: center;}'
                            );

            sheet.insertRule('.club_champion_start {'
                             + 'display: flex;'
                             + 'color: #24a0ff;'
                             + 'letter-spacing: 1px;'
                             + 'justify-content: center;'
                             + 'font-size: 12px;}'
                            );

            sheet.insertRule('.club-wrapper > .club-container .club_champions_details_container .club_champions_impression {'
                             + 'width: 92% !important;}'
                            );

            sheet.insertRule('.club_champions_timer_fight {'
                             + 'margin-left: -5px;'
                             + 'width: 104%;}'
                            );

            sheet.insertRule('#club_champions .club-champion-members-challenges .club-members-participants {'
                             + 'display: block;'
                             + 'position: absolute;'
                             + 'left: 500px;}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#club_champions .club-champion-members-challenges .club-members-participants {'
                             + 'top: 15px;}}'
                            );

            sheet.insertRule(`${mediaDesktop} {`
                             + '#club_champions .club-champion-members-challenges .club-members-participants {'
                             + 'top: 25px;}}'
                            );
        }
    });

    highlightMembersParticipation();
    clubMembersTabHighlight();

    let clubMembersTab = document.querySelector('#club-tabs #club_members_tab');
    clubMembersTab.addEventListener('click', function(){
        highlightMembersParticipation();
        clubMembersTabHighlight();
    });

    function clubMembersTabHighlight() {
        let sortClubLevel = document.querySelector('#members .head-row .head-column[column=level]');
        sortClubLevel.addEventListener('click', function(){
            highlightMembersParticipation();
        });
        let sortClubNames = document.querySelector('#members .head-row .head-column[column=nickname]');
        sortClubNames.addEventListener('click', function(){
            highlightMembersParticipation();
        });
        let sortClubGirls = document.querySelector('#members .head-row .head-column[column=count_girls]');
        sortClubGirls.addEventListener('click', function(){
            highlightMembersParticipation();
        });
        let sortClubMojo = document.querySelector('#members .head-row .head-column[column=mojo]');
        sortClubMojo.addEventListener('click', function(){
            highlightMembersParticipation();
        });
        let sortClubContribution = document.querySelector('#members .head-row .head-column[column=contribution_points]');
        sortClubContribution.addEventListener('click', function(){
            highlightMembersParticipation();
        });
    }
}

// Show final values when skipping battle
function skipBattleValues() {
    setTimeout(function() {
        $('#new-battle-skip-btn').show();
    }, timeout);

    $(document).ajaxComplete(function(evt, xhr, opt) {
        if(~opt.data.search(/action=do_battles_(league|seasons|trolls|pantheon|boss_bang)/i)) {
            if(!xhr.responseText.length) return;

            let respBattleData = JSON.parse(xhr.responseText);

            if(!respBattleData || !respBattleData.success) return;

            //We already spent some combativity, let's show this to the player:
            if(~location.pathname.indexOf("troll-battle") && ~location.search.search(/number_of_battles=\d+/i)) {
                let nBattlesCount = parseInt(location.search.match(/number_of_battles=(\d+)/i)[1]);
                if($.isNumeric(nBattlesCount)) {
                    window.Hero.update("energy_fight", -1 * nBattlesCount, true);
                }
            }

            if(!respBattleData.rounds) return;

            let arrRounds = respBattleData.rounds;
            let rewards = respBattleData.rewards;

            let nPlayerInitialEgo = $('.new-battle-player .new-battle-hero-ego-value').data("total-ego");
            let nOpponentInitialEgo = $('.new-battle-opponent .new-battle-hero-ego-value').data("total-ego");
            let nPlayerFinalEgo = 0;
            let nOpponentFinalEgo = 0;

            let nRoundsLen = arrRounds.length;
            if(nRoundsLen >= 2) {
                let arrLastRounds = [arrRounds[nRoundsLen - 2], arrRounds[nRoundsLen - 1]];
                if(!arrLastRounds[1].opponent_hit) {
                    nPlayerFinalEgo = arrLastRounds[0].opponent_hit.defender.remaining_ego;
                    nOpponentFinalEgo = arrLastRounds[1].hero_hit.defender.remaining_ego;
                }
                else if(!arrLastRounds[1].hero_hit) {
                    nPlayerFinalEgo = arrLastRounds[1].opponent_hit.defender.remaining_ego;
                    nOpponentFinalEgo = arrLastRounds[0].hero_hit.defender.remaining_ego;
                }
                else {
                    nPlayerFinalEgo = arrRounds[nRoundsLen - 1].opponent_hit.defender.remaining_ego;
                    nOpponentFinalEgo = arrRounds[nRoundsLen - 1].hero_hit.defender.remaining_ego;
                }
            }
            else {
                if(nRoundsLen == 1) {
                    if(!arrRounds[0].opponent_hit) {
                        nPlayerFinalEgo = nPlayerInitialEgo;
                        nOpponentFinalEgo = arrRounds[0].hero_hit.defender.remaining_ego;
                    }
                    else if(!arrRounds[0].hero_hit) {
                        nPlayerFinalEgo = arrRounds[0].opponent_hit.defender.remaining_ego;
                        nOpponentFinalEgo = nOpponentInitialEgo;
                    }
                    else {
                        nPlayerFinalEgo = arrRounds[0].opponent_hit.defender.remaining_ego;
                        nOpponentFinalEgo = arrRounds[0].hero_hit.defender.remaining_ego;
                    }
                }
                else {
                    throw new Error("incorrect amount of rounds");
                }
            }

            $('#new-battle-skip-btn').off("click");
            $('#new-battle-skip-btn').on("click", function() {
                $(this).remove();
                //newBattles.battleEnd();

                let $playerBar = $('.new-battle-player .new-battle-hero-ego-initial-bar');
                let $playerDamageBar = $('.new-battle-player .new-battle-hero-ego-damage-bar');
                let $playerHealBar = $('.new-battle-player .new-battle-hero-ego-heal-bar');
                let $opponentBar = $('.new-battle-opponent .new-battle-hero-ego-initial-bar');
                let $opponentDamageBar = $('.new-battle-opponent .new-battle-hero-ego-damage-bar');
                let $opponentHealBar = $('.new-battle-opponent .new-battle-hero-ego-heal-bar');

                let $playerEgo = $('.new-battle-player .new-battle-hero-ego-value');
                let $opponentEgo = $('.new-battle-opponent .new-battle-hero-ego-value');
                let $playerDamageDone = $('.new-battle-opponent .new-battle-hero-damage-taken-text');
                let $opponentDamageDone = $('.new-battle-player .new-battle-hero-damage-taken-text');
                let $criticalDamageIndicator = $('.new-battle-hero-container .new-battle-hero-critical-text');

                $playerDamageDone.css('opacity', '0');
                $opponentDamageDone.css('opacity', '0');
                $criticalDamageIndicator.css('opacity', '0');
                $playerHealBar.css('opacity', '0');
                $opponentHealBar.css('opacity', '0');

                let strPlayerCurEgo = $playerEgo.text().split(window.GT.ego)[1].replace(/[, ]/g, "");
                let nPlayerCurEgo = nPlayerInitialEgo;
                if($.isNumeric(strPlayerCurEgo)) {
                    nPlayerCurEgo = parseInt(strPlayerCurEgo);
                }
                let strOpponentCurEgo = $opponentEgo.text().split(window.GT.ego)[1].replace(/[, ]/g, "");
                let nOpponentCurEgo = nOpponentInitialEgo;
                if($.isNumeric(strOpponentCurEgo)) {
                    nOpponentCurEgo = parseInt(strOpponentCurEgo);
                }

                let nPlayerCompleteAtk = nOpponentCurEgo - nOpponentFinalEgo;
                let nOpponentCompleteAtk = nPlayerCurEgo - nPlayerFinalEgo;
                $playerDamageDone.text(nPlayerCompleteAtk.toString());
                $opponentDamageDone.text(nOpponentCompleteAtk.toString());

                let fPlayerEgoBarWidth = nPlayerFinalEgo <= 0 ? 0 : nPlayerFinalEgo / nPlayerInitialEgo * 100.0;
                let fOpponentEgoBarWidth = nOpponentFinalEgo <= 0 ? 0 : nOpponentFinalEgo / nOpponentInitialEgo * 100.0;

                let arrPlayerAnimationSequence = [
                    { e: $playerBar, p: { width: fPlayerEgoBarWidth.toFixed(2) + "%" }, o: { duration: 200 } },
                    { e: $playerDamageBar, p: { width: fPlayerEgoBarWidth.toFixed(2) + "%" }, o: { duration: 200 } },
                    { e: $playerDamageDone, p: { opacity: [0, 1], translateY: -20, translateZ: 0 }, o: {
                        duration: 300,
                        sequenceQueue: false,
                        complete: function(elm) {
                            $playerEgo.text(window.GT.ego + " " + nThousand(Math.ceil(nPlayerFinalEgo)));
                            $(elm).velocity({ translateY: 0 }, 0)
                        }
                    }
                    }
                ];
                let arrOpponentAnimationSequence = [
                    { e: $opponentBar, p: { width: fOpponentEgoBarWidth.toFixed(2) + "%" }, o: { duration: 200 } },
                    { e: $opponentDamageBar, p: { width: fOpponentEgoBarWidth.toFixed(2) + "%" }, o: { duration: 200 } },
                    { e: $opponentDamageDone, p: { opacity: [0, 1], translateY: -20, translateZ: 0 }, o: {
                        duration: 300,
                        sequenceQueue: false,
                        complete: function(elm) {
                            $opponentEgo.text(window.GT.ego + " " + nThousand(Math.ceil(nOpponentFinalEgo)));
                            $(elm).velocity({ translateY: 0 }, 0)
                        }
                    }
                    }
                ];

                $('.velocity-animating').velocity("stop", true);
                $.Velocity.RunSequence(arrPlayerAnimationSequence);
                $.Velocity.RunSequence(arrOpponentAnimationSequence);
                setTimeout(function() {window.Reward.handlePopup(rewards)}, 800);
            });
        }
    });
}

//Fix a bug with decimal separator in daily goals
function fixDailyGoalsBug() {
    for(let i = 0; i < $('#daily_goals .objective-progress-bar-fill').length; i++){
        $('#daily_goals .objective-progress-bar-fill')[i].attributes.style.value = $('#daily_goals .objective-progress-bar-fill')[i].attributes.style.value.replace(',', '.');
    }
}

//Sort daily missions by duration
function sortDailyMissions() {
    const compare = (asc) => (row1, row2) => {
        const missionDuration = row => parseInt(JSON.parse(row.attributes['data-d'].value).duration, 10)
        const tri = (v1, v2) => v1 - v2;
        return tri(missionDuration(asc ? row1 : row2), missionDuration(asc ? row2 : row1));
    };

    let missions = Array.from(document.querySelectorAll('.mission_object:not(.legendary)')).sort(compare(true));
    missions.forEach(tr => document.querySelector('.missions_wrap').appendChild(tr));
}

//Display a notification on home screen when Sultry Mysteries event's shop is refreshed
function notifySultryMysteriesShopRefresh() {
    if(CurrentPage == "/event.html") {
        if(!$('a.active[href*="?tab=sm_event_"]').length) return;

        const observer = new MutationObserver(() => {
            if(!$('#shop_tab.underline-tab').length) return;

            setTimeout(function(){
                let sm_shop_timer = parseInt($('#shop_tab_container .shop-timer.timer').attr('data-time-stamp'), 10);
                localStorage.setItem('HHS.sm_shop_timer', window.server_now_ts + sm_shop_timer);
            }, 1000);
        })
        observer.observe($('#shop_tab')[0], {attributes: true, attributeFilter: ['class']});
    }

    if(CurrentPage == "/home.html") {
        if(!localStorage.getItem('HHS.sm_shop_timer') && $($('.event-widget .event-thumbnail .bar-wrapper .over[rel="sm_event"]')).attr('href') != "#") {
            $('.event-widget .event-thumbnail .event-timer.bar-wrapper .over[rel="sm_event"]').append('<span class="button-notification-icon expired_notification_icn" style="top: 0px;right: 229px;"></span>')
            return;
        }

        else if(window.server_now_ts >= localStorage.getItem('HHS.sm_shop_timer') && $($('.event-widget .event-thumbnail .bar-wrapper .over[rel="sm_event"]')).attr('href') != "#") {
            $('.event-widget .event-thumbnail .event-timer.bar-wrapper .over[rel="sm_event"]').append('<span class="button-notification-icon expired_notification_icn" style="top: 0px;right: 229px;"></span>');
            return;
        }

        else if(localStorage.getItem('HHS.sm_shop_timer') == NaN && $($('.event-widget .event-thumbnail .bar-wrapper .over[rel="sm_event"]')).attr('href') != "#") {
            $('.event-widget .event-thumbnail .event-timer.bar-wrapper .over[rel="sm_event"]').append('<span class="button-notification-icon expired_notification_icn" style="top: 0px;right: 229px;"></span>');
            return;
        }
    }
}

//Fix girl stats tooltip position
function fixGirlStatsTooltipPosition() {
    new MutationObserver(() => {
        if (parseInt($('.hh_tooltip_new.new_girl_tooltip').css('top'), 10) < 0 || parseInt($('.hh_tooltip_new.new_girl_tooltip').css('top'), 10) > 360) {
            $('.hh_tooltip_new.new_girl_tooltip').css('top', 0)
        }
    }).observe(document.body, {childList: true});

    //Girl tooltip in event widget
    sheet.insertRule('#events .nc-event-reward-container .nc-event-reward-info {'
                     + 'z-index: 10 !important;'
                     + 'top: -4px !important;'
                     + 'left: 0rem !important;}'
                    );
}

function fixSeasonDisplay() {
    $('#seasons_tab_sub_title')[0].childNodes[0].remove();
}

//Display stats screen instead of girls screen
function fixProfilePopup() {
    const default_hero_page_popup = window.hero_page_popup
    window.hero_page_popup = (info) => {
        if (info && !info.page) {
            info.page = 'profile'
        }
        return default_hero_page_popup(info)
    }
}

//CSS rules to optimize display and fix some bugs
function fixCSSIssues() {
    sheet.insertRule(`${mediaMobile} {`
                     + '#fight_energy_bar .energy_counter_bar .energy_counter_icon .hudBattlePts_mix_icn {'
                     + 'left: 14px;}}'
                    );

    sheet.insertRule('.rotate_device {'
                     + 'display: none !important;}'
                    );

    //Hide claimed rewards
    sheet.insertRule('.script-hide-claimed {'
                     + 'display: none !important;}'
                    );
    

    //White border in market
    sheet.insertRule('#shops .slot {'
                     + 'border: none;}'
                    );

    //Club table
    sheet.insertRule('.club_dashboard .members_requests_tables table thead th:nth-child(1) {'
                     + 'width: 13% !important;}'
                    );

    sheet.insertRule('.club_dashboard .members_requests_tables table tbody tr td:nth-child(1) {'
                     + 'width: 9% !important;}'
                    );

    sheet.insertRule('.club_dashboard .members_requests_tables table thead th:nth-child(2) {'
                     + 'width: 0% !important;}'
                    );

    sheet.insertRule('.club_dashboard .members_requests_tables table thead th:nth-child(3) {'
                     + 'width: 29% !important;}'
                    );

    sheet.insertRule('.club_dashboard .members_requests_tables table tbody tr td:nth-child(3) {'
                     + 'width: 31% !important;}'
                    );

    sheet.insertRule('.club_dashboard .members_requests_tables table thead th:nth-child(4), .club_dashboard .members_requests_tables table tbody tr td:nth-child(4) {'
                     + 'width: 15% !important;}'
                    );

    sheet.insertRule('.club_dashboard .members_requests_tables table thead th:nth-child(5), .club_dashboard .members_requests_tables table tbody tr td:nth-child(5) {'
                     + 'width: 16% !important;}'
                    );

    sheet.insertRule('.club_dashboard .members_requests_tables table thead th:nth-child(6), .club_dashboard .members_requests_tables table tbody tr td:nth-child(6) {'
                     + 'width: 21% !important;}'
                    );

    //Good position on wrong place for champions
    sheet.insertRule(`${mediaMobile} {`
                     + '.girl-box__draggable .green-tick-icon.empty {'
                     + '-webkit-mask: url("' + window.IMAGES_URL + '/design/ic_tick_white.svg") no-repeat 50% 50%;'
                     + '-webkit-mask-size: contain;'
                     + 'background-image: none;'
                     + 'background-color: snow !important;}}'
                    );

    sheet.insertRule('#hh_comix #harem_left .girls_list.grid_view div[girl] .right .salary .loading .over.count {'
                     + 'font-weight: bold;}'
                    );

    //Season
    sheet.insertRule(`${mediaMobile} {`
                     + '#season-arena .rewards_list .slot_victory_points .amount, #season-arena .rewards_list .slot_season_xp_girl .amount, #season-arena .rewards_list .slot_season_affection_girl .amount {'
                     + 'font-size: 14px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#season-arena .player_team_block.opponent .opponent_rewards .rewards_list .slot.slot_victory_points .victory_points_icn {'
                     + 'width: 45% !important;'
                     + 'height: 45% !important;'
                     + 'left: 27% !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.team-hexagon-container .team-hexagon {'
                     + 'margin-top: -15px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#season-arena .opponents_arena .opponents_choose_text_container {'
                     + 'margin-top: -6px;}}'
                    );

    sheet.insertRule('.season_xp_girl span:nth-child(1), .season_affection_girl span:nth-child(1) {'
                     + 'display: none;}'
                    );

    //Move Claim all button in season
    sheet.insertRule('#seasons_tab_container #claim-all {'
                     + 'position: absolute;'
                     + 'top: 22px;}'
                    );

    //Skip button on battle screen
    sheet.insertRule('#new-battle-skip-btn {'
                     + 'position: absolute !important;'
                     + 'max-width: 7rem !important;'
                     + 'right: -57px;'
                     + 'top: 422px !important;}'
                    );

    sheet.insertRule('.page-troll-battle #popups #rewards_popup .flex-container button, .page-troll-pre-battle #popups #rewards_popup .flex-container button, .page-activities #popups #rewards_popup .flex-container button, .page-season-battle #popups #rewards_popup .flex-container button, .page-league-battle #popups #rewards_popup .flex-container button, .page-labyrinth-battle #popups #rewards_popup .flex-container button {'
                     + 'position: absolute !important;'
                     + 'right: 435px !important;'
                     + 'top: 493px !important;}'
                    );
    
    sheet.insertRule('.page-champions .section__preview-characters .skip-button {'
                     + 'right: 460px !important;}'
                    );

    //Girls display on battle screen
    sheet.insertRule('#new_battle .new-battle-girl-container, #new_battle .new-battle-girl-container {'
                     + 'z-index: -1;}'
                    );

    sheet.insertRule('.new-battle-girl-container .new-battle-image.js-displayed-girl {'
                     + 'width: 164px !important;}'
                    );

    //PoP buttons
    sheet.insertRule('#pop .pop_list .pop-action-btn {'
                     + 'font-size: 11px;}'
                    );

    sheet.insertRule('#pop .pop_list .pop-action-btn .pop-auto-asign-all, #pop .pop_list .pop-action-btn .pop-claim-all {'
                     + 'line-height: 16px;'
                     + 'height: 51px;'
                     + 'min-width: 50px !important;}'
                    );

    //Team display
    sheet.insertRule(`${mediaMobile} {`
                     + '#season-arena .player-team, #teams .player-team {'
                     + 'margin-top: 7px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#season-arena .player-team, #teams .player-team {'
                     + 'margin-top: -10px !important;}}'
                    );

    //CSS rules to fix the rewards display in path of valor
    sheet.insertRule('.potions-paths-background-panel {'
                     + 'z-index: 1;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai #pov_tab_container .potions-paths-title-panel {'
                     + 'transform: scale(0.5);'
                     + 'position: relative;'
                     + 'top: -37px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai #pov_tab_container .potions-paths-title-panel {'
                     + 'transform: scale(0.5);'
                     + 'position: relative;'
                     + 'top: -37px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai #pov_tab_container .potions-paths-next-milestone-panel {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: 15px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai #pov_tab_container .potions-paths-next-milestone-panel {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: 0px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai #pov_tab_container .potions-paths-objective {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: -22px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai #pov_tab_container .potions-paths-objective {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: -22px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai #pov_tab_container .potions-paths-progress-bar-section {'
                     + 'overflow-x: hidden;'
                     + 'margin-top: -63px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai #pov_tab_container .potions-paths-progress-bar-section {'
                     + 'margin-top: -63px !important;}}'
                    );

    sheet.insertRule('.pov-gradient-panel {'
                     + 'z-index: 1;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai .pov-title-panel {'
                     + 'transform: scale(0.5);'
                     + 'position: relative;'
                     + 'top: -78px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai .pov-title-panel {'
                     + 'transform: scale(0.5);'
                     + 'position: relative;'
                     + 'top: -82px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai .pov-next-milestone-panel {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: 15px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai .pov-next-milestone-panel {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: 0px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai .pov-objective {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: -22px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai .pov-objective {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: -22px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai .pov-progress-bar-section {'
                     + 'overflow-x: hidden;'
                     + 'margin-top: -104px !important;'
                     + 'margin-left: 17px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai .pov-progress-bar-section {'
                     + 'margin-top: -104px !important;}}'
                    );

    sheet.insertRule('#hh_hentai #pov_tab_container .potions-paths-first-row .timer-box, #hh_hentai #pog_tab_container .potions-paths-first-row .timer-box, #hh_hentai #pov_tab_container .potions-paths-first-row .potions-paths-potions, #hh_hentai #pog_tab_container .potions-paths-first-row .potions-paths-potions {'
                     + 'background-color: rgba(39,5,43,0.7) !important;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai #pov_tab_container .girl-preview > img {'
                     + 'margin-top: -152px !important;'
                     + 'height: 171% !important;}}'
                    );

   sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai #pov_tab_container .girl-preview > img {'
                     + 'margin-top: -152px !important;'
                     + 'height: 164% !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_comix .pov-title-panel {'
                     + 'transform: scale(0.5);'
                     + 'position: relative;'
                     + 'top: -34px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_comix .pov-title-panel {'
                     + 'transform: scale(0.5);'
                     + 'position: relative;'
                     + 'top: -74px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_comix .pov-next-milestone-panel {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: -4px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_comix .pov-next-milestone-panel {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: -4px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_comix .pov-objective {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: -22px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_comix .pov-objective {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: -22px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_comix .pov-progress-bar-section {'
                     + 'margin-top: -98px !important;'
                     + 'margin-left: 13px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_comix .pov-progress-bar-section {'
                     + 'margin-top: -58px !important;}}'
                    );

    setTimeout(() => {
        if ($('#pov_tab_container .potions-paths-next-milestone-panel .potions-paths-tier ').length > 0) {
            sheet.insertRule(`${mediaDesktop} {`
                             + '#hh_hentai #pov_tab_container .potions-paths-progress-bar-section {'
                             + 'height: 286px  !important;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#hh_hentai #pov_tab_container .potions-paths-progress-bar-section {'
                             + 'height: 271px  !important;}}'
                            );
        }
        else {
            sheet.insertRule(`${mediaDesktop} {`
                             + '#hh_hentai #pov_tab_container .potions-paths-progress-bar-section {'
                             + 'height: 362px  !important;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#hh_hentai #pov_tab_container .potions-paths-progress-bar-section {'
                             + 'height: 348px  !important;}}'
                            );
        }

        if ($('.pov-next-milestone-panel .pov-tier ').length > 0) {
            sheet.insertRule(`${mediaDesktop} {`
                             + '#hh_hentai .pov-progress-bar-section {'
                             + 'height: 326px  !important;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#hh_hentai .pov-progress-bar-section {'
                             + 'height: 307px  !important;}}'
                            );
        }
        else {
            sheet.insertRule(`${mediaDesktop} {`
                             + '#hh_hentai .pov-progress-bar-section {'
                             + 'height: 403px  !important;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#hh_hentai .pov-progress-bar-section {'
                             + 'height: 384px  !important;}}'
                            );
        }

        if ($('.pov-next-milestone-panel .pov-tier ').length > 0) {
            sheet.insertRule(`${mediaDesktop} {`
                             + '#hh_comix .pov-progress-bar-section {'
                             + 'height: 301px  !important;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#hh_comix .pov-progress-bar-section {'
                             + 'height: 261px  !important;}}'
                            );
        }
        else {
            sheet.insertRule(`${mediaDesktop} {`
                             + '#hh_comix .pov-progress-bar-section {'
                             + 'height: 378px  !important;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#hh_comix .pov-progress-bar-section {'
                             + 'height: 338px  !important;}}'
                            );
        }
    }, timeout)

    //CSS rules to fix the rewards display in path of glory
    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai #pog_tab_container .potions-paths-title-panel {'
                     + 'transform: scale(0.5);'
                     + 'position: relative;'
                     + 'top: -37px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai #pog_tab_container .potions-paths-title-panel {'
                     + 'transform: scale(0.5);'
                     + 'position: relative;'
                     + 'top: -37px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai #pog_tab_container .potions-paths-next-milestone-panel {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: 15px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai #pog_tab_container .potions-paths-next-milestone-panel {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: 0px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai #pog_tab_container .potions-paths-objective {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: -22px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai #pog_tab_container .potions-paths-objective {'
                     + 'transform: scale(0.8);'
                     + 'margin-top: -22px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai #pog_tab_container .potions-paths-progress-bar-section {'
                     + 'overflow-x: hidden;'
                     + 'margin-top: -63px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai #pog_tab_container .potions-paths-progress-bar-section {'
                     + 'margin-top: -63px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_hentai #pog_tab_container .girl-preview > img {'
                     + 'margin-top: -152px !important;'
                     + 'height: 171% !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_hentai #pog_tab_container .girl-preview > img {'
                     + 'margin-top: -152px !important;'
                     + 'height: 164% !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                    + '#hh_hentai #pog_tab_container .potions-paths-background-panel .potions-paths-first-row .potions-paths-title-panel h1 {'
                    + 'margin-top: 0.5rem !important;'
                    + 'font-size: 1.5rem !important;}}'
                   );

    setTimeout(() => {
        if ($('#pog_tab_container .potions-paths-next-milestone-panel .potions-paths-tier ').length > 0) {
            sheet.insertRule(`${mediaDesktop} {`
                             + '#hh_hentai #pog_tab_container .potions-paths-progress-bar-section {'
                             + 'height: 285px  !important;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#hh_hentai #pog_tab_container .potions-paths-progress-bar-section {'
                             + 'height: 270px  !important;}}'
                            );
        }
        else {
            sheet.insertRule(`${mediaDesktop} {`
                             + '#hh_hentai #pog_tab_container .potions-paths-progress-bar-section {'
                             + 'height: 338px  !important;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#hh_hentai #pog_tab_container .potions-paths-progress-bar-section {'
                             + 'height: 347px  !important;}}'
                            );
        }
    }, timeout)

    //CSS to remove scrollbars for every mission description
    $('#missions > div .missions_wrap .mission_object .mission_details').css('overflow-y', 'hidden');

    sheet.insertRule('#shops .stack_num {'
                     + 'width: 3.2rem !important;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#daily_goals .daily-goals-row .daily-goals-left-part .daily-goals-objectives-container {'
                     + 'z-index: 10;}'
                    );

    //CSS to fix money and kobans display on mobile
    sheet.insertRule(`${mediaMobile} {`
                     + 'body > div > header > div.currency div[hero="soft_currency"], body > div > header > div.currency div[hero="hard_currency"] {'
                     + 'left: 29px !important;}}'
                    );

    //CSS to fix rewards display for club champion
    sheet.insertRule('.club_champions_rewards_container .slot.size_large {'
                     + 'max-height: 4.5rem;'
                     + 'max-width: 4.5rem;}'
                    );

    //Hero level rewards window
    sheet.insertRule('#member-progression-container .content-header {'
                     + 'margin-top: 18px;}'
                    );
                    
    sheet.insertRule(`${mediaMobile} {`
                     + '.page-member-progression .member-progression-container .tiers-container #pass_holder {'
                     + 'margin-bottom: -40px;}}'
                    );

    //Domination synergy popup
    sheet.insertRule('#domination_synergy_popup {'
                     + 'top : 10px !important;}'
                    );

    sheet.insertRule('@media only screen and (max-width: 1025px) and (orientation: landscape) {'
                     + '#domination_synergy_popup {'
                     + 'transform: scale(1) !important;'
                     + 'height: max-content !important;'
                     + 'width : 100% !important;}}'
                    );

    sheet.insertRule('@media only screen and (max-width: 1025px) and (orientation: portrait) {'
                     + '#domination_synergy_popup .crit-bonus .crit-bonus-description {'
                     + 'right : -20px !important;}}'
                    );

    sheet.insertRule('@media only screen and (max-width: 1025px) and (orientation: landscape) {'
                     + '#domination_synergy_popup .impact-ego-bonus .impact-ego-bonus-description {'
                     + 'margin-right : 40px !important;}}'
                    );

    sheet.insertRule('#domination_synergy_popup .impact-ego-bonus .impact-ego-bonus-description > p {'
                     + 'margin-left : 0px !important;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#domination_synergy_popup .crit-bonus .crit-bonus-description {'
                     + 'right: 30px !important;}}'
                    );

    //Champions display
    sheet.insertRule('.champions-over__girl-image {'
                     + 'bottom: -50px !important;'
                     + 'right: 280px !important;}'
                    );

    //Mythic event widget
    sheet.insertRule('#events .nc-event-container.mythic_event .shards-info {'
                     + 'left: 32.8rem !important;'
                     + 'bottom: -2rem !important;'
                     + 'min-width: 26rem !important;}'
                    );

    sheet.insertRule('#events .nc-events-prize-locations-container .shards-info p {'
                     + 'font-size: 14px !important;}'
                    );

    sheet.insertRule('#events .nc-events-prize-locations-container .prize-locations-infos-container .nc-events-prize-locations-info {'
                     + 'text-align: center !important;'
                     + 'font-size: 14px !important;}'
                    );

    sheet.insertRule('#events .nc-events-prize-locations-container .prize-locations-infos-container .nc-events-prize-locations-info .girl-name {'
                     + 'max-width: 500px !important;}'
                    );

    sheet.insertRule('#events .nc-events-prize-locations-container .prize-locations-infos-container {'
                     + 'margin-left: -4rem;}'
                    );

    sheet.insertRule('#events .nc-events-prize-locations-container .prize-locations-infos-container .nc-events-prize-locations-info .girl-name.highlight {'
                     + 'text-align: center;}'
                    );

    sheet.insertRule('#events .nc-events-prize-locations-container .shards-progress-bar-container .shards_bar_wrapper p span {'
                     + 'top: -0.6rem !important;'
                     + 'font-size: 14px !important;}'
                    );

    //Mega-event widget
    sheet.insertRule('.mega-event-panel .mega-event-container .overlayed-section .mega-timer {'
                     + 'max-width: 115px;'
                     + 'text-align: right;}'
                    );

    sheet.insertRule('.mega-event-panel .mega-event-container .tabs-section #home_tab_container .bottom-container .left-part-container .player-shards {'
                     + 'background: linear-gradient(to top,rgba(87, 35, 50, 0.8) 0,rgba(87, 35, 50, 0.8) 1%,rgba(44, 30, 28, 0.8) 100%) !important;}'
                    );

    sheet.insertRule('.mega-event-panel .mega-event-container .tabs-section #top_ranking_tab_container .top_ranking-container #leaderboard_holder #outer-hero-row {'
                     + 'z-index: 10;}'
                    );

    //Labyrinth battle
    sheet.insertRule('.pvp-container .team-container .pvp-girls .girl-image {'
                     + 'height: 34rem !important;}'
                    );

    //DP event
    sheet.insertRule(`${mediaMobile} {`
                     + '#dp-content .left-container .objectives-container .nc-sub-panel {'
                     + 'height: 13rem !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#dp-content .left-container .tiers-container {'
                     + 'height: 11.75rem !important;}}'
                    );

    //PoA rewards
    sheet.insertRule(`${mediaDesktop} {`
                     + '#events .nc-panel-container .nc-panel-body #poa-content {'
                     + 'height: 14rem !important;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#events .nc-panel-container .nc-panel-body #poa-content {'
                     + 'height: 12rem !important;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#events .nc-panel-container .nc-panel-body #poa-content .objective .reward .nc-sub-panel {'
                     + 'padding: 0rem 0.75rem !important;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#events .nc-panel-container .nc-panel-body #poa-content .reward .icon {'
                     + 'margin-bottom: 1rem !important;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#events .nc-panel-container .nc-panel-body #poa-content .locations .goal {'
                     + 'margin-bottom: 1rem !important;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#events .nc-panel-container .nc-panel-body #poa-content .locations .status {'
                     + 'margin-bottom: 1rem !important;}'
                    );

    //Pantheon
    sheet.insertRule('.pantheon-container #pantheon_tab_container .bottom-container #pantheon_tab_worship_energy {'
                     + 'margin-left: 90px !important;'
                     + 'width: 220px !important;}'
                    );
}