Hentai Heroes++ (OCD) Season version

Adding things here and there in the Hentai Heroes game.

As of 15.01.2023. See ბოლო ვერსია.

// ==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.52.7
// @match           https://*.hentaiheroes.com/*
// @exclude         https://test.hentaiheroes.com/*
// @match           https://*.haremheroes.com/*
// @match           https://*.gayharem.com/*
// @match           https://*.comixharem.com/*
// @match           https://*.hornyheroes.com/*
// @match           https://*.pornstarharem.com/*
// @run-at			document-idle
// @grant			none
// @author			Raphael, 1121, Sluimerstand, shal, Tom208, test_anon, 45026831(Numbers)
// @license			MIT
// ==/UserScript==


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

// 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;

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

var CurrentPage = window.location.pathname;

// Numbers: rounding to K, M, G and T
function nRounding(num, digits, updown) {
    var power = [
        { value: 1, symbol: '' },
        { value: 1E3, symbol: 'K' },
        { value: 1E6, symbol: 'M' },
        { value: 1E9, symbol: 'B' },
        { value: 1E12, symbol: 'T' },
    ];
    var 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)
    }
}

const HC = 1;
const CH = 2;
const KH = 3;

const lvl_max_player = 500;
const lvl_max_girl = 750;

const DST = false;

try {
    const ELEMENTS_ENABLED = !!window.GT.design.fire_flavor_element
    } catch(e){}
/**
 * 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 tower of fame
 */
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 STOCHASTIC_SIM_RUNS = 10000

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

const CDNs = {
    'nutaku.haremheroes.com': 'hh.hh-content.com',
    'www.hentaiheroes.com': 'hh2.hh-content.com',
    'www.comixharem.com': 'ch.hh-content.com',
    'nutaku.comixharem.com': 'ch.hh-content.com',
    'www.gayharem.com': 'gh1.hh-content.com',
    'nutaku.gayharem.com': 'gh.hh-content.com',
    'www.pornstarharem.com': 'th.hh-content.com',
    'nutaku.pornstarharem.com': 'th.hh-content.com'
}
const cdnHost = CDNs[location.host] || 'hh.hh-content.com';

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

window.HHTimers.thresholdTenSec = 3600;
window.HHTimers.thresholdSec = 1800;
window.HHTimers.timerMapping.minute.threshold = 0;
window.HHTimers.timerMapping.tenSeconds.threshold = 0;
window.HHTimers.updateTimer("minute");
window.HHTimers.updateTimer("tenSeconds");
window.HHTimers.timerMapping.minute.threshold = 60000;
window.HHTimers.timerMapping.tenSeconds.threshold = 10000;

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

var texts = [];

texts.en = {
    optionsRefresh: 'Home screen refresh',
    optionsVillain: 'Fight a villain menu',
    optionsTiers: 'Show tiers with girls',
    optionsXPMoney : 'Better XP / Money',
    optionsMarket: 'Market information',
    optionsMarketRestockButton: 'Move the market Restock button next to the Buy all button',
    optionsFilterArmorItems: 'Filter market armors',
    optionsHarem: 'Harem information',
    optionsHaremTeamsFilter: 'Add the team filter to the harem',
    optionsLeague: 'League information',
    optionsLeagueBoard: 'Show the league tops',
    optionsSimFight : 'League / Season / Villains sim',
    optionsTeamsFilter: 'Teams filter',
    optionsChampions: 'Champions information',
    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',
    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_max_level: 'Required to get all haremettes to the max level of their awakening level',
    my_stocks: 'My stock',
    equipments: 'equipments',
    boosters: '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="../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',
    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',
    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="../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',
};

texts.fr = {
    optionsRefresh: 'Rafraîchir page d\'accueil',
    optionsVillain: 'Menu des combats des trolls',
    optionsTiers: 'Montrer les paliers/filles',
    optionsXPMoney : 'XP / Argent + précis',
    optionsMarket: 'Infos marché',
    optionsMarketRestockButton: 'Déplacer le bouton Remplir du marché à côté du bouton Acheter tout',
    optionsFilterArmorItems: 'Filtrer les équipements du marché',
    optionsHarem: 'Infos harem',
    optionsHaremTeamsFilter: 'Ajouter le filtre des équipes dans le harem',
    optionsLeague: 'Infos ligue',
    optionsLeagueBoard: 'Montrer les tops ligue',
    optionsSimFight: 'Simu ligue / saison / combats de troll',
    optionsTeamsFilter: 'Filtre d\'équipes',
    optionsChampions: 'Infos 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',
    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_max_level: 'Requis pour obtenir toutes les filles au niveau max de leur palier d\'éveil',
    my_stocks: 'Mes stocks',
    equipments: 'équipements',
    boosters: 'boosters',
    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="../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é',
    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é',
    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="../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',
};

texts.es = {
    optionsRefresh: 'Actualizacion Menu principal',
    optionsVillain: 'Menu Pelear contra villano',
    optionsTiers: 'Mostrar Rangos con Chicas',
    optionsXPMoney : 'Mejor XP / Dinero',
    optionsMarket: 'Informacion de Mercado',
    optionsMarketRestockButton: 'Mover el botón Reponer del mercado al lado del botón Comprar Todo',
    optionsFilterArmorItems: 'Filtrar armaduras del mercado',
    optionsHarem: 'Informacion de Harén',
    optionsHaremTeamsFilter: 'Añadir el filtro de equipo al harén',
    optionsLeague: 'Informacion de Liga',
    optionsLeagueBoard: 'Mostrar los mejores de la liga',
    optionsSimFight: 'Simulacion de Liga / Temporada / Villano',
    optionsTeamsFilter: 'Filtro de equipos',
    optionsChampions: 'Informacion de 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',
    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_max_level: 'Requerido para obtener todas las chicas al máximo nivel de su despertar nivel',
    my_stocks: 'Mi Stock',
    equipments: 'equipos',
    boosters: '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="../shop.html">Mercado</a> primero.',
    not_compatible: 'Tu navegador no es compatible.',
    or_level: 'o nivel',
    restock: 'Restock',
    wiki: ' wiki',
    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: 'Opositores',
    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',
    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',
    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="../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',
};

texts.it = {
    optionsRefresh: 'Refresh pagina Home',
    optionsVillain: 'Menù battaglia Troll',
    optionsTiers: 'Mostra battaglie con ragazze',
    optionsXPMoney : 'Migliora XP / soldi',
    optionsMarket: 'Informazioni negozio',
    optionsMarketRestockButton: 'Spostate il pulsante Rifornisci del mercato accanto al pulsante Acquista tutto',
    optionsFilterArmorItems: 'Filtrare armature di mercato',
    optionsHarem: 'Informazioni Harem',
    optionsHaremTeamsFilter: 'Aggiungere il filtro squadra all\'harem',
    optionsLeague: 'Informazioni sulle Leghe',
    optionsLeagueBoard: 'Mostra i top della lega',
    optionsSimFight: 'Simulazione Leghe / Stagione / Troll',
    optionsTeamsFilter: 'Filtro delle squadre',
    optionsChampions: 'Informazioni sui 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',
    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_max_level: 'Necessario per livellare tutte le ragazze al massimo livello di risveglio livello',
    my_stocks: 'Mio inventario',
    equipments: 'attrezzature',
    boosters: '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="../shop.html">negozio</a> prima.',
    not_compatible: 'Il tuo browser non è compatibile.',
    or_level: 'o livello',
    restock: 'Rifornimento',
    wiki: ' -> wiki',
    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',
    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',
    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="../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',
};

texts.de = {
    optionsRefresh: 'Homepage aktualisieren',
    optionsVillain: 'Widersacher-Menü',
    optionsTiers: 'Stufen mit Girls anzeigen',
    optionsXPMoney : 'Migliora XP / soldi',
    optionsMarket: 'Marktplatz-Informationen',
    optionsMarketRestockButton: 'Verschieben Sie die Schaltfläche "Auffüllen" neben die Schaltfläche "Kaufe alles"',
    optionsFilterArmorItems: 'Filter Markt Rüstungen',
    optionsHarem: 'Harem-Informationen',
    optionsHaremTeamsFilter: 'Hinzufügen des Teamfilters zum Harem',
    optionsLeague: 'Liga-Informationen',
    optionsLeagueBoard: 'Die Liga-Spitzen anzeigen',
    optionsSimFight: 'Liga/Saison/Widersacher-Simulation',
    optionsTeamsFilter: 'Mannschaften filtern',
    optionsChampions: 'Champion-Informationen',
    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',
    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_max_level: 'Erforderlich für die maximale Mädchen-Level ihrer Erweckungsstufe',
    my_stocks: 'Meine Bestände',
    equipments: 'Ausrüstungen',
    boosters: '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="../shop.html">Marktplatz</a>.',
    not_compatible: 'Dein Browser ist nicht kompatibel.',
    or_level: 'oder Level',
    restock: 'neue Angebote',
    wiki: '-Wikiseite',
    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: 'aktuelle Zuneigung',
    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="../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',
};

let lang = "en";
let 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'
}
const localeDecimalSep = Number(1.1).toLocaleString(locale).replace(/[0-9]/g, '');
const parseLocaleFloat = (numStr) => parseFloat(numStr.split(localeDecimalSep).map(part => part.replace(/[^0-9]/g, '')).join('.'), 10);

// Parser for League stats
const parseLocaleRoundedInt = (numStr) => numStr.includes(localeDecimalSep) ? parseInt(numStr.replace('K', '00').replace('M', '0000').replace(/[^0-9]/gi, ''), 10) : (numStr.includes('K') || numStr.includes('M')) ? parseInt(numStr.replace('K', '000').replace('M', '000000').replace(/[^0-9]/gi, ''), 10) : parseInt(numStr.replace(/[^0-9]/gi, ''), 10);

let tierGirlsID = [];

if (window.HH_UNIVERSE == 'hentai' || window.HH_UNIVERSE == 'horny_s' || 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') {
    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]],
    ];
}
else if (window.HH_UNIVERSE == 'comix_c' || window.HH_UNIVERSE == 'nutaku_c') {
    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]],
    ];
}
else if (window.HH_UNIVERSE == 'star_t' || window.HH_UNIVERSE == 'nutaku_t') {
    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]],
    ];
}

const GIRLS_EXP_LEVELS = [];

GIRLS_EXP_LEVELS.starting = [];
GIRLS_EXP_LEVELS.common = [];
GIRLS_EXP_LEVELS.rare = [];
GIRLS_EXP_LEVELS.epic = [];
GIRLS_EXP_LEVELS.legendary = [];
GIRLS_EXP_LEVELS.mythic = [];

GIRLS_EXP_LEVELS.starting[0] = 10;
GIRLS_EXP_LEVELS.common[0] = 10;
GIRLS_EXP_LEVELS.rare[0] = 12;
GIRLS_EXP_LEVELS.epic[0] = 14;
GIRLS_EXP_LEVELS.legendary[0] = 16;
GIRLS_EXP_LEVELS.mythic[0] = 40;

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 = [];

AWAKENING_GEMS_COST.starting = [0, 40, 60, 80, 100, 125, 150, 200, 275, 350, 500];
AWAKENING_GEMS_COST.common = [0, 40, 60, 80, 100, 125, 150, 200, 275, 350, 500];
AWAKENING_GEMS_COST.rare = [0, 80, 120, 160, 200, 250, 300, 400, 550, 700, 1000];
AWAKENING_GEMS_COST.epic = [0, 120, 180, 240, 300, 375, 450, 600, 825, 1050, 1500];
AWAKENING_GEMS_COST.legendary = [0, 160, 240, 320, 400, 500, 600, 800, 1100, 1400, 2000];
AWAKENING_GEMS_COST.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];

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

    if (temp === null) {
        switch (e) {
            case 'refresh':
                return false;
            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 'haremTeamsFilter':
                return true;
            case 'league':
                return true;
            case 'leagueBoard':
                return true;
            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;
        }
    }

    return temp
}

if (window.Hero === undefined) { return; }

if (CurrentPage.indexOf('home') != -1) options();

// Show which modules are enabled and if so, run them when appropriate
if (loadSetting('refresh')) {
    if (CurrentPage.indexOf('home') != -1) {
        moduleRefresh();
    }
}
if (loadSetting('villain')) {
    moduleVillain();
}
if (loadSetting('xpMoney')) {
    setTimeout(function() {
        moduleXP();
        moduleMoney();
    }, 200)

}
if (loadSetting('market')) {
    if (CurrentPage.indexOf('shop') != -1) {
        moduleMarket();
    }
}
if (loadSetting('marketRestockButton')) {
    if (CurrentPage.indexOf('shop') != -1) {
        moduleMarketRestockButton();
    }
}
if (loadSetting('filterArmorItems')) {
    if (CurrentPage.indexOf('shop') != -1) {
        setTimeout(function() {
            moduleFilterArmorItems();
        }, 200);
    }
    if (CurrentPage.indexOf('mythic-equipment-upgrade') != -1) {
        setTimeout(function() {
            moduleMythicEquipmentUpgrade();
        }, 200);
    }
}
if (loadSetting('harem')) {
    if (CurrentPage.indexOf('harem') != -1) {
        moduleHarem();
    }
}
if (loadSetting('haremTeamsFilter')) {
    if (CurrentPage.indexOf('harem') != -1) {
        moduleHaremTeamsFilter();
    }
    if (CurrentPage.indexOf('teams') != -1) {
        moduleTeamsCollector();
    }
}
if (loadSetting('league')) {
    moduleLeague();
}
if (loadSetting('simFight')) {
    if (CurrentPage.indexOf('tower-of-fame') != -1) {
        moduleSim();
    }
    if (CurrentPage.indexOf('season-arena') != -1) {
        moduleSeasonSim();
    }
    if (CurrentPage.indexOf('troll-pre-battle') != -1 || CurrentPage.indexOf('pantheon-pre-battle') != -1) {
        moduleBattleSim();
    }
}
if (loadSetting('teamsFilter')) {
    moduleTeamsFilter();
}
if (loadSetting('champions')) {
    setTimeout(function() {
        moduleChampions();
    }, 200)
}
if (loadSetting('links')) {
    moduleLinks();
}
if (loadSetting('seasonStats')) {
    if (CurrentPage.indexOf('season-battle') != -1 || CurrentPage.indexOf('season') != -1) {
        moduleSeasonStats();
    }
}
if (loadSetting('pachinkoNames')) {
    modulePachinkoNames();
}
if (loadSetting('missionsBackground')) {
    moduleMissionsBackground();
}
if (loadSetting('collectMoneyAnimation')) {
    moduleCollectMoneyAnimation();
}
if (loadSetting('activitiesTabChoice') && CurrentPage == '/home.html') {
    moduleActivitiesTabChoice();
}
if (loadSetting('customizedHomeScreen') && CurrentPage == '/home.html') {
    setTimeout(function() {
        moduleCustomizedHomeScreen();
    }, 200)
}
if (loadSetting('hideClaimedRewards')) {
    setTimeout(function() {
        moduleHideClaimedRewards();
    }, 200)
}
if (loadSetting('desktopDisplay')) {
    setTimeout(function() {
        moduleDesktopDisplay();
    }, 200)

}

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;">'
                                 + '<label class="switch"><input type="checkbox" hhs="refresh"><span class="slider"></span></label>' + labels.optionsRefresh + '<br />'
                                 + '<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 />'
                                 + '<label class="switch"><input type="checkbox" hhs="xpMoney"><span class="slider"></span></label>' + labels.optionsXPMoney + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="market"><span class="slider"></span></label>' + labels.optionsMarket + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="marketRestockButton"><span class="slider"></span></label>' + labels.optionsMarketRestockButton + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="filterArmorItems"><span class="slider"></span></label>' + labels.optionsFilterArmorItems + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="harem"><span class="slider"></span></label>' + labels.optionsHarem + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="haremTeamsFilter"><span class="slider"></span></label>' + labels.optionsHaremTeamsFilter + '<br />'
                                 + '<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 />'
                                 + '<label class="switch"><input type="checkbox" hhs="simFight"><span class="slider"></span></label>' + labels.optionsSimFight + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="teamsFilter"><span class="slider"></span></label>' + labels.optionsTeamsFilter + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="champions"><span class="slider"></span></label>' + labels.optionsChampions + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="links"><span class="slider"></span></label>' + labels.optionsLinks + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="seasonStats"><span class="slider"></span></label>' + labels.optionsSeasonStats + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="pachinkoNames"><span class="slider"></span></label>' + labels.optionsPachinkoNames + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="missionsBackground"><span class="slider"></span></label>' + labels.optionsMissionsBackground + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="collectMoneyAnimation"><span class="slider"></span></label>' + labels.optionsCollectMoneyAnimation + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="activitiesTabChoice"><span class="slider"></span></label>' + labels.optionsActivitiesTabChoice + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="customizedHomeScreen"><span class="slider"></span></label>' + labels.optionsCustomizedHomeScreen + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="hideClaimedRewards"><span class="slider"></span></label>' + labels.optionsHideClaimedRewards + '<br />'
                                 + '<label class="switch"><input type="checkbox" hhs="desktopDisplay"><span class="slider"></span></label>' + labels.optionsDesktopDisplay
                                 + '</div>');

    // Show and hide options menu
    $('#hhsButton').click(function() {
        var x = document.getElementById('hhsOptions');
        if (x.style.display === 'none') {
            x.style.display = 'block';
        }
        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'))
    })

    // 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=leagueBoard]').click(function() {
        if ($(this).is(':checked')) {
            $('[hhs=league]').prop('checked', true);
            localStorage.setItem('HHS.league', true)
        }
    });

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

    setTimeout(function() {
        if ($('.hh-plus-plus-config-button').length > 0) {
            sheet.insertRule(`${mediaDesktop} {`
                             + '#hhsButton {'
                             + 'top: 100px;}}'
                             //+ 'top: 55px;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#hhsButton {'
                             + 'top: 150px;}}'
                            );
        }
        else {
            sheet.insertRule(`${mediaDesktop} {`
                             + '#hhsButton {'
                             + 'top: 55px;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '#hhsButton {'
                             + 'top: 95px;}}'
                            );
        }
    }, 200);

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

    sheet.insertRule('.hhsTooltip {'
                     + 'column-count: 2;'
                     + 'column-width: auto;'
                     + 'width: 830px;'
                     + '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;'
                     + 'right: 50px;'
                     + 'top: 85px;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.hhsTooltip {'
                     + 'font-size: 18px; '
                     + 'line-height: 36px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.hhsTooltip {'
                     + 'font-size: 14px;'
                     + 'line-height: 28px;}}'
                    );

    sheet.insertRule('#hhsOptions > 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);}'
                    );
}

/* =====================
	HOME SCREEN REFRESH
   ===================== */

function moduleRefresh() {
    setInterval(function() {
        window.location.reload();
    }, 600000);
}

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

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

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

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

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

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

    if (window.location.search.includes("tab=event")) {
        let eventRemainingTime = parseInt($('#contains_all #events .nc-panel-header .nc-pull-right #timer').attr("data-seconds-until-event-end"), 10);
        eventEndTime = Math.floor(new Date().getTime()/1000) + eventRemainingTime;
        localStorage.setItem('eventTime', eventEndTime);

        eventTrolls = [];

        let totalGirls = $('#contains_all #events .nc-panel-body .nc-event-container .nc-event-reward-container').length;
        for (var i=0; i<totalGirls; i++) {
            let girlId = $('#contains_all #events .nc-panel-body .nc-event-container .nc-event-reward-container')[i].attributes["data-reward-girl-id"].value;
            let girlLocation = $('#contains_all #events .nc-panel-body .nc-event-container .nc-event-reward-container')[i].children[0].children[0].children[1].children[0].attributes.href.value;
            let index = $('#contains_all #events .nc-panel-body .nc-event-container .nc-event-reward-container')[i].children[2].children[0].children[0].attributes.class.value.indexOf('-text');
            let girlRarity = $('#contains_all #events .nc-panel-body .nc-event-container .nc-event-reward-container')[i].children[2].children[0].children[0].attributes.class.value.substring(0, index);
            if (girlLocation.includes('troll-pre-battle')) {
                eventTrolls.push({id: girlId, troll: girlLocation.substring(35), rarity: girlRarity});
            }
        }
        localStorage.setItem('eventTrolls', JSON.stringify(eventTrolls));
    }

    if (window.location.search.includes("tab=mythic_event")) {
        let eventRemainingTime = parseInt($('#contains_all #events .nc-panel-header .nc-pull-right #timer').attr("data-seconds-until-event-end"), 10);
        mythicEventEndTime = Math.floor(new Date().getTime()/1000) + eventRemainingTime;
        localStorage.setItem('mythicEventTime', mythicEventEndTime);

        mythicEventTrolls = [];

        let totalGirls = $('#contains_all #events .nc-panel-body .nc-event-container .nc-event-reward-container').length;
        for (var j=0; j<totalGirls; j++) {
            let girlId = $('#contains_all #events .nc-panel-body .nc-event-container .nc-event-reward-container:nth-child(' + (j+1) + ')').attr('data-reward-girl-id');
            let girlLocation = $('#contains_all #events .nc-panel-body .nc-event-container .nc-event-reward-container:nth-child(' + (j+1) + ') .nc-events-prize-locations-buttons-container .nc-events-prize-locations-buttons-container a').attr('href');
            let index = $('#contains_all #events .nc-panel-body .nc-event-container .nc-event-reward-container:nth-child(' + (j+1) + ') .nc-event-reward-info .new_girl_info h5').attr('class').indexOf('-text');
            let girlRarity = $('#contains_all #events .nc-panel-body .nc-event-container .nc-event-reward-container:nth-child(' + (j+1) + ') .nc-event-reward-info .new_girl_info h5').attr('class').substring(0, index);
            if (girlLocation.includes('troll-pre-battle')) mythicEventTrolls.push({id: girlId, troll: girlLocation.substring(35), rarity: girlRarity});
        }
        localStorage.setItem('mythicEventTrolls', JSON.stringify(mythicEventTrolls));
    }

    if (includeTiers) {
        //Check if villain tier girls have been collected
        tierGirlsOwned = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []];

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

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

    //Add the actual menu
    var trolls;
    var trollGems;
    var trollRewards;
    if (window.HH_UNIVERSE == 'hentai' || window.HH_UNIVERSE == 'horny_s' || 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') {
        trolls = ['Dark Lord', 'Ninja Spy', 'Gruntt', 'Edwarda', 'Donatien', 'Silvanus', 'Bremen', 'Finalmecia', 'Roko Senseï', 'Karole', 'Jackson&#8217;s Crew', 'Pandora Witch', 'Nike', 'Sake', 'WereBunny Police', 'Auga'];
        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] = 'Ninja Spion';
            trolls[10] ='Jacksons Crew';
            trolls[11] ='Pandora Hexe';
            trolls[14] = 'Wer-Kaninchen Polizei';
        }
    }
    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'];
    }
    else if (window.HH_UNIVERSE == 'star_t' || window.HH_UNIVERSE == 'nutaku_t') {
        trolls = ['Headmistress Asa Akira', 'Sammy Jayne', 'Ivy Winters', 'Lily Cade', 'Amia Miley', 'Alyssa Reece', 'Kelly Kline'];
        if (lang == 'fr') {
            trolls[0] = 'Directrice Asa Akira';
        }
    }

    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>',
                ];

    trollRewards = ['',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '&nbsp;&nbsp;<span class="gift_reward"></span>',
                    '&nbsp;&nbsp;<span class="book_reward"></span>',
                    '&nbsp;&nbsp;<span class="gift_reward"></span>',
                    '',
                    '',
                    '',
                    '',
                   ]

    var currentWorld = window.Hero.infos.questing.id_world,
        trollName = '',
        trollNameTiers = '',
        trollGemRewards = '',
        trollOtherRewards = '',
        trollsMenu = '';

    for (var k = 0; k < (currentWorld-1); k++) {
        if (typeof trolls[k] !== typeof undefined && trolls[k] !== false) {
            trollName = trolls[k];
            trollGemRewards = trollGems[k];
            trollOtherRewards = trollRewards[k];
            if (includeTiers) {
                trollNameTiers = ' ';
                if (!(tierGirlsOwned[k][0])) {
                    trollNameTiers = trollNameTiers + '&#185;';
                }
                if (!(tierGirlsOwned[k][1])) {
                    trollNameTiers = trollNameTiers + '&#178;';
                }
                if (!(tierGirlsOwned[k][2])) {
                    trollNameTiers = trollNameTiers + '&#179;';
                }
            }
        }
        else trollName = labels.world + ' ' + (k + 2) + ' ' + labels.villain;
        var type = 'regular';
        for (var l = 0, len = eventTrolls.length; l < len; l++) {
            let shards = (girlDictionary.get(parseInt(eventTrolls[l].id, 10)) != undefined) ? girlDictionary.get(parseInt(eventTrolls[l].id, 10)).shards : 0;
            if (eventTrolls[l].troll == (k + 1) && shards != 100) {
                type = 'eventTroll ' + eventTrolls[l].rarity;
            }
        }
        for (var m = 0; m < mythicEventTrolls.length; m++) {
            let shards = (girlDictionary.get(parseInt(mythicEventTrolls[m].id, 10)) != undefined) ? girlDictionary.get(parseInt(mythicEventTrolls[m].id, 10)).shards : 0;
            if (mythicEventTrolls[m].troll == (k + 1) && shards != 100) {
                type = 'mythicEventTroll';
            }
        }
        trollsMenu += '<a class="' + type + '" href="/troll-pre-battle.html?id_opponent=' + (k + 1) + '">' + trollName + trollNameTiers + '</a>' + trollGemRewards + trollOtherRewards + '&nbsp;&nbsp;&nbsp;<a class="troll_world_script" href="/world/' + (k + 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');
    });

    $('#contains_all > header [type=fight] .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('#contains_all > header [type="fight"] .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.infos.soft_currency >= 1E6) {
            $('div[hero="soft_currency"]').empty().append(nRounding(window.Hero.infos.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() {
    var loc2 = $('#my-hero-stats-upgrade-tab-container .upgrade-stats-container').children();
    loc2.each(function() {
        var stat = $(this).attr('class');
        if (stat == 'caracs-1-container' || stat == 'caracs-2-container' || stat == 'caracs-3-container') {
            stat = 'carac' + stat.replace(/\D/g, '');
            $(this).append('<span class="CustomStats"></span><div id="CustomStats' + stat + '" class="StatsTooltip"></div>');
        }
    });

    updateStats();

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

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

                var equipmentsData = $('#equiped.armor-container .armor .slot-container .slot-container').children(),
                    itemPoints = 0;
                equipmentsData.each(function() {
                    if ($(this).attr('class').indexOf('slot empty') == -1) {
                        var 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);
                    }});

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

                var 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) {
        var last_price = calculateStatPrice(points);
        var 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);
        }
        return price;
    }

    function calculateStatPrice(points) {
        var 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;
        }
        return cost;
    }

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

    setTimeout(function() {
        var restocktime = 0;
        var 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})
    }, 500);

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

    function get_buyableStocks(loc_class) {
        var itemsNb = 0,
            itemsXp = 0,
            itemsPriceYmens = 0,
            itemsPriceKobans = 0,
            loc = $('#merchant-inventory.' + loc_class);
        loc.find('.slot').each(function() {
            if ($(this).hasClass('empty')) return false;
            var 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) {
        var itemsNb = 0,
            itemsXp = (itemUnit === '') ? -1 : 0,
            itemsSell = 0,
            loc = $('#player-inventory.' + loc_class);

        loc.find('.slot').each(function() {
            if ($(this).hasClass('empty')) return false;
            var 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);
        });

        var 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('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) {
        var 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']});
    }

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

    if (localStorage.getItem('HHPlusPlusConfig')) {
        if (JSON.parse(localStorage.getItem('HHPlusPlusConfig')).zoo_MarketTweaks) {
            sheet.insertRule('#player-inventory-container .CustomTT {'
                             + 'margin-left: -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: 42px;}'
                    );

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


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

    setTimeout(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'));

        $('#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'));
        });
    }, 200);

    const getFavorites = () => JSON.parse(localStorage.getItem('EQUIP_FAVORITES')) || [];
    const setFavorites = (favorites) => localStorage.setItem('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('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('market_paramFilterHero', JSON.stringify(paramFilterHero));
    const getParamFilterEquip = () => JSON.parse(localStorage.getItem('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('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', bgColor: '#9150bf', bgImage: 'url("' + window.IMAGES_URL + '/legendary.png")'},
            {value: 'mythic', bgColor: '#9e0e27'}
        ]}
        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: '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_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',
            rows: '1fr 1fr 1fr'
        },
        rarity: {
            flow: 'row',
            cols: '1fr 1fr',
            rows: '1fr 1fr 1fr'
        },
        stats: {
            flow: 'row',
            cols: '1fr 1fr',
            rows: '1fr 1fr 1fr',
        },
        favorites: {
            flow: 'row',
            cols: '1fr auto',
            rows: '1fr'
        },
        resonance_class: {
            flow: 'row',
            cols: '1fr 1fr',
            rows: '1fr 1fr'
        },
        resonance_class_type: {
            flow: 'row',
            cols: '1fr 1fr',
            rows: '1fr'
        },
        resonance_theme: {
            flow: 'row',
            cols: '1fr 1fr',
            rows: '1fr 1fr 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}" ${(currentFilter(location)[id] == '' + value) ? "checked = checked" : ''} />`
                                                                                       + `<label for="${location}-${id}-${value}">`
                                                                                       + `${icon ? `<img src="${window.IMAGES_URL}/${icon}">` : ''}`
                                                                                       + `${bgColor || bgImage ? `<div style="${bgColor?`background-color:${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}" value="${FILTER_DEFAULT}" ${(currentFilter(location)[id] == FILTER_DEFAULT) ? "checked = checked" : ''} />`
                                                                         + `<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>');

    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('')}`
                 + '</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())
        $box.find('input').each((i, input) => {
            $(input).change((e) => {
                const {value, name} = e.target;
                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);
            })
        })
    }

    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 !important;'
                     + 'top: 87px !important;}'
                    );

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

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

            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: -349px !important;'
                             + 'left: -90px !important;}'
                            );

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

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

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

    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: 120px !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('#my-hero-equipement-tab-container #player-inventory-container .equip_filter_box {'
                     + 'left: -111px !important;'
                     + 'top: -345px !important;}'
                    );

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

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

    sheet.insertRule('#equipement-tab-container #player-inventory-container .equip_filter_box.resonance {'
                     + 'left: -718px !important;'
                     + 'top: 33px !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: unset !important;'
                     + 'margin-bottom: 16px !important;}'
                    );

    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: 32px;'
                     + 'width: 32px;'
                     + 'margin: 2px;}'
                    );

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

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

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

    sheet.insertRule('.equip_filter_box .grid-selector input:checked + 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;}'
                    );
}


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

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

    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('_');


    function protectFavoriteItems() {
        const favorites = getFavorites();
        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.item, equipData.skin) : makeEquipKeyMythic(equipData, equipData.skin, classIdentifier, classResonance, themeIdentifier, themeResonance)

            const isFavorite = favorites.includes(equipKey)

            if (isFavorite) {
                //$el.parentNode.remove();
                $($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], {subtree: true, attributes: true, attributeFilter: ['class']})
}


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

function moduleHarem() {
    let stats = [];
    let girlsList = [];
    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.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;

    for (let id in window.girlsDataList) {
        let girl = window.jQuery.extend(true, {}, window.girlsDataList[id]);
        if (girl.own) {
            stats.allCollect += girl.salary;
            stats.rarities[girl.rarity]++;
            stats.elements[girl.element]++;
            stats.caracs[girl.class]++;
            stats.girls++;
            stats.level_max += girl.level_cap;
            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;
                var 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][girl.level_cap - 2] - girl.Xp.cur);
            if (expToMax < 0) expToMax = 0;
            stats.xp += expToMax;

            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
            let awakening_level = parseInt(girl.awakening_level, 10);
            if (awakening_level < (AWAKENING_GEMS_COST[girl.rarity].length-1) && nbgrades >= 5 && (girl.rarity == 'legendary' || girl.rarity == 'mythic')) {
                for (let i = (awakening_level+1); i < AWAKENING_GEMS_COST[girl.rarity].length; i++) {
                    stats.gemsRequirements[girl.element] += AWAKENING_GEMS_COST[girl.rarity][i];
                }
            }
        }
    }

    /*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];
        }
    }*/

    try {
        var lsMarket = JSON.parse(localStorage.getItem('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="../shop.html">Market</a> restocked since your last visit.';
        }
        else {
            var	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"></span> ' + labels.and + ' ' + nThousand(lsMarket.buyable.potion.ValueKobans) + ' <span class="imgKobans"></span>'
                + '<br />- ' + marketGiftTxt + ' = ' + nThousand(lsMarket.buyable.gift.ValueYmens) + ' <span class="imgMoney"></span> ' + labels.and + ' ' + nThousand(lsMarket.buyable.gift.ValueKobans) + ' <span class="imgKobans"></span>'
                + '<br /><font style="color: gray;">' + labels.restock + ': ' + d.toLocaleString() + ' (' + labels.or_level + ' ' + (window.Hero.infos.level+1) + ')</font>';
        }

        var myArmorTxt = nThousand(lsMarket.stocks.armor.Nb) + (lsMarket.stocks.armor.Nb > 99 ? '+ ' : ' ') + ' ' + (lsMarket.stocks.armor.Nb > 1 ? labels.equipments : labels.equipment) + (lsMarket.stocks.armor.Nb > 1 ? '' : -'s'),
            myBoosterTxt = nThousand(lsMarket.stocks.booster.Nb) + ' ' + (lsMarket.stocks.booster.Nb > 1 ? labels.boosters : labels.booster),
            myBookTxt = nThousand(lsMarket.stocks.potion.Nb) + ' ' + (lsMarket.stocks.potion.Nb > 1 ? labels.books : labels.book) + ' (' + nThousand(lsMarket.stocks.potion.Xp) + ' ' + labels.Xp + ')',
            myGiftTxt = nThousand(lsMarket.stocks.gift.Nb) + ' ' + (lsMarket.stocks.gift.Nb > 1 ? labels.gifts : labels.gift) + ' (' + nThousand(lsMarket.stocks.gift.Xp) + ' ' + labels.affection + ')',
            MarketStocks = '- ' + myArmorTxt + ', ' + myBoosterTxt
        + '<br />- ' + myBookTxt
        + '<br />- ' + myGiftTxt
        + '<span class="subTitle">' + labels.currently_buyable + ':</span>'
        + RestockInfo;
    } catch(e) {
        MarketStocks = (window.lsAvailable == 'yes') ? '> ' + labels.visit_the : '> ' + labels.not_compatible;
    }

    var StatsString = '<div class="StatsContent"><span class="Title">' + labels.harem_stats + ':</span>' +
        '<span class="subTitle" style="margin-top: -10px;">' + nThousand(stats.girls) + ' ' + labels.haremettes + ':</span>' +
        '- ' + stats.caracs[1] + ' ' + labels.hardcore + (stats.caracs[1] > 1 && lang == 'fr' ? 's' : '') + ', ' + stats.caracs[2] + ' ' + labels.charm + (stats.caracs[2] > 1 && lang == 'fr' ? 's' : '') + ', ' + stats.caracs[3] + ' ' + labels.know_how + '<br />- '
    + (stats.rarities.starting + stats.rarities.common) + ' ' + labels.common + (lang == 'fr' ? 'e' : '') + ((stats.rarities.starting + stats.rarities.common) > 1 && lang == 'fr' ? 's' : '') + ' ' + labels.including + ':&nbsp;&nbsp;' + stats.grades.common['1'] + '&nbsp;&nbsp;1<span class="imgStar"></span>,&nbsp;&nbsp;' + (stats.grades.starting['3'] + stats.grades.common['3']) + '&nbsp;&nbsp;3<span class="imgStar"></span>&nbsp;&nbsp;' + labels.and + '&nbsp;&nbsp;' + (stats.grades.starting['5'] + stats.grades.common['5']) + '&nbsp;&nbsp;5<span class="imgStar"></span><br />- '
    + stats.rarities.rare + ' ' + labels.rare + (stats.rarities.rare > 1 && lang == 'fr' ? 's' : '') + ' ' + labels.including + ':&nbsp;&nbsp;' + stats.grades.rare['3'] + '&nbsp;&nbsp;3<span class="imgStar"></span>&nbsp;&nbsp;' + labels.and + '&nbsp;&nbsp;' + stats.grades.rare['5'] + '&nbsp;&nbsp;5<span class="imgStar"></span><br />- '
    + stats.rarities.epic + ' ' + labels.epic + (stats.rarities.epic > 1 && lang == 'fr' ? 's' : '') + ' ' + labels.including + ':&nbsp;&nbsp;' + stats.grades.epic['3'] + '&nbsp;&nbsp;3<span class="imgStar"></span>&nbsp;&nbsp;' + labels.and + '&nbsp;&nbsp;' + stats.grades.epic['5'] + '&nbsp;&nbsp;5<span class="imgStar"></span><br />- '
    + stats.rarities.legendary + ' ' + labels.legendary + (stats.rarities.legendary > 1 && lang == 'fr' ? 's' : '') + ' ' + labels.including + ':&nbsp;&nbsp;' + stats.grades.legendary['3'] + '&nbsp;&nbsp;3<span class="imgStar"></span>&nbsp;&nbsp;' + labels.and + '&nbsp;&nbsp;' + stats.grades.legendary['5'] + '&nbsp;&nbsp;5<span class="imgStar"></span><br />- '
    + stats.rarities.mythic + ' ' + labels.mythic + (stats.rarities.mythic > 1 && lang == 'fr' ? 's' : '') + ' <br />- '
    + stats.elements.darkness + ' <span class="darkness_elem"></span>, ' + stats.elements.light + ' <span class="light_elem"></span>, ' + stats.elements.psychic + ' <span class="psychic_elem"></span>, ' + stats.elements.fire + ' <span class="fire_elem"></span>, ' + stats.elements.nature + ' <span class="nature_elem"></span>, ' + stats.elements.stone + ' <span class="stone_elem"></span>, ' + stats.elements.sun + ' <span class="sun_elem"></span>, ' + stats.elements.water + ' <span class="water_elem"></span> <br />- '
    + nThousand(parseInt(window.player_gems_amount.darkness.amount)) + ' <span class="darkness_gem"></span>, ' + nThousand(parseInt(window.player_gems_amount.light.amount)) + ' <span class="light_gem"></span>, ' + nThousand(parseInt(window.player_gems_amount.psychic.amount)) + ' <span class="psychic_gem"></span>, ' + nThousand(parseInt(window.player_gems_amount.fire.amount)) + ' <span class="fire_gem"></span>, ' + nThousand(parseInt(window.player_gems_amount.nature.amount)) + ' <span class="nature_gem"></span>, ' + nThousand(parseInt(window.player_gems_amount.stone.amount)) + ' <span class="stone_gem"></span>, ' + nThousand(parseInt(window.player_gems_amount.sun.amount)) + ' <span class="sun_gem"></span>, ' + nThousand(parseInt(window.player_gems_amount.water.amount)) + ' <span class="water_gem"></span> <br />- '
    + nThousand(parseInt(document.getElementsByClassName('focus_text')[0].innerHTML.replace(/\D/g, ''), 10)) + '/' + nThousand(stats.level_max) + ' ' + labels.harem_levels + ' (' + nThousand(stats.level_max - parseInt(document.getElementsByClassName('focus_text')[0].innerHTML.replace(/\D/g, ''), 10)) + ' ' + labels.to_go + ((stats.level_max - parseInt(document.getElementsByClassName('focus_text')[0].innerHTML.replace(/\D/g, ''), 10)) > 1 && lang == 'fr' ? 's' : '') + ')<br />- '
    + stats.unlockedScenes + '/' + stats.allScenes + ' ' + labels.unlocked_scenes + ' (' + nThousand(stats.allScenes - stats.unlockedScenes) + ' ' + labels.to_go + (lang == 'fr' ? 'e' : '') + ((stats.allScenes - stats.unlockedScenes) > 1 && lang == 'fr' ? 's' : '') + ')'
    + '<span class="subTitle">' + labels.money_income + ':</span>'
    + '~' + nThousand(stats.hourlyMoney) + ' <span class="imgMoney"></span> ' + labels.per_hour
    + '<br />' + nThousand(stats.allCollect) + ' <span class="imgMoney"></span> ' + labels.when_all_collectable
    + '<span class="subTitle">' + labels.required_to_unlock + ':</span>'
    + addPriceRow('', stats.affection, stats.money, stats.kobans)
    + '<span class="subTitle">' + labels.required_to_get_max_level + ':</span>'
    + nThousand(stats.xp) + ' ' + labels.Xp + ' (' + nThousand(stats.xp * 200) + ' <span class="imgMoney"></span>) <br />'
    + '<span class="subTitle">' + labels.my_stocks + ':</span>'
    + MarketStocks
    + '</div>';

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

    var TabsContainer = $('#TabsContainer');
    var Stats = TabsContainer.children('.StatsContent');

    $('body').click(function(e) {
        var clickOn = e.target.getAttribute('f');
        switch (clickOn) {
            case 'stats':
                toggleTabs(Stats);
                break;
            default:
                var clickedContainer = $(e.target).closest('[id]').attr('id');
                if (clickedContainer == 'TabsContainer') return;
                TabsContainer.fadeOut(400);
        }
    });

    function toggleTabs(tabIn) {
        if (TabsContainer.css('display') == 'block') {
            setTimeout(function() { tabIn.fadeIn(300); }, 205);
            TabsContainer.fadeOut(400);
        }
        else {
            tabIn.toggle(true);
            TabsContainer.fadeIn(400);
        }
    }

    function addPriceRow(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 + ' <br />' +
            nThousand(money) + ' <span class="imgMoney"></span> ' + labels.or + ' ' +
            nThousand(kobans) + ' <span class="imgKobans"></span><br />';
    }

    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() {
        updateInfo();
    });

    $('#filtering_girls').click(function() {
        updateInfo();
    });

    updateInfo();

    function updateInfo() {
        setTimeout(function () {
            haremRight.children('[girl]').each(function() {
                var girl = window.girlsDataList[$(this).attr('girl')];
                //for Wiki FR
                var 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') {
                    if ($(this).find('.middle_part .WikiLink h3').length == 0) {
                        if (!girl.own) {
                            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 == 'fr') {
                                $(this).find('.middle_part.missing_girl .dialog-box').after('<div class="WikiLinkDialogbox"><a href="http://hentaiheroes.wikidot.com/' + girlName + '" target="_blank"> ' + labels.wiki + girl.name + ' </a></div>');
                            }
                            else {
                                $(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>');
                            }
                        }
                        if (girl.own && ($('#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 == 'fr') {
                                $(this).find('.middle_part h3').after('<div class="WikiLink"><a href="http://hentaiheroes.wikidot.com/' + girlName + '" target="_blank"> ' + labels.wiki + girl.name + ' </a></div>');
                            }
                            else {
                                $(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 {
                        var 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.wikidot.com/' + girlName;
                        }
                        else {
                            newHref = 'https://harem-battle.club/wiki/Harem-Heroes/HH:' + girlName;
                        }
                        $(this).find('.middle_part .WikiLink a').attr('href', newHref);
                    }
                }
                var j = 0,
                    FirstLockedScene = 1,
                    AffectionTT = labels.evolution_costs + ':<br />',
                    ScenesLink = '',
                    girl_quests = $(this).find('.girl_quests');
                girl_quests.find('g').each(function() {

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

                girl_quests.children('a').each(function() {
                    var 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>');

            });
        }, 50);
    }

    moduleGemStock();
    moduleSultryCoins();

    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('hh_title', stockTable);
            $('#harem_right').append($gemStock);
        }

        const injectCSS = () => {
            const randomElement = elements[Math.floor(Math.random() * elements.length)]
            sheet.insertRule('.gemStock {'
                             + 'display: block;'
                             + 'position: absolute;'
                             + 'left: 10px;'
                             + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/gems/all.png");'
                             + 'background-size: contain;'
                             + 'height: 30px;'
                             + 'width: 30px;'
                             + 'z-index: 30;}'
                            );

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

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

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

        injectCSS();
        displayGemStock();
    }

    function moduleSultryCoins() {
        const displaySCStock = () => {
            const sultryCoins = localStorage.getItem('HHS.sultry_coins') || 0;
            const $sc_stock = $('<div class="sc_stock">'
                                + '<span class="sultryCoins">' + sultryCoins
                                + '</span></div>')
            $('#harem_right').append($sc_stock);
        }

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

            sheet.insertRule(`${mediaDesktop} {`
                             + '.sc_stock {'
                             + 'left: 270px;'
                             + 'top: 6px;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '.sc_stock {'
                             + 'left: 240px;'
                             + 'top: 33px;}}'
                            );

            sheet.insertRule('.sultryCoins {'
                             + 'position: relative;'
                             + 'top: 2px;'
                             + 'left: 35px;}'
                            );
        }

        injectCSS();
        displaySCStock();
    }

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

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

    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, #TabsContainer a {'
                     + 'color: #008; '
                     + '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('#TabsContainer {'
                     + 'z-index: 99; '
                     + 'position: absolute; '
                     + 'bottom: 0px; '
                     + 'left: 25px; '
                     + 'width: max-content;'
                     + 'border: 1px solid rgb(156, 182, 213); '
                     + 'box-shadow: 1px -1px 1px 0px rgba(0,0,0,0.3); '
                     + 'font: normal 10px/16px Tahoma, Helvetica, Arial, sans-serif; '
                     + 'color: #000000; '
                     + 'background-color: #ffffff; '
                     + 'display: none;}'
                    );

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

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

    sheet.insertRule('#TabsContainer .subTitle {'
                     + 'padding-top: 6px; '
                     + 'font-weight: bold; '
                     + 'display: block;}'
                    );

    sheet.insertRule('#TabsContainer img {'
                     + 'width: 14px; '
                     + 'height: 14px; '
                     + 'vertical-align: text-bottom;}'
                    );

    sheet.insertRule('.StatsContent, #TabsContainer span, #TabsContainer img, #TabsContainer a, #TabsContainer b, #TabsContainer br {'
                     + 'box-sizing: content-box;}'
                    );

    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('#collect_all_container {'
                     + 'margin-top: 0px !important;}'
                    );

    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: 130px;'
                     + 'margin-left: 110px;'
                     + 'width: 235px;'
                     + 'text-decoration: none; '
                     + 'color: #24a0ff !important;}'
                    );

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

    sheet.insertRule('#harem_whole .imgStar, #harem_whole .imgMoney, #harem_whole .imgKobans {'
                     + 'background-size: 10px; '
                     + 'background-repeat: no-repeat; '
                     + 'width: 10px; '
                     + 'height: 14px; '
                     + 'display: inline-block;}'
                    );

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

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

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

    sheet.insertRule('#TabsContainer .darkness_gem, #TabsContainer .light_gem, #TabsContainer .psychic_gem, #TabsContainer .fire_gem, #TabsContainer .nature_gem, #TabsContainer .stone_gem, #TabsContainer .sun_gem, #TabsContainer .water_gem, #TabsContainer .darkness_elem, #TabsContainer .light_elem, #TabsContainer .psychic_elem, #TabsContainer .fire_elem, #TabsContainer .nature_elem, #TabsContainer .stone_elem, #TabsContainer .sun_elem, #TabsContainer .water_elem {'
                     + 'background-size: 12px;'
                     + 'background-repeat: no-repeat;'
                     + 'width: 12px;'
                     + 'height: 14px;'
                     + 'display: inline-block;}'
                    );

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


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

function moduleHaremTeamsFilter() {
    createAndAttach()
    loadFilter()


    function loadFilter () {
        const filters = JSON.parse(localStorage.getItem('filters'))

        if (filters && filters.team) {
            if ($('.girls_list > div').length) {
                doFilter(filters.team)
            } else {
                const observer = new MutationObserver(() => {
                    if ($('.girls_list > div').length) {
                        doFilter(filters.team)
                        observer.disconnect()
                    }
                })
                observer.observe($('.girls_list')[0], {childList: true})
            }
        }
    }

    function createAndAttach () {
        const $teamsButton = createTeamsButton()
        const $teamsBox = createTeamsBox()
        $('#filtering_girls .reset-filters-container').prepend($teamsButton)
        $('#harem_whole').append($teamsBox)

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

    function doFilter(girlIds) {
        const {harem, hh_show_filtered_girls} = window
        harem.haremFilter.resetFilters()
        harem.filteredGirlsIds = girlIds
        harem.filteredGirlsList = girlIds.map(id => harem.allGirls[id])

        const filterData = girlIds.reduce((a, i) => {a[i] = {};return a}, {})
        hh_show_filtered_girls('.girls_list', filterData)

        harem.resetGirlsList()
        harem.loadMoreGirlsAfterCurrent()
        harem.scrollToAndOpenGirl()

        localStorage.setItem('filters', JSON.stringify({team: girlIds}))
    }

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

    function createTeamsBox () {
        const bdsmTeams = JSON.parse(localStorage.getItem('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 => `
                    <div class="team-slot-container ${team.iconRarity}" data-id-team="${team.teamId}" data-girl-ids='${JSON.stringify(team.girls)}'>
                        <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>
                        ` : ''}
                    </div>
                `).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;}'
                    );
}

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"]').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)
    })

    teamIds.forEach(teamId => {
        const $teamGirlContainer = $(`.team-info-girls-container[data-id-team=${teamId}]`)
        const girls = []
        $teamGirlContainer.find('.team-member-container').each((i, girl) => {
            const girlId = parseInt($(girl).data('girl-id'), 10)
            if (girlId) {
                girls.push(girlId)
            }
        })
        teamsDict[teamId].girls = girls
    })

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

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

        $('#harem_left .general_girls_console').after('<div class="nb_girls">' + window.GT.design.Girls + ' : '
                                                      + '<span id="girls_nb" style="color: #fff">' + nThousand(parseInt(window.harem.filteredGirlsList.length, 10)) + '</span></div>');

        if (window.harem.filteredGirlsList.length > 0) {
            window.harem.filteredGirlsList.forEach((girl) => {if (girl.shards >= 100) {
                filteredGirlsList.push(girl.id_girl);
                filteredAvatarList.push(girl.avatar);
            }});
        }
        else {
            window.harem.girlsBeforeSelected.forEach((girl) => {if (girl.shards >= 100) {
                filteredGirlsList.push(girl.id_girl);
                filteredAvatarList.push(girl.avatar);
            }});
            filteredGirlsList.push(window.harem.preselectedGirlId);
            window.harem.girlsAfterSelected.forEach((girl) => {if (girl.shards >= 100) {
                filteredGirlsList.push(girl.id_girl);
                filteredAvatarList.push(girl.avatar);
            }});
        }
        localStorage.setItem('filteredGirlsList', JSON.stringify(filteredGirlsList));
        localStorage.setItem('filteredAvatarList', JSON.stringify(filteredAvatarList));

        new MutationObserver(() => {
            let filteredGirlsList = [];
            let filteredAvatarList = [];
            $('#girls_nb')[0].textContent = nThousand(parseInt(window.harem.filteredGirlsList.length, 10));
            if (window.harem.filteredGirlsList.length > 0) {
                window.harem.filteredGirlsList.forEach((girl) => {if (girl.shards >= 100) {
                    filteredGirlsList.push(girl.id_girl);
                    filteredAvatarList.push(girl.avatar);
                }});
            }
            else {
                window.harem.girlsBeforeSelected.forEach((girl) => {if (girl.shards >= 100) {
                    filteredGirlsList.push(girl.id_girl);
                    filteredAvatarList.push(girl.avatar);
                }});
                filteredGirlsList.push(window.harem.preselectedGirlId);
                window.harem.girlsAfterSelected.forEach((girl) => {if (girl.shards >= 100) {
                    filteredGirlsList.push(girl.id_girl);
                    filteredAvatarList.push(girl.avatar);
                }});
            }
            localStorage.setItem('filteredGirlsList', JSON.stringify(filteredGirlsList));
            localStorage.setItem('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 .general_girls_console {'
                         + 'margin-bottom: 0px !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;}}'
                        );
    }, 500);
}

if (CurrentPage.includes('girl')) {
    setTimeout(function() {
        $('.girl-leveler-container .girl-section .girl-lower-info .girl-resource-section .bar-section .top-text').append('<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>')

        const idCurrentGirl = parseInt(window.girl.id_girl, 10);
        const filteredGirlsList = JSON.parse(localStorage.getItem('filteredGirlsList'));
        const filteredAvatarList = JSON.parse(localStorage.getItem('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];
        let currentWindow = (window.location.search.indexOf('experience') != -1) ? 'experience' : 'affection';

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

        if ($('.girl-leveler-container .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($('.girl-leveler-container .girl-section .girl-lower-info .girl-resource-section .girl_exp_left .xp-next-level')[0], {childList: true})
        }

        new MutationObserver(() => {
            currentWindow = (window.location.search.indexOf('experience') != -1) ? 'experience' : 'affection';
            $('#previous_girl')[0].attributes.href.value = '/girl/' + idPreviousGirl + '?resource=' + currentWindow;
            $('#next_girl')[0].attributes.href.value = '/girl/' + idNextGirl + '?resource=' + currentWindow;
            $('.girl-leveler-container .girl-section .girl-lower-info .girl-resource-section .present-block').append('<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 ($('.girl-leveler-container .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($('.girl-leveler-container .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.prev {'
                         + 'left: 10px;}'
                        );

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

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

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

        sheet.insertRule('.overlayed-title {'
                         + 'position: absolute;'
                         + 'margin-top: -11px !important;}'
                        );
    }, 500);
}


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

function moduleLeague() {
    if (CurrentPage.includes('tower-of-fame')) {

        var playersTotal;
        var challengesLeft;
        var challengesPossibleMinutes;
        var challengesPossible;
        var challengesDone = 0;
        var playerCurrentParse;
        var playerCurrentPos;
        var playerCurrentPoints;
        var maxDemoteParse;
        var maxDemotePoints;
        var maxDemoteDiff;
        var maxDemoteDisplay;
        var textDemote;
        var maxStagnateParse;
        var maxStagnatePoints;
        var maxStagnateDiff;
        var maxStagnateDisplay;
        var textStagnate;
        var minTop4Parse;
        var minTop4Points;
        var minTop4Diff;
        var minTop4Display;
        var textTop4;
        var minTop15Points;
        var textTop15;
        var minTop15Display;
        var minTop30Parse;
        var minTop30Points;
        var minTop30Diff;
        var minTop30Display;
        var textTop30;
        var avgScore;
        var scoreExpected;
        var playerSelectedPos;
        var playerSelectedPoints;
        var top4Points;
        var top5Points;
        var top15Points;
        var top16Points;
        var top30Points;
        var top31Points;
        var topDemotePoints;
        var topNonDemotePoints;

        var	includeBoard = false;

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

        let heroLeagueRank = $('.leagues_table.lead_table .lead_table_view .leadTable .personal_highlight')[0].children[0].innerText;
        localStorage.setItem('leagueRankData', JSON.stringify({'league_tag': window.window.league_tag, 'league_rank': heroLeagueRank}));


        challengesPossibleMinutes = parseInt(Math.floor(window.season_end_at/60), 10);
        challengesPossible = (window.Hero.energies.challenge.amount != window.Hero.energies.challenge.max_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 = $('.leagues_table .lead_table_view tbody.leadTable')[0].children.length;

        for(var i=0; i<playersTotal; i++) {
            var playerData = $('.leagues_table .lead_table_view tbody.leadTable')[0].children[i];
            var fightsDone = 0;
            if (playerData.className.indexOf('selected-player-leagues') != -1) {
                var fightsData = $('.leagues_table .lead_table_view tbody.leadTable .selected-player-leagues div.wrapper')[0].children;
                for (var j=0; j<fightsData.length; j++){
                    if (fightsData[j].className != 'result') fightsDone ++;
                }
                playerSelectedPos = parseInt(window.playerLeaguesData.rank, 10);
                playerSelectedPoints = parseInt(window.playerLeaguesData.points.replace(/\D/g, ''), 10);

                switch (playerSelectedPos) {
                    case 4:
                        top4Points = playerSelectedPoints;
                        break;
                    case 5:
                        top5Points = playerSelectedPoints;
                        break;
                    case 15:
                        top15Points = playerSelectedPoints;
                        break;
                    case 16:
                        top16Points = playerSelectedPoints;
                        break;
                    case 30:
                        top30Points = playerSelectedPoints;
                        break;
                    case 31:
                        top31Points = playerSelectedPoints;
                        break;
                    case (playersTotal-14):
                        topDemotePoints = playerSelectedPoints;
                        break;
                    case (playersTotal-15):
                        topNonDemotePoints = playerSelectedPoints;
                        break;
                }
            }
            else {
                var fightsStr = playerData.children[3].innerText;
                var pos = parseInt(playerData.children[0].innerText, 10);
                var points = parseInt(playerData.children[4].innerText.replace(/\D/g, ''), 10);

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

                if (fightsStr == '-') {
                    fightsDone = 0;
                    playerCurrentParse = playerData;
                }
                else {
                    fightsDone = parseInt(fightsStr.substring(0,1), 10);
                }
            }
            challengesDone += fightsDone;
        }

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

        playerCurrentPos = parseInt(playerCurrentParse.children[0].innerText, 10);
        playerCurrentPoints = parseInt(playerCurrentParse.children[4].innerText.replace(/\D/g, ''), 10);

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

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

        if (playerCurrentPos > (playersTotal - 15)) {
            maxDemotePoints = topNonDemotePoints;
            maxDemoteDiff = maxDemotePoints - playerCurrentPoints;
            if (playerCurrentPoints == 0 && maxDemotePoints == 0) {
                maxDemoteDisplay = '±' + nThousand(maxDemoteDiff);
                textDemote = labels.demote_holdzero;
            }
            else {
                maxDemoteDisplay = '+' + nThousand(maxDemoteDiff);
                textDemote = labels.demote_up;
            }
        }
        else {
            maxDemotePoints = topDemotePoints
            maxDemoteDiff = maxDemotePoints - playerCurrentPoints;
            if (playerCurrentPoints == 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 (playerCurrentPos > 15) {
            maxStagnatePoints = top15Points;
            maxStagnateDiff = maxStagnatePoints - playerCurrentPoints;
            minTop15Points = maxStagnatePoints + 1;
            if (playerCurrentPoints == 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 - playerCurrentPoints;
            minTop15Points = top16Points;
            if (playerCurrentPoints == 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 (playerCurrentPos > 30) {
            minTop30Points = top30Points + 1;
            minTop30Diff = minTop30Points - playerCurrentPoints;
            if (minTop30Diff > 0) {
                minTop30Display = '+' + (nThousand(minTop30Diff));
                textTop30 = labels.top30_up;
            }
            else {
                minTop30Display = nThousand(minTop30Diff);
                textTop30 = labels.top30_hold;
            }
        }
        else {
            minTop30Points = top31Points;
            minTop30Diff = minTop30Points - playerCurrentPoints;
            if (minTop30Diff < 0) {
                minTop30Display = nThousand(minTop30Diff);
                textTop30 = labels.top30_hold;
            }
            else {
                minTop30Display = '+' + (nThousand(minTop30Diff));
                textTop30 = labels.top30_hold;
            }
        }

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

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

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

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

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

        //CSS
        sheet.insertRule('.scriptLeagueInfo {'
                         + 'font-size: 13px; '
                         + 'display: block; '
                         + 'float: right;}'
                        );

        sheet.insertRule(`${mediaDesktop} {`
                         + '.scriptLeagueInfo {'
                         + 'position: relative;'
                         + 'bottom: 3px;'
                         + 'margin-right: 3px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '.scriptLeagueInfo {'
                         + 'margin-right: 345px;}}'
                        );

        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,.9); '
                         + '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('.kobanWinningsTooltip {'
                         + 'top: 20px; '
                         + 'margin-left: -95px;}'
                        );

        sheet.insertRule('.kobanWinnings:hover .kobanWinningsTooltip {'
                         + 'visibility: visible;}'
                        );

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

        sheet.insertRule('.averageScore:hover .averageScoreTooltip {'
                         + 'visibility: visible;}'
                        );

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

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

        sheet.insertRule('.maxStagnateTooltip {'
                         + 'max-width: 190px; '
                         + 'top: 20px; '
                         + 'margin-left: -115px;}'
                        );

        sheet.insertRule('.maxStagnate:hover .maxStagnateTooltip {'
                         + 'visibility: visible;}'
                        );

        sheet.insertRule('.minTop4Tooltip {'
                         + 'max-width: 190px; '
                         + 'top: 20px; '
                         + 'margin-left: -115px;}'
                        );

        sheet.insertRule('.minTop4:hover .minTop4Tooltip {'
                         + 'visibility: visible;}'
                        );

        sheet.insertRule('.minTop15Tooltip {'
                         + 'max-width: 190px; '
                         + 'top: 20px; '
                         + 'margin-left: -115px;}'
                        );

        sheet.insertRule('.minTop15:hover .minTop15Tooltip {'
                         + 'visibility: visible;}'
                        );

        sheet.insertRule('.minTop30Tooltip {'
                         + 'max-width: 190px; '
                         + 'top: 20px; '
                         + 'margin-left: -111px;}'
                        );

        sheet.insertRule('.minTop30:hover .minTop30Tooltip {'
                         + 'visibility: visible;}'
                        );

        sheet.insertRule('.minTop45Tooltip {'
                         + 'max-width: 190px; '
                         + 'top: 20px; '
                         + 'margin-left: -111px;}'
                        );

        sheet.insertRule('.minTop45:hover .minTop45Tooltip {'
                         + 'visibility: visible;}'
                        );

        sheet.insertRule('.maxDemoteTooltip {'
                         + 'min-width: 155px; '
                         + 'max-width: 170px; '
                         + 'top: 20px; '
                         + 'margin-left: -100px;}'
                        );

        sheet.insertRule('.maxDemote:hover .maxDemoteTooltip {'
                         + 'visibility: visible;}'
                        );

        sheet.insertRule('#leagues_middle .leagues_middle_header .leagues_girl_reward_container {'
                         + 'top: -44px !important;'
                         + 'right: 10px !important;}'
                        );

        sheet.insertRule('[hero-leagues-fixed-bar] [main-row] {'
                         + 'margin-top: -7px;}'
                        );

        sheet.insertRule('[hero-leagues-fixed-bar] [second-row] {'
                         + 'margin-top: 0;}'
                        );

        sheet.insertRule('[hero-leagues-fixed-bar] [second-row] .balance-element {'
                         + 'margin-bottom: 0px !important;'
                         + 'margin-top: 0px !important;}'
                        );

        sheet.insertRule('[hero-leagues-fixed-bar] [second-row] .blue_button_L {'
                         + 'height: 80%;}'
                        );

        sheet.insertRule('[hero-leagues-fixed-bar] {'
                         + 'margin-bottom: 0 !important;}'
                        );

        sheet.insertRule(`${mediaMobile + ' and (orientation: portrait)'} {`
                         + '#leagues_middle > .leagues_table.lead_table > .lead_table_view {'
                         + 'height: 122% !important;}}'
                        );

        sheet.insertRule(`${mediaMobile + ' and (orientation: landscape)'} {`
                         + '#leagues_middle > .leagues_table.lead_table > .lead_table_view {'
                         + 'height: 77% !important;}}'
                        );

        sheet.insertRule(`${mediaMobile + ' and (orientation: portrait)'} {`
                         + '.canvas {'
                         + 'height: 135% !important;}}'
                        );

        sheet.insertRule(`${mediaMobile + ' and (orientation: landscape)'} {`
                         + '.canvas {'
                         + 'height: 103% !important;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#leagues_middle .theme-container .theme-element {'
                         + 'margin-left: 20% !important;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '[page="leaderboard"] .canvas .base_block.lead_wrapper .leagues-btn-mobile-refill-multi {'
                         + 'transform: scale(0.8);'
                         + 'margin-top: 9px;'
                         + 'margin-right: 10px;}}'
                        );


        function removeBeatenOpponents() {
            var board = document.getElementsByClassName("leadTable")[0];
            if(!board) return;
            var opponents = board.getElementsByTagName("tr");
            for (var i=0; i<opponents.length; i++) {
                try {
                    const playerId = $(opponents[i]).attr('sorting_id');
                    if(window.leagues_list.find(({id_player}) => id_player === playerId).nb_challenges_played === "3" && opponents[i].className.indexOf('selected-player-leagues') == -1){
                        opponents[i].style.display="none";
                    }
                } catch(e) {}
            }
            $('.lead_table_view').getNiceScroll().resize()
        }

        function displayBeatenOpponents() {
            var board = document.getElementsByClassName("leadTable")[0];
            if(!board) return;
            var opponents = board.getElementsByTagName("tr");
            for (var i=0; i<opponents.length; i++) {
                try {
                    const playerId = $(opponents[i]).attr('sorting_id');
                    if(window.leagues_list.find(({id_player}) => id_player === playerId).nb_challenges_played === "3"){
                        opponents[i].style.display="";
                    }
                } catch(e) {}
            }
            $('.lead_table_view').getNiceScroll().resize()
        }

        let hidden = loadSetting('hide_beaten');
        $(".league_end_in").append('<button id="beaten_opponents" class="blue_text_button"><span id="hide_beaten"></span></button>');

        if (hidden == 1) {
            removeBeatenOpponents();
            $('#hide_beaten').html(labels.display);
        }
        else {
            $('#hide_beaten').html(labels.hide);
        }

        let button = document.querySelector('#beaten_opponents');
        button.addEventListener('click', function(){
            if (hidden == 0) {
                removeBeatenOpponents();
                hidden = 1;
                localStorage.setItem('HHS.hide_beaten', 1);
                $('#hide_beaten').html(labels.display);
            }
            else {
                displayBeatenOpponents();
                hidden = 0;
                localStorage.setItem('HHS.hide_beaten', 0);
                $('#hide_beaten').html(labels.hide);
            }
        });

        let sort_by = document.querySelectorAll('span[sort_by]');
        for (var sort of sort_by) {
            sort.addEventListener('click', function() {
                if (hidden == 1) removeBeatenOpponents();
                displayLeaguePlayersInfo();
            });
        }


        sheet.insertRule(`${mediaDesktop} {`
                         + '#beaten_opponents {'
                         + 'position: absolute;'
                         + 'height: 26px;'
                         + 'top: -39px;'
                         + 'right: 519px;}}'
                        );

        sheet.insertRule(`${mediaDesktop} {`
                         + '#hide_beaten {'
                         + 'position: relative;'
                         + 'top: -5px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#beaten_opponents {'
                         + 'position: absolute;'
                         + 'height: 26px;'
                         + 'top: -10px;'
                         + 'right: 700px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '#hide_beaten {'
                         + 'position: relative;'
                         + 'top: -5px;}}'
                        );


        function displayLeaguePlayersInfo() {
            if (localStorage.getItem('newLeagueResults') == null) {
                localStorage.removeItem('leagueResults');
                localStorage.removeItem('pointHistory');
                localStorage.setItem('newLeagueResults', 1)
            }

            let player = window.playerLeaguesData.id_fighter;
            let points;
            try{
                points = JSON.parse(localStorage.getItem('pointHistory'))[player].points;
            }catch(e){
                points = [];
            }
            for(let i=0;i<3;i++){
                let result = $('.result')[i];
                if(result.innerText != ""){
                    result.innerText = points[i] || '?';
                }
            }

            const data = JSON.parse(localStorage.getItem('leagueResults')) || {};
            const pointHistory = JSON.parse(localStorage.getItem('pointHistory')) || {};
            let pointHistoryChanged = false
            for(let i=0; i<playersTotal; i++) {
                let playerData = $('.leagues_table .lead_table_view tbody.leadTable tr:nth-child(' + (i+1) + ')');
                let playerId = playerData.attr('sorting_id');
                let player = data[playerId];

                if (player) {
                    if (playerData.find('.classLeague').length===0) {
                        var playerClass = player.class;

                        switch (playerClass) {
                            case 1:
                                playerData.find('.square-avatar-wrapper').append($('<img class="classLeague" src="' + window.IMAGES_URL + '/caracs/hardcore.png">'));
                                break;

                            case 2:
                                playerData.find('.square-avatar-wrapper').append($('<img class="classLeague" src="' + window.IMAGES_URL + '/caracs/charm.png">'));
                                break;

                            case 3:
                                playerData.find('.square-avatar-wrapper').append($('<img class="classLeague" src="' + window.IMAGES_URL + '/caracs/knowhow.png">'));
                                break;
                        }
                    }
                }

                if (!playerData.hasClass('personal_highlight')) {
                    let points;
                    const leaguesListPlayer = window.leagues_list.find(({id_player}) => id_player===playerId)
                    try{
                        points = pointHistory[playerId].points;

                    } catch {
                        points=[];
                    }
                    let pointsText='';
                    const showIndividualPoints = localStorage.getItem('leagueTableShowIndividual') === "1"
                    if (showIndividualPoints) {
                        pointsText = [0,1,2].map(j => {
                            if(j<parseInt(leaguesListPlayer.nb_challenges_played)){
                                return points[j] || '?';
                            }
                            return '-';
                        }).join('/')
                    } else {
                        pointsText = `${leaguesListPlayer.nb_challenges_played}/3`
                    }
                    if (!playerData.hasClass('selected-player-leagues')) {
                        playerData[0].children[3].innerText=pointsText
                    }
                }
            }
            if (pointHistoryChanged) {
                localStorage.setItem('pointHistory', JSON.stringify(pointHistory))
            }


            sheet.insertRule(`${mediaDesktop} {`
                             + '.classLeague {'
                             + 'position: relative !important;'
                             + 'height: 17px !important;'
                             + 'width: 17px !important;'
                             + 'left: 25px !important;'
                             + 'border: none !important;}}'
                            );

            sheet.insertRule(`${mediaMobile} {`
                             + '.classLeague {'
                             + 'position: relative !important;'
                             + 'height: 25px !important;'
                             + 'width: 25px !important;'
                             + 'left: 45px !important;'
                             + 'border: none !important;}}'
                            );
        }


        //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('leagueTime');
            if (time_results == null) {
                time_results = date_end_league;
                localStorage.setItem('leagueTime', time_results);
                localStorage.setItem('leagueResults', null);
            }
            //Next Thursday after DST at 12:00 UTC
            if (time_results == 1680177600) {
                time_results = 1680174000;
                localStorage.setItem('leagueTime', time_results);
            }

            if (current_date_ts > time_results) {
                localStorage.setItem('oldLeagueResults', localStorage.getItem('leagueResults'));
                localStorage.setItem('oldLeagueTime', localStorage.getItem('leagueTime'));
                localStorage.setItem('oldLeaguePlayers', localStorage.getItem('leaguePlayers'));
                localStorage.setItem('oldLeagueScore', localStorage.getItem('leagueScore'));
                localStorage.setItem('oldLeagueUnknown', localStorage.getItem('leagueUnknown'));
                localStorage.removeItem('leagueResults');
                localStorage.removeItem('pointHistory')
                localStorage.setItem('leagueTime', date_end_league);
                localStorage.removeItem('leagueScore');
                localStorage.removeItem('leagueUnknown');
            }

            let data = JSON.parse(localStorage.getItem('leagueResults')) || {};
            let player = $('#leagues_right .player_block .avatar_border > img').attr('onclick').slice(22,-3);
            let spec = $('#leagues_right .player_block .icon').attr('carac').slice(5);
            let results = $('#leagues_right .challenge .result');
            let nb_victories = 0;
            let nb_defeats = 0;

            for(let i = 0; i < results.length; ++i) {
                let result = results.eq(i);

                if(result.text() == window.GT.design.leagues_won_letter) ++nb_victories;
                if(result.text() == window.GT.design.leagues_lost_letter) ++nb_defeats;
            }

            data[player] = {
                victories: nb_victories,
                defeats: nb_defeats,
                class: parseInt(spec, 10),
            };

            localStorage.setItem('leagueResults', JSON.stringify(data));

            calculateVictories();
        }

        function calculateVictories() {
            let data = JSON.parse(localStorage.getItem('leagueResults')) || {};
            let players = $('#leagues_middle .leadTable tr');
            let nb_players = players.length;
            let nb_opponents = nb_players-1;
            localStorage.setItem('leaguePlayers', nb_opponents);

            let fightsPlayed = 0;
            for (var i=0; i<nb_players; i++) {
                var played = 0;
                if (players[i].className.indexOf('lead_table_default') != -1) {
                    if ($('.lead_table_default .result').length != 0) {
                        played = parseInt($('.lead_table_default .won').length + $('.lead_table_default .lost').length, 10);
                    }
                    else {
                        played = parseInt(players[i].children[3].innerText.split('/')[0], 10) || 0;
                    }
                }
                else {
                    played = parseInt(players[i].children[3].innerText.split('/')[0], 10) || 0;
                }
                fightsPlayed += played;
            }

            let tot_victory = 0;
            let tot_defeat = 0;
            for(let key in data) {
                tot_victory += data[key].victories;
                tot_defeat += data[key].defeats;
            }

            let tot_notPlayed = 3*nb_opponents - fightsPlayed;
            let nb_unknown = fightsPlayed - tot_victory - tot_defeat;
            localStorage.setItem('leagueUnknown', nb_unknown);

            $('span.possibleChallenges span.scriptLeagueInfoTooltip.possibleChallengesTooltip span#leagueStats').empty();
            $('span.scriptLeagueInfoTooltip.possibleChallengesTooltip').append('<span id="leagueStats"><BR><BR><u>' + labels.current_league + '</u>'
                                                                               + '<br />'
                                                                               + '<BR>' + labels.victories + ' : ' + tot_victory + '/' + 3*nb_opponents
                                                                               + '<BR>' + labels.defeats + ' : ' + tot_defeat + '/' + 3*nb_opponents
                                                                               + '<BR>' + labels.unknown + ' : ' + nb_unknown + '/' + 3*nb_opponents
                                                                               + '<BR>' + labels.notPlayed + ' : ' + tot_notPlayed + '/' + 3*nb_opponents
                                                                               + '</span>');

            $('span.possibleChallengesMobile span.scriptMobileLeagueInfoTooltip.possibleChallengesMobileTooltip span#leagueStatsMobile').empty();
            $('span.scriptMobileLeagueInfoTooltip.possibleChallengesMobileTooltip').append('<span id="leagueStatsMobile"><BR><BR><u>' + labels.current_league + '</u>'
                                                                                           + '<br />'
                                                                                           + '<BR>' + labels.victories + ' : ' + tot_victory + '/' + 3*nb_opponents
                                                                                           + '<BR>' + labels.defeats + ' : ' + tot_defeat + '/' + 3*nb_opponents
                                                                                           + '<BR>' + labels.unknown + ' : ' + nb_unknown + '/' + 3*nb_opponents
                                                                                           + '<BR>' + labels.notPlayed + ' : ' + tot_notPlayed + '/' + 3*nb_opponents
                                                                                           + '</span>');


            let old_data = JSON.parse(localStorage.getItem('oldLeagueResults')) || {};
            let old_nb_opponents = JSON.parse(localStorage.getItem('oldLeaguePlayers')) || 0;
            let old_nb_unknown = localStorage.getItem('oldLeagueUnknown');
            let old_score = JSON.parse(localStorage.getItem('oldLeagueScore')) || {};

            let old_tot_victory = 0;
            let old_tot_defeat = 0;

            let old_points = old_score.points || 0;
            let old_avg = old_score.avg || 0;

            for(let old_key in old_data) {
                old_tot_victory += old_data[old_key].victories;
                old_tot_defeat += old_data[old_key].defeats;
            }

            let old_tot_notPlayed = 3*old_nb_opponents - old_tot_victory - old_tot_defeat - old_nb_unknown;

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

            if (localStorage.getItem('oldLeagueTime') != null) {
                $('span.possibleChallenges span.scriptLeagueInfoTooltip.possibleChallengesTooltip span#oldLeagueStats').empty();
                $('span.scriptLeagueInfoTooltip.possibleChallengesTooltip').append('<span id="oldLeagueStats"><BR>_______________________'
                                                                                   + '<BR><BR>' + labels.league_finished + old_date_end_league
                                                                                   + '<br />'
                                                                                   + '<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.opponents + ' : ' + old_nb_opponents
                                                                                   + '<BR>' + labels.leaguePoints + ' : ' + old_points
                                                                                   + '<BR>' + labels.avg + ' : ' + nThousand(old_avg)
                                                                                   + '</span>');

                $('span.possibleChallengesMobile span.scriptMobileLeagueInfoTooltip.possibleChallengesMobileTooltip span#oldLeagueStatsMobile').empty();
                $('span.scriptMobileLeagueInfoTooltip.possibleChallengesMobileTooltip').append('<span id="oldLeagueStatsMobile"><BR>_______________________'
                                                                                               + '<BR><BR>' + labels.league_finished + old_date_end_league
                                                                                               + '<br />'
                                                                                               + '<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.opponents + ' : ' + old_nb_opponents
                                                                                               + '<BR>' + labels.leaguePoints + ' : ' + old_points
                                                                                               + '<BR>' + labels.avg + ' : ' + nThousand(old_avg)
                                                                                               + '</span>');
            }
        }
        saveVictories();
        displayLeaguePlayersInfo();

        var observeCallback = function() {
            saveVictories();
            displayLeaguePlayersInfo();
        }

        let observer = new MutationObserver(observeCallback);
        let leagues_right = document.getElementById('leagues_right');
        observer.observe(leagues_right, {attributes: false, childList: true, subtree: false});

        const leagueTableShowIndividualCurrent = localStorage.getItem('leagueTableShowIndividual')
        const individualDisplaySwitchOptions = [
            {label: '22/21/-', value: "1"},
            {label: '2/3', value: "0"}
        ].map(option => $(`
            <label>
                <input type="radio" name="leagueTableShowIndividual" value="${option.value}" ${option.value === leagueTableShowIndividualCurrent ? 'checked' : ''} />
                <span>${option.label}</span>
            </label>
        `.replace(/(\n|    )/g, '')).change((e) => {
            localStorage.setItem('leagueTableShowIndividual', e.target.value)
            displayLeaguePlayersInfo()
        }))
        const individualDisplaySwitch = $('<div class="individualDisplaySwitch"></div>')
        individualDisplaySwitchOptions.forEach((option, i) => {
            if (i > 0) {
                individualDisplaySwitch.append('&middot;')
            }
            individualDisplaySwitch.append(option)
        })

        $('.league_end_in').append(individualDisplaySwitch)


        sheet.insertRule('.individualDisplaySwitch {'
                         + 'position: absolute;}'
                        );
        sheet.insertRule('.individualDisplaySwitch input {'
                         + 'display: none;}'
                        );
        sheet.insertRule('.individualDisplaySwitch input+span {'
                         + 'color: #d08467;'
                         + 'padding: 5px;'
                         + 'cursor: pointer;}'
                        );
        sheet.insertRule('.individualDisplaySwitch input:checked+span, .individualDisplaySwitch input:hover+span {'
                         + 'color: #fff;}'
                        );
        sheet.insertRule(`${mediaDesktop} {`
                         + '.individualDisplaySwitch {'
                         + 'top: -33px;'
                         + 'left: 90px !important;}}'
                        );
        sheet.insertRule(`${mediaMobile} {`
                         + '.individualDisplaySwitch {'
                         + 'top: 28px;'
                         + 'left: 335px;'
                         + 'font-size: 16px;}}'
                        );
        sheet.insertRule(`${mediaDesktop} {`
                         + '.record_league {'
                         + 'left: 245px !important;}'
                        );
        sheet.insertRule(`${mediaMobile} {`
                         + '.record_league {'
                         + 'top: 20px !important;}'
                        );
        sheet.insertRule(`${mediaMobile} {`
                         + '.record_league > span#this_week {'
                         + 'left: 50px !important;}'
                        );
    }

    if (CurrentPage.includes('battle') && !CurrentPage.includes('pre-battle')) {
        $(document).ajaxComplete(function(evt, xhr, opt) {
            const searchParams = new URLSearchParams(opt.data)
            if(searchParams.get('action') === 'do_battles_leagues') {
                if(!xhr.responseText.length) return;

                const response = JSON.parse(xhr.responseText)

                if(!response || !response.success) return;

                const player = searchParams.get('id_opponent')
                const points = response.rewards.heroChangesUpdate.league_points

                const pointHist = JSON.parse(localStorage.getItem('pointHistory')) || {}
                try{
                    pointHist[player].points.push(points)
                } catch(e) {
                    pointHist[player]={points:[points]}
                }
                localStorage.setItem('pointHistory', JSON.stringify(pointHist))
            }
        })
    }
}

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

function moduleSim() {
    function calculatePower() {
        // INIT
        const opponentId = window.playerLeaguesData.id_fighter
        let playerCrit
        let playerAtk
        let playerDef
        let playerEgo
        if (opponentId && window.caracs_per_opponent && window.caracs_per_opponent[opponentId]) {
            if (window.caracs_per_opponent[opponentId].remaining_ego) {
                ({
                    chance: playerCrit,
                    damage: playerAtk,
                    defense: playerDef,
                    remaining_ego: playerEgo,
                } = window.caracs_per_opponent[opponentId])
            }
            else {
                ({
                    chance: playerCrit,
                    damage: playerAtk,
                    defense: playerDef,
                    total_ego: playerEgo,
                } = window.caracs_per_opponent[opponentId])
            }
        } else {
            ({
                chance: playerCrit,
                damage: playerAtk,
                defense: playerDef,
                remaining_ego: playerEgo,
            } = window.heroLeaguesData)
        }
        const {
            team: playerTeam
        } = window.heroLeaguesData

        const playerSynergies = playerTeam.synergies;
        const playerElements = playerTeam.theme_elements.map(({type}) => type);

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

        const {
            chance: opponentCrit,
            damage: opponentAtk,
            defense: opponentDef,
            remaining_ego: opponentEgo,
            team: opponentTeam
        } = window.playerLeaguesData;

        const opponentSynergies = opponentTeam.synergies;
        const opponentElements = opponentTeam.theme_elements.map(({type}) => type);

        const opponentBonuses = {
            critDamage: opponentSynergies.find(({element: {type}})=>type==='fire').bonus_multiplier,
            critChance: opponentSynergies.find(({element: {type}})=>type==='stone').bonus_multiplier,
            defReduce: 0,
            healOnHit: opponentSynergies.find(({element: {type}})=>type==='water').bonus_multiplier
        };

        const dominanceBonuses = calculateDominationBonuses(playerElements, opponentElements);

        let player = {
            hp: playerEgo,
            dmg: playerAtk - opponentDef,
            critchance: calculateCritChanceShare(playerCrit, opponentCrit) + dominanceBonuses.player.chance + playerBonuses.critChance,
            bonuses: playerBonuses
        };

        let opponent = {
            hp: opponentEgo,
            dmg: opponentAtk - playerDef,
            critchance: calculateCritChanceShare(opponentCrit, playerCrit) + dominanceBonuses.opponent.chance + opponentBonuses.critChance,
            name: $('#leagues_right .player_block .title').text(),
            bonuses: opponentBonuses
        };

        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>';

        $('.matchRating').remove();

        const $rating = $(`<div class="matchRating" tooltip="" style="color:${pointGrade[Math.round(expectedValue)]};" hh_title="${probabilityTooltip}">${(100*win).toFixed(2)}% / ${expectedValue.toFixed(1)}</div>`)
        $('#leagues_right .average-lvl').append($rating);
        $('.lead_table_default > td:nth-child(1) > div:nth-child(1) > div:nth-child(2) .level').append($rating);
    }

    calculatePower();

    // Refresh sim on new opponent selection (Credit: BenBrazke)
    var opntName;
    $('.leadTable').click(function() {
        opntName=''
    })

    function waitOpnt() {
        setTimeout(function() {
            if (JSON.parse($('#leagues_right .team-hexagon div:nth-child(2) div:nth-child(2) .team-member img').attr('data-new-girl-tooltip'))) {
                sessionStorage.setItem('opntName', opntName);
                calculatePower();
            }
            else {
                waitOpnt()
            }
        }, 50);
    }

    var observeCallback = function() {
        var opntNameNew = $('#leagues_right .player_block .title')[0].innerHTML
        if (opntName !== opntNameNew) {
            opntName = opntNameNew;
            waitOpnt();
        }
    }

    let observer = new MutationObserver(observeCallback);
    let leagues_right = document.getElementById('leagues_right');
    observer.observe(leagues_right, {attributes: false, childList: true, subtree: false});

    //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: 75px;'
                     + 'text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000;'
                     + 'line-height: 0px;'
                     + 'width: 150px;'
                     + 'font-size: 18px;}}'
                    );

    sheet.insertRule('.average-lvl {'
                     + 'text-align: center;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.average-lvl {'
                     + 'width: 160px;}}'
                    );

    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('.gridWrapper {'
                     + 'margin-top: -42px;'
                     + 'display: grid;'
                     + 'grid-template-columns: 1fr 1fr;'
                     + 'grid-gap: 24px;'
                     + 'z-index: 0;}'
                    );

    sheet.insertRule('#leagues_right .player_block .team-hexagon-container .icon {'
                     + 'z-index: 1;}'
                    );

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

// == Helper functions for probability calculations ==
// Calculate the chance to get a sequence with given amount of crits and non-crits at a given critchance
function calculateChance(crits, hits, critchance) {
    // returns (crits+hits)!/(crits!*hits!) * critchance^crits * (1-critchance)^hits
    let binCoeffNumerator = 1;
    for(let i = crits+hits; i>crits; i--) {
        binCoeffNumerator *= i;
    }

    let binCoeffDenominator = 1;
    for(let j = 1; j<=hits; j++) {
        binCoeffDenominator *= j;
    }

    return binCoeffNumerator/binCoeffDenominator * Math.pow(critchance, crits) * Math.pow(1-critchance, hits);
}
// Calculate the chance to finish a match with a crit even though a normal hit would have been enough
function calculateOverkillChance(crits, hits, critchance) {
    if (hits==0) return 0;
    return calculateChance(crits, hits-1, critchance)*critchance;
}
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 calculateSynergiesFromTeamMemberElements(elements) {
    const counts = countElementsInTeam(elements)

    // Only care about those not included in the stats already: fire, stone, sun and water
    // Assume max harem synergy
    const girlDictionary = (typeof(localStorage.HHPNMap) == "undefined") ? new Map(): new Map(JSON.parse(localStorage.HHPNMap));
    const girlCount = girlDictionary.size || 800
    const girlsPerElement = Math.min(girlCount / 8, 100)

    return {
        critDamage: (0.0035 * girlsPerElement) + (0.1 * counts.fire),
        critChance: (0.0007 * girlsPerElement) + (0.02 * counts.stone),
        defReduce:  (0.0007 * girlsPerElement) + (0.02 * counts.sun),
        healOnHit:  (0.001 * girlsPerElement) + (0.03 * counts.water)
    }
}

function calculateThemeFromElements(elements) {
    const counts = countElementsInTeam(elements)

    const theme = []
    Object.entries(counts).forEach(([element, count]) => {
        if (count >= 3) {
            theme.push(element)
        }
    })
    return theme
}

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

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

    const setup = x => {
        x.critMultiplier = 2 + x.bonuses.critDamage;
        x.dmg = Math.max(0, x.dmg);
        x.baseAttack = {
            probability: 1 - x.critchance,
            damageAmount: Math.ceil(x.dmg),
            healAmount: Math.ceil(x.dmg * x.bonuses.healOnHit)
        };
        x.critAttack = {
            probability: x.critchance,
            damageAmount: Math.ceil(x.dmg * x.critMultiplier),
            healAmount: Math.ceil(x.dmg * x.critMultiplier * x.bonuses.healOnHit)
        };
        x.hp = Math.ceil(x.hp);
    }

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

    this.cache = {};
    this.runs = 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 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 = this.player.baseAttack;
        const baseAtkResult = playerAttack(playerHP, opponentHP, baseAtk, turns);
        const critAtk = this.player.critAttack;
        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) {
        // damage
        opponentHP -= attack.damageAmount;

        // heal on hit
        playerHP += attack.healAmount;
        playerHP = Math.min(playerHP, this.player.hp);

        // check win
        if (opponentHP <= 0) {
            const point = 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 = this.opponent.baseAttack;
        const baseAtkResult = opponentAttack(playerHP, opponentHP, baseAtk, turns);
        const critAtk = this.opponent.critAttack;
        const critAtkResult = opponentAttack(playerHP, opponentHP, critAtk, turns);
        // merge result
        return mergeResult(baseAtkResult, baseAtk.probability, critAtkResult, critAtk.probability);
    }

    function opponentAttack(playerHP, opponentHP, attack, turns) {
        // damage
        playerHP -= attack.damageAmount;

        // heal on hit
        opponentHP += attack.healAmount;
        opponentHP = Math.min(opponentHP, this.opponent.hp);

        // check loss
        if (playerHP <= 0) {
            const point = 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);
    }
}


/* =========================================
	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="/champions-map.html" >'
                                      + $('nav [rel="content"] a[href="/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 (window.location.pathname.indexOf('/champions/') != -1 || window.location.pathname.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('championsData') || DEFAULT_CHAMPIONS_DATA) : JSON.parse(localStorage.getItem('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 = (window.location.pathname.indexOf('/champions/') != -1) ? $('.page-champions') : $('.page-club_champion');
        let isSkipButtonClicked;
        markMatchedPositions();
        if (window.location.pathname.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('championsData') || DEFAULT_CHAMPIONS_DATA) : JSON.parse(localStorage.getItem('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('championsData', JSON.stringify(championsData));
            }
            else {
                localStorage.setItem('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);
        }

        function showAdditionalInformation() {
            if ($('.champions-middle__champion-resting').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');

                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');
                    }
                    else if (positions2.some((e) => (preparePositionImage(e) === currentGirlsPose.attr('src')))) {
                        currentGirlsPose.next().addClass('green-tick-icon empty');
                        currentGirlsPose.next().css('filter', 'hue-rotate(-45deg)');
                    }
                    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(-45deg)');
                    }
                    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 || 165) + 'px; right:' + (config.right || -165)
                                + '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 || 165) + 'px; right:' + (config.right || -165)
                                 + '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();
            }
        }

        sheet.insertRule('.champions-bottom__ticket-amount {'
                         + 'width: 145px;}'
                        );

        sheet.insertRule('.champions-bottom__ticket-amount.right {'
                         + 'text-align: left !important;}'
                        );
    }
}


/* =======
    LINKS
   ======= */

function moduleLinks() {
    let time_now = window.server_now_ts;
    const options = {hour: '2-digit', minute: '2-digit'};

    // is localstorage available?
    function lsTest() {
        try {
            localStorage.setItem('test', 'test');
            localStorage.removeItem('test');
            return true;
        } catch(e) {
            return false;
        }
    }

    // verify localstorage
    let lsAvailable = (lsTest() === true) ? 'yes' : 'no';
    // Current page: Homepage
    if (CurrentPage.indexOf('home') != -1) setTimeout(home(), 500);
    // Current page: Homepage
    else if (CurrentPage.indexOf('log_in') != -1) home();
    // Current page: Pachinko
    else if (CurrentPage.indexOf('pachinko') != -1) pachinko();
    // Current page: Activities
    else if (CurrentPage.indexOf('activities') != -1){
        if ($('#activities-tabs').children('[data-tab=pop]').length > 0) pop();
    }
    // Current page: Champions
    else if (CurrentPage.indexOf('champions') != -1) champions();
    // Current page: Market
    else if (CurrentPage.indexOf('shop') != -1) collectBoostersFromMarket();
    else if ((CurrentPage.indexOf('map') != -1) || (CurrentPage.indexOf('world') != -1) || (CurrentPage.indexOf('quest') != -1)) questTitle();
    else if (CurrentPage.indexOf('path-of-valor') != -1) pov();
    else if (CurrentPage.indexOf('path-of-glory') != -1) 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 + " ";
            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){
            var 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("LeagueExists") == 1 && window.Hero.infos.level >= 20) {
        $('#contains_all > header').children('[type=quest]').append('<div class="league_counter" id="LeagueTimer">'
                                                                    + '<span class="league_icn">'
                                                                    + '<span id="leagueTool" class="infoTooltip leagueTooltip"></span></span>'
                                                                    + '<a href="/tower-of-fame.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_amount + '</span>'
                                                                    + '<span id="scriptLeagueTimer" rel="league_count_txt" timeforsinglepoint="2100" timeonload="24"></span>'
                                                                    + '</a></div></div></div>');
    }

    $('#contains_all > header').children('[type=quest]').append('<div class="scriptSeasonInfo" id="FightSeason">'
                                                                + '<span class="season_icn">'
                                                                + '<span id="seasonTool" class="infoTooltip seasonTooltip"></span></span>'
                                                                + '<a href="/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_amount + '</span>'
                                                                + '<span id="scriptSeasonTimer" rel="season_count_txt" timeforsinglepoint="3600" timeonload="24"></span>'
                                                                + '</a></div></div></div>');

    if ((window.HH_UNIVERSE != 'comix_c' && window.HH_UNIVERSE != 'star_t') && window.Hero.infos.level >= 15) {
        $('#contains_all > header').children('[type=quest]').append('<div class="scriptPantheonInfo" id="FightPantheon">'
                                                                    + '<span class="pantheon_icn">'
                                                                    + '<span id="pantheonTool" class="infoTooltip pantheonTooltip"></span></span>'
                                                                    + '<a href="/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_amount + '</span>'
                                                                    + '<span id="scriptPantheonTimer" rel="pantheon_count_txt" timeforsinglepoint="8640"></span>'
                                                                    + '</a></div></div></div>');
    }

    if (localStorage.getItem("nb_Pop") > 0) {
        $('#contains_all > header').children('[type=quest]').append('<div class="pop_timer" id="PoPTimer">'
                                                                    + '<a href="/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>'
                                                                    + '<span id="popTool" class="infoTooltip popTooltip"></span>'
                                                                    + '</a></div></div></div>');
    }

    $('#canvas_fight_energy .hudBattlePts_mix_icn')[0].className = "trollPts_icn";
    $('#canvas_fight_energy .trollPts_icn').append('<span id="trollTool" class="infoTooltip trollTooltip"></span>');
    document.querySelector('.trollPts_icn').removeAttribute('energy-fight-tooltip')

    $('#canvas_quest_energy .hudEnergy_mix_icn')[0].className = "energy_icn";
    $('#canvas_quest_energy .energy_icn').append('<span id="energyTool" class="infoTooltip energyTooltip"></span>');
    document.querySelector('.energy_icn').removeAttribute('energy-quest-tooltip')


    function questTitle(){
        $('#breadcrumbs').css('z-index', '99');
        $('#breadcrumbs').css('top', '63px');
    }

    function scriptTimers(){
        setTimeout(function(){
            questLink();
        }, 500);

        addBoosterStatus();

        setInterval(function(){
            leagueBattles();
            seasonBattles();
            popTimer();
            pantheonBattles();
            questTooltip();
            trollTooltip();
        }, 1000);
    }

    function questLink() {
        let quest_link = window.Hero.infos.questing.current_url;
        if (!quest_link.includes('quest')) {
            quest_link = "/champions-help.html";
        }

        const $energybar = $('#canvas_quest_energy .bar-wrapper .over');
        $energybar.prepend('<a href="' + 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_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) {
            $('#energyTool').html("<span id=energy_title>" + labels.energy + "<BR></span>" + labels.full);
        }
        else {
            $('#energyTool').append("<span id=energy_title>" + labels.energy + "<BR></span>"
                                    + labels.full_in + " <span id=energy_time_remaining>" + calculateTime(full_quest_date*1000) + "</span><BR>"
                                    + labels.ends_at + ' ' + new Date(full_quest_date*1000).toLocaleTimeString(undefined, options)
                                    + '<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_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) {
            $('#trollTool').html("<span id=troll_title>" + labels.combativity + "<BR></span>" + labels.full);
        }
        else {
            $('#trollTool').html("<span id=troll_title>" + labels.combativity + "<BR></span>"
                                 + labels.full_in + " <span id=troll_time_remaining>" + calculateTime(full_troll_date*1000) + "</span><BR>"
                                 + labels.ends_at + ' ' + new Date(full_troll_date*1000).toLocaleTimeString(undefined, options)
                                 + '<BR>' + labels.date_on + ' ' + new Date(full_troll_date*1000).toLocaleDateString());
        }
    }

    function pop(){
        var current_date_sec = Math.floor(new Date().getTime()/1000);
        var popDate = current_date_sec;
        var popTime = 0;
        var popRemainingTime = 0;
        var popList = [];
        var popId = 0;
        var popAll = document.getElementsByClassName("pop_thumb");
        for (let i=0; i<popAll.length; i++) {
            var 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("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("pop_" + (i+1) + "_can_start", "true");
                }
                else {
                    var 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("pop_" + (i+1) + "_can_start", "false");
                }
                if (current_date_sec > localStorage.getItem("popDate" + (i+1))) {
                    localStorage.setItem("popDate" + (i+1), popDate);
                    localStorage.setItem("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("pop_" + popId + "_can_start", "false");
            localStorage.setItem("popDate" + popId, popDate);
            localStorage.setItem("popTime" + popId, popTime);
        });

        displayClassGirl();

        function displayClassGirl() {
            const girlDictionary = (typeof(localStorage.HHPNMap) == "undefined") ? new Map(): new Map(JSON.parse(localStorage.HHPNMap));
            let girls = $('#pop #pop_info .pop_right_part .grid_view')[0].children;
            for (var m=0; m<girls.length; m++) {
                if (girls[m].attributes.girl != undefined) {
                    let girl_id = girls[m].attributes.girl.value;
                    let girl_class = (girlDictionary.get(parseInt(girl_id, 10)) != undefined) ? girlDictionary.get(parseInt(girl_id, 10)).class : 0;
                    switch (girl_class) {
                        case 1:
                            $($('#pop #pop_info .pop_right_part .grid_view .not_selected')[m]).find('.girl_action').append($('<img class="classGirl" src="' + window.IMAGES_URL + '/caracs/hardcore.png">'));
                            break;

                        case 2:
                            $($('#pop #pop_info .pop_right_part .grid_view .not_selected')[m]).find('.girl_action').append($('<img class="classGirl" src="' + window.IMAGES_URL + '/caracs/charm.png">'));
                            break;

                        case 3:
                            $($('#pop #pop_info .pop_right_part .grid_view .not_selected')[m]).find('.girl_action').append($('<img class="classGirl" src="' + window.IMAGES_URL + '/caracs/knowhow.png">'));
                            break;
                    }
                }
            }
            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("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("pop_" + (i+1) + "_can_start") == "true") {
                    pop_can_start = true;
                }
                else {
                    let popDate_i = parseInt(localStorage.getItem("popDate" + (i+1)), 10) || 0;
                    popDate.push(popDate_i);
                    let popTime_i = parseInt(localStorage.getItem("popTime" + (i+1)), 10) || 0;
                    popTime.push(popTime_i);
                    if (popDate_i == 0) {
                        localStorage.setItem("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)');
                $('#popTool').html(labels.ends_at + ' ' + new Date(popDateMin*1000).toLocaleTimeString(undefined, options)
                                   + '<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%)');
                $('#popTool').css('display', 'none');
            }
        }
    }


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

        this.activeBoosters = {};

        const boosterStatus = JSON.parse(localStorage.getItem('booster_status')) || DEFAULT_BOOSTERS;

        boosterStatus.normal = boosterStatus.normal.filter(({endAt}) => endAt > window.server_now_ts)

        Object.keys(boosterStatus).forEach(key => {
            if (boosterStatus[key].length < 3) {
                // fill the rest with empty
                boosterStatus[key] = [...boosterStatus[key], ...Array(3-boosterStatus[key].length).fill({empty:true})]
            }
        })

        const $boosterStatusHTML = $('<a class="script-booster-status" href="/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 - window.server_now_ts
            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>
            `)

            if (useTimer) {
                let timerId
                const onComplete = () => {
                    $wrapper.find('.slot')
                        .attr('class', 'slot empty')
                        .empty()
                        .attr('data-d', '').removeAttr('data-d')
                        .attr('tooltip-id', '').removeAttr('tooltip-id')
                        .attr('id_item', '').removeAttr('id_item')
                    $wrapper.find('.progress').css('transform', 'rotate(0deg)')
                }
                const onUpdate = () => {
                    if (!timerId) {
                        return
                    }
                    const timer = window.HHTimers.timers[timerId]
                    const remainingTime = timer.remainingTime

                    const percentage = remainingTime/max
                    const firstHalf = Math.min(percentage, 0.5) * 2
                    const secondHalf = Math.max(percentage - 0.5, 0) * 2

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

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

                    if (flashingClass) {
                        $wrapper.find('.left, .right').addClass(flashingClass)
                    }

                    const $left = $wrapper.find('.left .progress')
                    const $right = $wrapper.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}`)
                }
                timerId = window.HHTimers.initDecTimer($wrapper.find('.dummy-timer-target'), current, onComplete, onUpdate)
            }

            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('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('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 {'
                         + 'display: grid;'
                         + 'grid-gap: 3px;'
                         + 'grid-template-columns: repeat(6, 1fr);}'
                        );

        sheet.insertRule(`${mediaDesktop} {`
                         + '.script-booster-status {'
                         + 'position: fixed;'
                         + 'top: 41px;'
                         + 'left: 126px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '.script-booster-status {'
                         + 'position: fixed;'
                         + 'top: 75px;'
                         + 'left: 179px;}}'
                        );

        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%;'
                         + 'border-radius: 7px;'
                         + '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%);'
                         + 'border-radius: 7px;'
                         + '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() {
        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('booster_status', JSON.stringify(boosterStatus));
    }

    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('club_status', JSON.stringify(clubStatus));
        }
    }

    function getClubXPBonus() {
        const clubStatus = JSON.parse(localStorage.getItem('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('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('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('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 boosterData = equipped_booster

                        if (boosterData) {
                            const clonedData = {...boosterData}

                            if (isMythic) {
                                boosterStatus.mythic.push(clonedData)
                            } else {
                                boosterStatus.normal.push({...clonedData, endAt: clonedData.lifetime})
                            }

                            localStorage.setItem('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, headband, watch, cinnamon, perfume
                    boosterStatus.mythic.forEach(booster => {
                        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
                        }
                    })

                    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 (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('booster_status', JSON.stringify(boosterStatus));

                    if (mythicUpdated) {
                        $(document).trigger('boosters:updated-mythic')
                    }
                }, 200);
            }
        })
    }

    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_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('tower-of-fame') == -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>");
            $('#leagueTool').html("<span id=league_title>" + labels.league + "<BR></span>"
                                  + labels.full_in + " <span id=league_time_remaining>" + convertToTimeFormat(remaining_full_time) + "</span><BR>"
                                  + labels.ends_at + ' ' + new Date(league_time_full*1000).toLocaleTimeString(undefined, options)
                                  + '<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();
            $('#leagueTool').html("<span id=league_title>" + labels.league + "<BR></span>" + labels.full);
            $('.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_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>");
            $('#seasonTool').html("<span id=season_title>" + labels.season + "<BR></span>"
                                  + labels.full_in + " <span id=season_time_remaining>" + convertToTimeFormat(season_time_remaining) + "</span><BR>"
                                  + labels.ends_at + ' ' + new Date((time_now + full_time_remaining)*1000).toLocaleTimeString(undefined, options)
                                  + '<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();
            $('#seasonTool').html("<span id=season_title>" + labels.season + "<BR></span>" + labels.full);
            $('.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_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>");
            $('#pantheonTool').html("<span id=pantheon_title>" + labels.pantheon + "<BR></span>"
                                    + labels.full_in + " <span id=pantheon_time_remaining>" + convertToTimeFormat(pantheon_time_remaining) + "</span><BR>"
                                    + labels.ends_at + ' ' + new Date((time_now + full_time_remaining)*1000).toLocaleTimeString(undefined, options)
                                    + '<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();
            $('#pantheonTool').html("<span id=pantheon_title>" + labels.pantheon + "<BR></span>" + labels.full);
            $('.tier_bar_pantheon').css('background-image', 'linear-gradient(to top,#008ed5 0,#05719c 100%)');
        }
    }

    function pachinko(){
        setTimeout(function() {
            var pachinkoTime = window.server_now_ts*1000 + window.pachinkoVar.next_game*1000;
            localStorage.setItem("pachinkoTime", pachinkoTime);

            if ($('#playzone-replace-info > div.btns-section > button.blue_button_L:nth-child(1)').length && $('.playing-zone')[0].attributes[1].value == "great") {
                let button = document.querySelector('#playzone-replace-info > div.btns-section > button.blue_button_L:nth-child(1)');
                button.addEventListener('click', function(){
                    if (button.attributes[3].value == "true") {
                        pachinkoTime = new Date().getTime() + (24*3600)*1000;
                        localStorage.setItem("pachinkoTime", pachinkoTime);
                    }
                });
            }

            var observer = new MutationObserver(function(mutations) {
                mutations.forEach(function(mutation) {
                    if ($('.playing-zone')[0].attributes[1].value != "great") {
                        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', function(){
                            if (button.attributes[3].value == "true") {
                                pachinkoTime = new Date().getTime() + (24*3600)*1000;
                                localStorage.setItem("pachinkoTime", pachinkoTime);
                            }
                        });
                    }
                })
            })

            observer.observe($('.playing-zone')[0], {
                childList: false
                , subtree: false
                , attributes: true
            })
        }, 200);
    }

    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 = $('a.champion-lair[href$="champions/' + (i+1) + '"] > div.champion-lair-name.map-label-link > div').attr('timer') || time_min_champions;
                time_min_champions = Math.min(time_min_champions, parseInt(time_champion, 10));
                let timer = $('a.champion-lair[href$="champions/' + (i+1) + '"] > div.champion-lair-name.map-label-link > div').attr('timer') || 0;
            }
            if (time_min_champions == time_now + 15*60 + 1) {
                localStorage.setItem("championsTime", time_now*1000);
            }
            else {
                localStorage.setItem("championsTime", time_min_champions*1000);
            }
        }
        else {
            setTimeout(function() {
                let current_timer = parseInt($('.champions-bottom__rest > span:nth-child(1)').attr('timer'), 10);
                let current_min = parseInt(localStorage.getItem("championsTime"), 10);

                if (current_min < time_now*1000) {
                    current_min = (time_now + 15*60 + 1)*1000;
                }
                if ((current_timer*1000) < current_min) {
                    localStorage.setItem("championsTime", current_timer*1000);
                }

                if ($('button.champions-bottom__start-battle').length > 0) {
                    let button = document.querySelector('.champions-bottom__wrapper .champoions-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("championsTime"), 10);
                        if (champion_timer < champion_min || champion_min < new Date().getTime()) {
                            localStorage.setItem("championsTime", champion_timer);
                        }
                    });
                }
            }, 200);
        }
    }

    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("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("PogTime", pog_end_time);
    }

    function season() {
        let seasonTimer = window.season_sec_untill_event_end;
        let season_end_time = time_now + seasonTimer;
        localStorage.setItem("SeasonTime", season_end_time);
    }

    function home() {
        //Check if the player have access to the league or if the league exists
        if ($('a[href$="tower-of-fame.html"]').length === 0) {
            localStorage.setItem("LeagueExists", 0);
        }
        else {
            localStorage.setItem("LeagueExists", 1);
        }

        //Market timer
        if($('#homepage .main-container .left-side-container a[rel="shop"] .notif-position .additional-menu-data .timer [rel="expires"] .timerClock_icn').length == 0) {
            let market = $('#homepage .main-container .left-side-container a[rel="shop"] .notif-position .additional-menu-data .timer [rel="expires"]');
            market.append('<span class="timerClock_icn"></span>'
                          + '0s');
            $('#homepage .main-container .left-side-container a[rel="shop"] .notif-position .additional-menu-data .timer').css('display', 'block');
        }

        //Great Pachinko timer
        let pachinkoTime = localStorage.getItem("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 = (localStorage.getItem("championsTime") > time_now*1000) ? localStorage.getItem("championsTime") : (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("PovTime") == "NaN") ? 0 : localStorage.getItem("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="scriptPoVTimer">' + calculateTime(povTime*1000) + '</span></div>'
                       + '</div></div>');
        }

        //PoG timer
        let pogTime = (localStorage.getItem("PogTime") == "NaN") ? 0 : localStorage.getItem("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="scriptPoGTimer">' + calculateTime(pogTime*1000) + '</span></div>'
                       + '</div></div>');
        }

        //Season timer
        let seasonTime = (localStorage.getItem("SeasonTime") == "NaN") ? 0 : localStorage.getItem("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="/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_pantheon = '<a class="champions_menu pantheon" href="/pantheon.html">' + window.GT.design.pantheon + '</a>';
            let championsMenu_Romero = '<a class="champions_menu champion1" href="/champions/1">Romero</a>';
            let championsMenu_Whaty = '<a class="champions_menu champion2" href="/champions/2">Whaty</a>';
            let championsMenu_Matsuda = '<a class="champions_menu champion3" href="/champions/3">Matsuda</a>';
            let championsMenu_Ryu = '<a class="champions_menu champion4" href="/champions/4">Ryu</a>';
            let championsMenu_Visor = '<a class="champions_menu champion5" href="/champions/5">Visor</a>';
            let championsMenu_Alban = '<a class="champions_menu champion6" href="/champions/6">Alban</a>';
            if (window.Hero.infos.level >= 15) {
                $('a[rel="sex-god-path"]').append(championsMenu_pantheon);
            }
            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);
            }
        }

        //Club champion shortcut
        let clubChampion = '<a class="clubChampion" href="/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="/activities.html?tab=daily_goals">' + window.GT.design.daily_goals + '</a>';
        let missionsMenu = '<a class="missions_menu" href="/activities.html?tab=missions">' + window.GT.design.missions + '</a>';
        let contestsMenu = '<a class="contests_menu" href="/activities.html?tab=contests">' + window.GT.design.contests + '</a>';
        let popMenu = '<a class="pop_menu" href="/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="/shop.html?type=player-stats&subtab=armor">' + labels.Equipments + '</a>';
        let marketMenu_boosters = '<a class="market_menu boosters" href="/shop?type=booster">' + labels.Boosters + '</a>';
        let marketMenu_books = '<a class="market_menu books" href="/shop?type=potion">' + labels.Books + '</a>';
        let marketMenu_gifts = '<a class="market_menu gifts" href="/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);

        //Missions timer
        var mission_remaining_time = window.missions_datas.remaining_time || window.missions_datas.next_missions || 0;
        var mission_remaining_date = (time_now + parseInt(mission_remaining_time, 10))*1000;
        $('#home_missions_bar1 .mission-timer-container .text').remove();
        $('#home_missions_bar1 .mission-timer-container').append('<div style="width: 150px; font-size: 13px !important; color: rgb(255, 255, 255); text-decoration: none;"><span id="missionsTimer1">' + calculateTime(mission_remaining_date) + '</span></div>');
        $('#home_missions_bar2 .mission-timer-container .text').remove();
        $('#home_missions_bar2 .mission-timer-container').append('<div style="width: 150px; font-size: 13px !important; color: rgb(255, 255, 255); text-decoration: none;"><span id="missionsTimer2">' + calculateTime(mission_remaining_date) + '</span></div>');

        //Quests shortcuts
        let currentQuest = '<a class="current_quest" href="' + window.Hero.infos.questing.current_url + '">' + window.GT.design.current_quest + '</a>';
        let sideQuests = '<a class="side_quests" href="/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_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_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_amount + '<BR>'
                                             + labels.full + '</span>');
            }
        }


        setInterval(function(){$('#scriptPachinkoTimer').text(calculateTime(pachinkoTime));
                               $('#scriptChampionsTimer').text(calculateTime(championsTime));
                               $('#scriptPoVTimer').text(calculateTime(povTime*1000));
                               $('#scriptSeasonTime').text(calculateTime(seasonTime*1000));
                               $('#missionsTimer1').text(calculateTime(mission_remaining_date));
                               $('#missionsTimer2').text(calculateTime(mission_remaining_date));
                              }, 1000);
    }


    //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: 80px;'
                     + '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 .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;}'
                    );

    var championsHeightDesktop = (parseInt($('.sex-god-path-btn').css('height'), 10) - 2) / 2;
    var championsHeightMobile = 54 - parseInt($('.sex-god-path-btn').css('height'), 10) / 2;

    sheet.insertRule(`${mediaDesktop} {`
                     + '.champions_menu {'
                     + 'height: ' + championsHeightDesktop + 'px;'
                     + 'text-decoration: none;'
                     + 'top: 1px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.champions_menu {'
                     + 'height: 52px;'
                     + 'top: -' + championsHeightMobile + 'px;}}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] a:hover, a[rel="clubs"] a:hover {'
                     + 'text-decoration: underline;}'
                    );

    sheet.insertRule('a[rel="clubs"] > .clubChampion {'
                     + 'text-decoration: none;'
                     + 'width: 130px !important;'
                     + 'height: 52px;'
                     + 'top: 1px;'
                     + 'margin-left: 130px;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] > .champions_map {'
                     + 'width: 100px !important;'
                     + 'margin-left: 130px;}'
                    );

    sheet.insertRule('#hh_comix a[rel="sex-god-path"] > .champions_map {'
                     + 'width: 100px !important;'
                     + 'height: 52px !important;'
                     + 'margin-left: 130px;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] > .pantheon {'
                     + 'width: 100px !important;'
                     + 'margin-left: 130px;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="sex-god-path"] > .pantheon, a[rel="sex-god-path"] > .champion4, a[rel="sex-god-path"] > .champion5, a[rel="sex-god-path"] > .champion6 {'
                     + 'margin-top: ' + championsHeightDesktop + 'px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="sex-god-path"] > .pantheon, a[rel="sex-god-path"] > .champion4, a[rel="sex-god-path"] > .champion5, a[rel="sex-god-path"] > .champion6 {'
                     + 'margin-top: ' + (championsHeightDesktop + championsHeightMobile) + 'px;}}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] > .champion1, a[rel="sex-god-path"] > .champion4 {'
                     + 'margin-left: 230px;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] > .champion2, a[rel="sex-god-path"] > .champion5 {'
                     + 'margin-left: 310px;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"] > .champion3, a[rel="sex-god-path"] > .champion6 {'
                     + 'margin-left: 390px;}'
                    );

    sheet.insertRule('a[rel="clubs"]:hover > .clubChampion {'
                     + 'width: 130px !important;'
                     + 'height: 52px;'
                     + 'margin-left: 130px;'
                     + 'top: 1px;'
                     + 'opacity: 1;'
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"]:hover > .champions_map {'
                     + 'width: 100px !important;'
                     + 'margin-left: 130px;'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#hh_comix a[rel="sex-god-path"]:hover > .champions_map {'
                     + 'width: 100px !important;'
                     + 'height: 52px !important;'
                     + 'margin-left: 130px;'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"]:hover > .pantheon {'
                     + 'width: 100px !important;'
                     + 'margin-left: 130px;'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + 'a[rel="sex-god-path"]:hover > .pantheon, a[rel="sex-god-path"]:hover > .champion4, a[rel="sex-god-path"]:hover > .champion5, a[rel="sex-god-path"]:hover > .champion6 {'
                     + 'margin-top: ' + championsHeightDesktop + 'px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="sex-god-path"]:hover > .pantheon, a[rel="sex-god-path"]:hover > .champion4, a[rel="sex-god-path"]:hover > .champion5, a[rel="sex-god-path"]:hover > .champion6 {'
                     + 'margin-top: ' + (championsHeightDesktop + championsHeightMobile) + 'px;}}'
                    );

    sheet.insertRule('a[rel="sex-god-path"]:hover > .champion1, a[rel="sex-god-path"]:hover > .champion4 {'
                     + 'margin-left: 230px;'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"]:hover > .champion2, a[rel="sex-god-path"]:hover > .champion5 {'
                     + 'margin-left: 310px;'
                     + 'opacity: 1; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('a[rel="sex-god-path"]:hover > .champion3, a[rel="sex-god-path"]:hover > .champion6 {'
                     + 'margin-left: 390px;'
                     + '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: 160px;}}'
                    );

    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('a[rel="activities"] > .missions_menu {'
                     + 'margin-left: 290px;}'
                    );

    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: 380px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="activities"] > .pop_menu {'
                     + 'margin-left: 490px;}}'
                    );

    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('a[rel="activities"]:hover > .missions_menu {'
                     + 'margin-left: 291px;'
                     + '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: 382px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + 'a[rel="activities"]:hover > .pop_menu {'
                     + 'margin-left: 493px;}}'
                    );

    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: 150px;'
                     + '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: 102px !important;}'
                    );

    sheet.insertRule('#home_season_bar {'
                     + 'width: 90px;'
                     + '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 .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-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: 75px 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: 75%; '
                     + 'left: 6px;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#LeagueTimer {'
                     + 'width: 85%; '
                     + 'left: -5px;}'
                    );

    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 + '/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('.leagueTooltip {'
                     + 'width: 180px; '
                     + 'top: 30px; '
                     + 'margin-left: -90px;}'
                    );

    sheet.insertRule('.league_icn:hover .leagueTooltip {'
                     + 'color: gray; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('.league_icn:hover #league_title {'
                     + 'color: white; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('.league_icn:hover #league_time_remaining {'
                     + 'color: orange; '
                     + 'visibility: visible;}'
                    );

    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: 75px 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: 75%; '
                     + 'left: -35px;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#FightSeason {'
                     + 'width: 85%; '
                     + 'left: -30px;}'
                    );

    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('.seasonTooltip {'
                     + 'width: 180px; '
                     + 'top: 30px; '
                     + 'margin-left: -90px;}'
                    );

    sheet.insertRule('.season_icn:hover .seasonTooltip {'
                     + 'z-index: 99; '
                     + 'color: gray; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('.season_icn:hover #season_title {'
                     + 'color: white; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('.season_icn:hover #season_time_remaining {'
                     + 'color: orange; '
                     + 'visibility: visible;}'
                    );

    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: 75%; '
                     + 'top: -45px; '
                     + 'left: 345px;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#FightPantheon {'
                     + 'width: 85%; '
                     + 'top: 15px; '
                     + 'left: 285px;}'
                    );

    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('.pantheonTooltip {'
                     + 'width: 180px; '
                     + 'top: 30px; '
                     + 'margin-left: -90px;}'
                    );

    sheet.insertRule('.pantheon_icn:hover .pantheonTooltip {'
                     + 'z-index: 99; '
                     + 'color: gray; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('.pantheon_icn:hover #pantheon_title {'
                     + 'color: white; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('.pantheon_icn:hover #pantheon_time_remaining {'
                     + 'color: orange; '
                     + 'visibility: visible;}'
                    );

    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: 75px 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: 70%; '
                     + 'left: 106px;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#PoPTimer {'
                     + 'width: 80%; '
                     + 'left: 109px;}'
                    );

    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('.popTooltip {'
                     + 'width: 120px; '
                     + 'top: 25px; '
                     + 'margin-left: -120px;}'
                    );

    sheet.insertRule('#PoPTimer a:hover .popTooltip {'
                     + 'z-index:99; '
                     + 'color: gray; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('.infoTooltip {'
                     + 'width: max-content;'
                     + '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: 5px;'
                     + 'z-index: 100;}'
                    );

    sheet.insertRule('.infoTooltip::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('.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('#canvas_fight_energy .trollTooltip {'
                     + 'width: 180px; '
                     + 'top: 36px; '
                     + 'margin-left: -75px;}'
                    );

    sheet.insertRule('#canvas_fight_energy .trollPts_icn:hover .trollTooltip {'
                     + 'color: gray; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#canvas_fight_energy .trollPts_icn:hover #troll_title {'
                     + 'color: white; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#canvas_fight_energy .trollPts_icn:hover #troll_time_remaining {'
                     + 'color: orange; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#canvas_quest_energy .bar-wrapper .over a {'
                     + 'display: flex;'
                     + 'color: white;'
                     + 'text-decoration: none;}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#canvas_quest_energy .bar-wrapper .over a {'
                     + 'flex-direction: row;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#canvas_quest_energy .bar-wrapper .over a {'
                     + 'flex-direction: column;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#canvas_quest_energy .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: 19px;'
                     + 'height: 31px;'
                     + 'background-image: url("' + window.IMAGES_URL + '/pictures/design/ic_topbar_energy_quest.png");'
                     + 'background-size: 19px;'
                     + 'background-position: center;'
                     + 'background-repeat: no-repeat;'
                     + 'margin: 0;'
                     + 'padding: 0;}'
                    );

    sheet.insertRule('#canvas_quest_energy .energyTooltip {'
                     + 'width: 175px; '
                     + 'top: 36px; '
                     + 'margin-left: -75px;}'
                    );

    sheet.insertRule('#canvas_quest_energy .energy_icn:hover .energyTooltip {'
                     + 'color: gray; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#canvas_quest_energy .energy_icn:hover #energy_title {'
                     + 'color: white; '
                     + 'font-size: 14px; '
                     + 'visibility: visible;}'
                    );

    sheet.insertRule('#canvas_quest_energy .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 {'
                     + 'top: 95px !important;}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.page-pachinko #content-unscaled {'
                     + 'top: 75px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#tower_of_fame .base_block.lead_wrapper > h3 {'
                     + 'margin-left: -80px !important;'
                     + 'top: 8px !important;}}'
                    );

    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: 1;'
                     + 'position: fixed;'
                     + 'bottom: 10px;'
                     + 'left: 542px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_comix #homepage .social_links {'
                     + 'left: 542px !important;}}'
                    );

    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, #tower_of_fame, .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: 20px;}'
                    );

    sheet.insertRule('#shops #my-hero-tab-container p.content-title {'
                     + 'position: relative;'
                     + 'top: 13px;}'
                    );

    sheet.insertRule('#shops p.left-side-title, #shops p.right-side-title {'
                     + 'position: relative;'
                     + 'top: 11px;}'
                    );

    sheet.insertRule('#shops p.menu-title {'
                     + 'margin-right: 50px;}'
                    );

    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('#homepage .main-container .left-side-container span[rel="expires"] {'
                     + 'width: 85px !important;'
                     + 'margin-left: 1.8rem !important;}'
                    );

    sheet.insertRule('#homepage .main-container .left-side-container > a > .notif-position .additional-menu-data p.league-rank {'
                     + 'margin-left: 20px !important;}'
                    );
}


/* ============
	SEASON SIM
   ============ */

function moduleSeasonSim() {
    var playerEgo;
    var playerAtk;
    var playerDef;
    var playerCrit;

    var opponentEgo;
    var opponentAtk;
    var opponentDef;
    var opponentCrit;

    function calculateSeasonPower(idOpponent) {
        // INIT
        const $playerData = $('#season-arena .battle_hero');
        playerEgo = parseInt($playerData.find('.hero_stats .hero_stats_row:nth-child(2) div:nth-child(1) span:nth-child(2)').text().replace(/[^0-9]/gi, ''), 10);
        playerAtk = parseInt($playerData.find('.hero_stats .hero_stats_row:nth-child(1) div:nth-child(1) span:nth-child(2)').text().replace(/[^0-9]/gi, ''), 10);
        playerDef = parseInt($playerData.find('.hero_stats .hero_stats_row:nth-child(1) div:nth-child(2) span:nth-child(2)').text().replace(/[^0-9]/gi, ''), 10);
        playerCrit = parseInt($playerData.find('.hero_stats .hero_stats_row:nth-child(2) div:nth-child(2) span:nth-child(2)').text().replace(/[^0-9]/gi, ''), 10);
        const playerSynergyDataJSON = $playerData.find('.hero_team .icon-area').attr('synergy-data');
        const playerSynergies = JSON.parse(playerSynergyDataJSON);
        const playerTeam = $playerData.find('.hero_team .team-member img').map((i, el) => $(el).data('new-girl-tooltip')).toArray();
        const playerTeamMemberElements = playerTeam.map(({element_data: {type: element}})=>element);
        const playerElements = calculateThemeFromElements(playerTeamMemberElements);
        const playerBonuses = {
            critDamage: playerSynergies.find(({element: {type}})=>type==='fire').bonus_multiplier,
            critChance: playerSynergies.find(({element: {type}})=>type==='stone').bonus_multiplier,
            defReduce: playerSynergies.find(({element: {type}})=>type==='sun').bonus_multiplier,
            healOnHit: playerSynergies.find(({element: {type}})=>type==='water').bonus_multiplier
        };

        let $opponentData = $('#season-arena .opponents_arena .season_arena_opponent_container:nth-child(' + (2*idOpponent+1) + ')');
        opponentEgo = parseInt($opponentData.find('.hero_stats div:nth-child(2) div:nth-child(1) span:nth-child(2)').text().replace(/[^0-9]/gi, ''), 10);
        opponentDef = parseInt($opponentData.find('.hero_stats div:nth-child(1) div:nth-child(2) span:nth-child(2)').text().replace(/[^0-9]/gi, ''), 10);
        opponentAtk = parseInt($opponentData.find('.hero_stats div:nth-child(1) div:nth-child(1) span:nth-child(2)').text().replace(/[^0-9]/gi, ''), 10);
        opponentCrit = parseInt($opponentData.find('.hero_stats div:nth-child(2) div:nth-child(2) span:nth-child(2)').text().replace(/[^0-9]/gi, ''), 10);
        const opponentTeam = $opponentData.find('.hero_team .team-member img').map((i, el) => $(el).data('new-girl-tooltip')).toArray();
        const opponentTeamMemberElements = opponentTeam.map(({element})=>element);
        const opponentElements = calculateThemeFromElements(opponentTeamMemberElements);
        const opponentBonuses = calculateSynergiesFromTeamMemberElements(opponentTeamMemberElements);

        const dominanceBonuses = calculateDominationBonuses(playerElements, opponentElements);

        const player = {
            hp: playerEgo * (1 + dominanceBonuses.player.ego),
            dmg: (playerAtk * (1 + dominanceBonuses.player.attack)) - (opponentDef * (1 - playerBonuses.defReduce)),
            critchance: calculateCritChanceShare(playerCrit, opponentCrit) + dominanceBonuses.player.chance + playerBonuses.critChance,
            bonuses: playerBonuses
        };
        const opponent = {
            hp: opponentEgo * (1 + dominanceBonuses.opponent.ego),
            dmg: (opponentAtk * (1 + dominanceBonuses.opponent.attack)) - (playerDef * (1 - opponentBonuses.defReduce)),
            critchance: calculateCritChanceShare(opponentCrit, playerCrit) + dominanceBonuses.opponent.chance + opponentBonuses.critChance,
            name: $('.season_arena_opponent_container:nth-child(' + (2*idOpponent+1) + ') > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1)').text(),
            bonuses: opponentBonuses
        };

        const simu = calculateBattleProbabilities(player, opponent);

        $('#season-arena .opponents_arena .season_arena_opponent_container:nth-child(' + (2*idOpponent+1) + ') .team-total-power .matchRating').remove();

        $('#season-arena .opponents_arena .season_arena_opponent_container:nth-child(' + (2*idOpponent+1) + ') .team-total-power').append(`<span class="matchRating ${simu.scoreClass}">${nRounding(100*simu.win, 2, -1)}%</span>`);

        let teamPower = $('#season-arena .opponents_arena .season_arena_opponent_container .team-total-power')[(idOpponent-1)].firstChild.nodeValue;
        teamPower = nThousand(parseInt(teamPower.replace(' ', '').replace(',', '.'), 10));
        $('#season-arena .opponents_arena .season_arena_opponent_container .team-total-power')[(idOpponent-1)].firstChild.textContent = teamPower;
    }

    setTimeout(function() {
        calculateSeasonPower(1);
        calculateSeasonPower(2);
        calculateSeasonPower(3);
    }, 200);

    const observer = new MutationObserver(() => {calculateSeasonPower(1);
                                                 calculateSeasonPower(2);
                                                 calculateSeasonPower(3);});
    observer.observe($('#season-arena .opponents_arena')[0], {subtree: true, attributes: true, attributeFilter: ['class']})

    //CSS
    sheet.insertRule('.matchRating {'
                     + '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; '
                     + 'font-size: 16px;}'
                    );

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

/* ==============
	SEASON STATS
   ============== */

function moduleSeasonStats() {
    const resetUTCHour = 12;
    var seasonDateEndData = localStorage.getItem('SeasonDateEnd') || JSON.stringify({day: 0, month: 0, year: 0, hour: 0});
    var seasonDateEnd = JSON.parse(seasonDateEndData);
    var currentDay = new Date().getUTCDate();
    var currentMonth = new Date().getUTCMonth();
    var currentYear = new Date().getUTCFullYear();
    var 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('SeasonDateEnd', JSON.stringify(seasonDateEnd));
    }
    if ((currentMonth == seasonDateEnd.month) && (currentDay >= seasonDateEnd.day) && (currentHour >= seasonDateEnd.hour)) {
        localStorage.setItem('oldSeasonStats', localStorage.getItem('SeasonStats'));
        localStorage.removeItem('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('SeasonDateEnd', JSON.stringify(seasonDateEnd));
    }
    else if ((currentMonth == seasonDateEnd.month) && (currentDay > seasonDateEnd.day)) {
        localStorage.setItem('oldSeasonStats', localStorage.getItem('SeasonStats'));
        localStorage.removeItem('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('SeasonDateEnd', JSON.stringify(seasonDateEnd));
    }
    else if ((currentMonth > seasonDateEnd.month) && (currentYear == seasonDateEnd.year)) {
        localStorage.setItem('oldSeasonStats', localStorage.getItem('SeasonStats'));
        localStorage.removeItem('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('SeasonDateEnd', JSON.stringify(seasonDateEnd));
    }
    else if (currentYear > seasonDateEnd.year) {
        localStorage.setItem('oldSeasonStats', localStorage.getItem('SeasonStats'));
        localStorage.removeItem('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('SeasonDateEnd', JSON.stringify(seasonDateEnd));
    }

    var seasonStatsData = localStorage.getItem('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});
    var seasonStats = JSON.parse(seasonStatsData);
    localStorage.setItem('SeasonStats', JSON.stringify(seasonStats));
    var fights = seasonStats.fights;
    var victories = seasonStats.victories;
    var losses = seasonStats.losses;
    var won_mojo = seasonStats.won_mojo;
    var lost_mojo = seasonStats.lost_mojo;
    var won_mojo_avg = seasonStats.won_mojo_avg;
    var lost_mojo_avg = seasonStats.lost_mojo_avg;
    var mojo_avg = seasonStats.mojo_avg;
    var i=0;

    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 += parseInt((response.rewards.data.rewards[0].value).replace(/\D/g, ''), 10);
                    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 += parseInt((response.rewards.data.rewards[1].value).replace(/\D/g, ''), 10);
                    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('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 + ' : ' + victories
                                          + '<BR>' + labels.defeats + ' : ' + losses
                                          + '<BR><BR>' + labels.won_mojo + ' : ' + won_mojo
                                          + '<BR>' + labels.lost_mojo + ' : ' + 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 + '</span>'
                                          + '</span>');
    }

    if (CurrentPage.indexOf('season-arena') != -1) {
        $('div#season-arena > div:nth-child(1) > div:nth-child(2) > div:nth-child(2) > div:nth-child(2)').append('<span class="scriptSeasonStatsArena" style="color: #8ec3ff; margin-left: 15px; font-size: 16px">Stats'
                                                                                                                 + '<span class="scriptSeasonStatsTooltipArena">' + labels.fights + ' : ' + fights
                                                                                                                 + '<BR>' + labels.victories + ' : ' + victories
                                                                                                                 + '<BR>' + labels.defeats + ' : ' + losses
                                                                                                                 + '<BR><BR>' + labels.won_mojo + ' : ' + won_mojo
                                                                                                                 + '<BR>' + labels.lost_mojo + ' : ' + 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 + '</span>'
                                                                                                                 + '</span>');
    }

    //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: 75%; '
                     + '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: 75%; '
                     + '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.HHPNMap;
        if (typeof(jsonMapData) == "undefined"){
            return
        }
        const localizationMap = new Map(JSON.parse(jsonMapData));
        const targetNode = document.getElementById('pachinko_whole');
        const config = { attributes: true, childList: true, subtree: true };

        const callback = function(mutationsList, observer){
            var 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);

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

                var 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) {
            var girls = "";
            for (var i = 0, l = found.length; i < l; i++) {
                const raw = found[i];
                const id = parseInt(raw.match(/\d+/g), 10);
                const name = (localizationMap.get(id) != undefined) ? localizationMap.get(id).name : 'Unknown';
                let girlName = name.replaceAll("’", "-").replaceAll("/", "-");
                if (id == 145462484) girlName = girlName.concat('-', 'Usagi');

                var element = (girlName != 'Unknown') ? '<a href="/harem/' + id + '"> ' + name + ' </a>' : name;

                if (girls != ""){
                    girls += ", " + element;
                } else {
                    girls += element;
                }
            }
            return girls;
        }

        function displayWikiGirlsNames(found) {
            var girls = "";
            for (var i = 0, l = found.length; i < l; i++){
                const raw = found[i];
                const id = parseInt(raw.match(/\d+/g), 10);
                const name = (localizationMap.get(id) != undefined) ? localizationMap.get(id).name : 'Unknown';
                let girlName = name.replaceAll("’", "-").replaceAll("/", "-");
                if (id == 145462484) girlName = girlName.concat('-', 'Usagi');
                var 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.wikidot.com/' + girlName + '" 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="/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;}'
                    );
}

/* ====================
	BATTLE SIMULATION
   ==================== */

function moduleBattleSim() {
    var playerEgo;
    var playerAtk;
    var playerDef;
    var playerCrit;

    var opponentEgo;
    var opponentAtk;
    var opponentDef;
    var opponentCrit;

    function calculateBattleSynergiesFromTeamMemberElements(elements) {
        const counts = countElementsInTeam(elements)

        return {
            critDamage: (0.0035 * counts.fire) + (0.1 * counts.fire),
            critChance: (0.0007 * counts.stone) + (0.02 * counts.stone),
            defReduce: 0,
            healOnHit: (0.001 * counts.water) + (0.03 * counts.water)
        }
    }

    function calculatePower() {
        // INIT
        const playerStats = $('#pre-battle #player-panel .stat');
        playerAtk = parseLocaleRoundedInt(playerStats[0].innerText);
        playerEgo = parseLocaleRoundedInt(playerStats[1].innerText);
        playerDef = parseLocaleRoundedInt(playerStats[2].innerText);
        playerCrit = parseLocaleRoundedInt(playerStats[3].innerText);
        const playerSynergyDataJSON = $('#player-panel .icon-area').attr('synergy-data')
        const playerSynergies = JSON.parse(playerSynergyDataJSON)
        const playerTeam = $('#player-panel .team-member img').map((i, el) => $(el).data('new-girl-tooltip')).toArray()
        const playerTeamMemberElements = playerTeam.map(({element_data: {type: element}})=>element)
        const playerElements = calculateThemeFromElements(playerTeamMemberElements)
        const playerBonuses = {
            critDamage: playerSynergies.find(({element: {type}})=>type==='fire').bonus_multiplier,
            critChance: playerSynergies.find(({element: {type}})=>type==='stone').bonus_multiplier,
            defReduce: 0,
            healOnHit: playerSynergies.find(({element: {type}})=>type==='water').bonus_multiplier
        }

        const opponentStats = $('#pre-battle #opponent-panel .stat');
        opponentAtk = parseLocaleRoundedInt(opponentStats[0].innerText);
        opponentEgo = parseLocaleRoundedInt(opponentStats[1].innerText);
        opponentDef = parseLocaleRoundedInt(opponentStats[2].innerText);
        opponentCrit = parseLocaleRoundedInt(opponentStats[3].innerText);
        const opponentTeam = $('#opponent-panel .team-member img').map((i, el) => $(el).data('new-girl-tooltip')).toArray();
        const opponentTeamMemberElements = opponentTeam.map(({element})=>element);
        const opponentElements = calculateThemeFromElements(opponentTeamMemberElements);
        const opponentBonuses = calculateBattleSynergiesFromTeamMemberElements(opponentTeamMemberElements);

        const dominanceBonuses = calculateDominationBonuses(playerElements, opponentElements);

        const player = {
            hp: playerEgo * (1 + dominanceBonuses.player.ego),
            dmg: playerAtk - opponentDef,
            critchance: calculateCritChanceShare(playerCrit, opponentCrit) + dominanceBonuses.player.chance + playerBonuses.critChance,
            bonuses: playerBonuses
        };
        const opponent = {
            hp: opponentEgo * (1 + dominanceBonuses.opponent.ego),
            dmg: opponentAtk - playerDef,
            critchance: calculateCritChanceShare(opponentCrit, playerCrit) + dominanceBonuses.opponent.chance + opponentBonuses.critChance,
            name: $('#opponent-panel .hero-name-container').text(),
            bonuses: opponentBonuses
        };

        const simu = calculateBattleProbabilities(player, opponent);

        let teamPower = $('#pre-battle #player-panel .fighter-team .team-hexagon-container .average-lvl .team-total-power')[0].firstChild.nodeValue;
        teamPower = nThousand(parseInt(teamPower.replace(',', '.'), 10));
        $('#pre-battle #player-panel .fighter-team .team-hexagon-container .average-lvl .team-total-power')[0].firstChild.textContent = teamPower;

        teamPower = $('#pre-battle #opponent-panel .fighter-team .team-hexagon-container .average-lvl .team-total-power')[0].firstChild.nodeValue;
        teamPower = nThousand(parseInt(teamPower.replace(',', '.'), 10));
        $('#pre-battle #opponent-panel .fighter-team .team-hexagon-container .average-lvl .team-total-power')[0].firstChild.textContent = teamPower;

        $('#opponent-panel .average-lvl')
            .wrap('<div class="gridWrapper"></div>')
            .after(`<span class="matchRating ${simu.scoreClass}">${nRounding(100*simu.win, 2, -1)}%</span>`);
    }

    calculatePower();

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

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

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

    sheet.insertRule('.gridWrapper {'
                     + 'display: grid;'
                     + 'grid-template-columns: 1fr 1fr;'
                     + 'width: 100%;}'
                    );

    sheet.insertRule('.matchRating {'
                     + 'text-align: center;'
                     + 'font-size: 16px;}'
                    );

    sheet.insertRule('#pre-battle .fighter-team .team-hexagon-container .average-lvl {'
                     //+ 'width: max-content;'
                     + 'text-align: center;'
                     + 'margin-top: 0px;'
                     + 'line-height: 26px;}'
                    );
}

/* ========================================
	TEAMS FILTER (Credit : randomfapper34)
   ======================================== */

function moduleTeamsFilter() {
    var storage = window.localStorage;
    var arenaGirls = undefined;
    var girlsData = undefined;
    var totalTooltips = 80;

    $(document).ready(function() {
        if (CurrentPage.indexOf('edit-team') != -1 || CurrentPage.indexOf('add-boss-bang-team') != -1) {
            updateFilterGirlData("seasons");
            $("h3.panel-title").after('<button id="arena_filter" class="blue_text_button">' + labels.filter + '</button>');
            $("h3.panel-title").after(createFilterBox("default"));
            createFilterEvents();
        }
    });

    function updateFilterGirlData(type) {
        var pose_id;

        arenaGirls = $('.harem-panel-girls div.harem-girl-container');

        girlsData = $.map(arenaGirls, function(girl, index) {
            const jsonMapData = localStorage.HHPNMap;
            if (typeof(jsonMapData) != "undefined") {
                const localizationMap = new Map(JSON.parse(jsonMapData));
                var girl_id = parseInt($(girl).attr("id_girl"), 10);
                pose_id = localizationMap.get(girl_id).pose;
            }
            var girl_data = $(girl).attr("data-new-girl-tooltip");
            var girl_data_split = girl_data.split(',"rarity":');
            var new_girl_data = girl_data_split[0] + ',"pose":"' + pose_id + '","rarity":' + girl_data_split[1];

            return JSON.parse(new_girl_data);
        });
    }

    function createFilterEvents() {
        $("#arena_filter").on('click', function() {
            if (typeof arenaGirls === 'undefined' || typeof girlsData === 'undefined') return;
            var currentBoxDisplay = $("#arena_filter_box").css('display');
            $("#arena_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_blessed_attributes").on('change', filterGirls);
        $("#filter_aff_category").on('change', filterGirls);
        $("#filter_aff_lvl").on('change', filterGirls);
        $("#filter_element").on('change', filterGirls);
        $("#filter_pose").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 filterBlessedAttributes = $("#filter_blessed_attributes").get(0).value;
        let filterAffCategory = $("#filter_aff_category").get(0).value;
        let filterAffLvl = $("#filter_aff_lvl").get(0).value;
        let filterElement = $("#filter_element").get(0).value;
        let filterPose = $("#filter_pose").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 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 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 matchesPose = (girl.pose == filterPose) || (filterPose == 'all');

            return (matchesClass && matchesRarity && matchesName && matchesBlessedAttributes && matchesAffCategory && matchesAffLvl && matchesElement && matchesPose) ? 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() {
        var totalHTML = '<div id="arena_filter_box" class="form-wrapper" style="'
        + 'position: absolute; width: 275px; 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;">';

        totalHTML += '<div class="form-control"><div class="input-group">'
            + '<label class="head-group" for="filter_name">' + labels.searched_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">'
            + '<label class="head-group" for="filter_class">' + labels.searched_class + '</label>'
            + '<select name="filter_class" id="filter_class" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option><option value="hardcore">' + labels.hardcore + '</option><option value="charm">' + labels.charm + '</option><option value="knowhow">' + labels.know_how + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group">'
            + '<label class="head-group" for="filter_element">' + labels.searched_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:grey">' + labels.dominatrix + '</option><option value="light">' + labels.submissive + '</option><option value="psychic" style="color:mediumpurple;">' + labels.voyeur + '</option><option value="fire" style="color:red;">' + labels.eccentric + '</option><option value="nature" style="color:green;">' + labels.exhibitionist + '</option><option value="stone" style="color:darkorange;">' + labels.physical + '</option><option value="sun" style="color:yellow;">' + labels.playful + '</option><option value="water" style="color:royalblue;">' + labels.sensual + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group">'
            + '<label class="head-group" for="filter_rarity">' + labels.searched_rarity + '</label>'
            + '<select name="filter_rarity" id="filter_rarity" icon="down-arrow">'
            + '<option value="all" selected="selected">' + labels.all + '</option><option value="starting">' + labels.starting + '</option><option value="common">' + labels.common + '</option><option value="rare">' + labels.rare + '</option><option value="epic">' + labels.epic + '</option><option value="legendary">' + labels.legendary + '</option><option value="mythic">' + labels.mythic + '</option>'
            + '</select></div></div>';

        totalHTML += '<div class="form-control"><div class="select-group">'
            + '<label class="head-group" for="filter_aff_category">' + labels.searched_aff_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">'
            + '<label class="head-group" for="filter_aff_lvl">' + labels.searched_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">'
            + '<label class="head-group" for="filter_blessed_attributes">' + labels.searched_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">'
            + '<label class="head-group" for="filter_pose">' + labels.searched_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>';

        return totalHTML;
    }

    //CSS
    sheet.insertRule(`${mediaMobile} {`
                     + '#arena_filter_box {'
                     + 'top: 98px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#arena_filter_box {'
                     + 'top: 66px;}}'
                    );

    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 #arena_filter {'
                     + 'position: absolute;'
                     + 'width: 84px;'
                     + 'top: 99px;'
                     + 'right: 98px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.change-team-panel #arena_filter {'
                     + 'position: absolute;'
                     + 'width: 84px;'
                     + 'top: 76px;'
                     + '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;}}'
                    );
}

//Display your ranking in season or pantheon at the bottom of the screen if you are in the top 1000
if (CurrentPage == '/season.html' || CurrentPage == '/pantheon.html') {
    function fixLeaderboard() {
        const $leaderboardList = $('#leaderboard_list')
        const numRows = $leaderboardList.find('.leaderboard_row').length

        if (numRows === 0) {
            // not loaded yet
            const observer = new MutationObserver(() => {
                observer.disconnect()
                fixLeaderboard()
            })
            observer.observe($leaderboardList[0], {childList: true})
            return
        }

        const inTheTop1000 = numRows <= 1000
        if (!inTheTop1000) return;

        fixSeasonLeaderboard($leaderboardList);
    }

    function fixSeasonLeaderboard ($leaderboardList) {
        const ownRowData = $leaderboardList.find('.hero-row').length
        if (ownRowData == 0) {return}

        const $ownRow = $leaderboardList.find('.hero-row')
        .clone()
        .addClass('script-season-leaderboard-fix')
        $leaderboardList.append($ownRow)
    }

    fixLeaderboard();

    //CSS
    sheet.insertRule(`${mediaMobile} {`
                     + '.script-season-leaderboard-fix {'
                     + 'position: fixed;'
                     + 'bottom: 0px;'
                     + 'width: 904px;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.script-season-leaderboard-fix {'
                     + 'position: fixed;'
                     + 'bottom: 20px;'
                     + 'width: 904px;}}'
                    );
}


//Stop background switching during Orgy Days event (Credit: Finderkeeper)
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 girls data in the harem
if ($('#harem_whole').length){
    if (typeof(localStorage.HHPNMap) != "undefined") {
        if(JSON.parse(localStorage.HHPNMap)[0].length == 2) localStorage.removeItem('HHPNMap');
    }
    const jsonMapData = localStorage.HHPNMap;
    const localizationMap = typeof(jsonMapData) == "undefined"? new Map(): new Map(JSON.parse(localStorage.HHPNMap));
    let keys = Object.keys(window.girlsDataList);

    var girlNameDictionary = new Map()
    for (let j = 0, l = keys.length; j < l; j++){
        let key = parseInt(keys[j], 10);
        let girl = window.girlsDataList[key];
        let name = girl.name;
        let shards = (girl.shards != undefined) ? parseInt(girl.shards) : 100;
        let girl_class = parseInt(girl.class, 10);
        let pose = parseInt(girl.figure, 10);
        let girlData = {name: name,
                        shards: shards,
                        class: girl_class,
                        pose: pose}
        if (typeof(name) != "undefined") {
            girlNameDictionary.set(key, girlData);
        }
    }
    if (girlNameDictionary.size > 0){
        let json = JSON.stringify(Array.from(girlNameDictionary.entries()));
        localStorage.HHPNMap = json;
    }
}

//Display the number of shards for girls
if (CurrentPage.indexOf('battle') != -1 || CurrentPage.indexOf('clubs') != -1 || CurrentPage.indexOf('pachinko') != -1 || CurrentPage.indexOf('season-arena') != -1 || CurrentPage.indexOf('tower-of-fame') != -1) {
    const girlDictionary = (typeof(localStorage.HHPNMap) == "undefined") ? new Map(): new Map(JSON.parse(localStorage.HHPNMap));

    if (CurrentPage.indexOf('battle') != -1 || CurrentPage.indexOf('pachinko') != -1 || CurrentPage.indexOf('season-arena') != -1) {
        displayTrollGirlsShards();
        updateTrollGirlsShards();
    }
    else if (CurrentPage.indexOf('club') != -1) {
        displayClubChampionGirlsShards();
        setTimeout(function(){updateClubChampionGirlsShards();}, 2000);
    }
    else if (CurrentPage.indexOf('season-battle') != -1) {
        updateTrollGirlsShards();
    }
    else if (CurrentPage.indexOf('tower-of-fame') != -1) {
        displayLeagueGirlShards();
        updateTrollGirlsShards();
        updateLeagueGirlShards();
    }

    function displayTrollGirlsShards() {
        setTimeout(function() {
            if(($('.girls_reward').attr('data-rewards') != undefined) && (CurrentPage.indexOf('troll-pre-battle') != -1)) {
                let girlsData = JSON.parse($('.girls_reward').attr('data-rewards'));
                for (let j=0; j < girlsData.length; j++) {
                    let girlId = girlsData[j].id_girl;
                    let shards = (girlDictionary.get(girlId) != undefined) ? girlDictionary.get(girlId).shards : 0;
                    let name = (girlDictionary.get(girlId) != undefined) ? girlDictionary.get(girlId).name : '';
                    $('.slot_girl_shards:nth-child(' + (j+1) + ') .girl_ico').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: -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;'
                                     + 'font-size: 12px !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: -0.25em;'
                                     + 'width: 20px;'
                                     + 'height: 20px;}'
                                    );

                    if (girlsData.length > 1) {
                        sheet.insertRule('.page-troll-pre-battle #shard_number {'
                                         + 'margin-left: -1px;'
                                         + 'margin-top: -10px;}'
                                        );

                        sheet.insertRule('.page-troll-pre-battle .shards_troll .shard_troll {'
                                         + 'margin-left: 2px;'
                                         + 'margin-top: -11px;}'
                                        );
                    }
                    else {
                        sheet.insertRule('.page-troll-pre-battle #shard_number {'
                                         + 'margin-left: -1px;'
                                         + 'margin-top: -14px;}'
                                        );

                        sheet.insertRule('.page-troll-pre-battle .shards_troll .shard_troll {'
                                         + 'margin-left: 2px;'
                                         + 'margin-top: -15px;}'
                                        );
                    }
                }
            }
            else if (($('.girls_reward .animate > div').attr('data-reward-display') != undefined) && ((window.location.href.indexOf('league_battle') != -1) || (CurrentPage.indexOf('season-arena') != -1))) {
                let girlsData = JSON.parse($('.girls_reward .animate > div').attr('data-reward-display'));
                for (let j=0; j < girlsData.length; j++) {
                    let girlId = girlsData[j].id_girl;
                    let shards = (girlDictionary.get(girlId) != undefined) ? girlDictionary.get(girlId).shards : 0;
                    let name = (girlDictionary.get(girlId) != undefined) ? girlDictionary.get(girlId).name : '';
                    $('.slot_girl_shards:nth-child(' + (j+1) + ') .girl_ico').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-top: -15px; margin-left: -2px; 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: -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: 24px;'
                                     + 'text-align: right;'
                                     + 'margin-top: -13px;'
                                     + 'margin-left: -9px;'
                                     + 'font-size: 11px;}'
                                    );
                }
            }

            var observer = new MutationObserver(function(mutations) {
                mutations.forEach(function(mutation) {
                    if ($('.hh_tooltip_new .slot_girl').length == 0) return;

                    else if(($($('.hh_tooltip_new .slot_girl')[0]).find('.girl_ico .shards_troll')).length != 0) return;

                    else {
                        if ($($('.hh_tooltip_new .slot_girl .girl_ico img')[0]).attr('src').indexOf('girls/') == -1) return;

                        else {
                            for (var l=0; l < $('.hh_tooltip_new .slot_girl').length; l++) {
                                let idGirlStr = $($('.hh_tooltip_new .slot_girl img')[l]).attr('src');
                                let indexStart = idGirlStr.indexOf('girls/') + 'girls/'.length;
                                let indexEnd = idGirlStr.indexOf('/ico');
                                let girlId = parseInt(idGirlStr.substring(indexStart, indexEnd), 10);
                                let shards = (girlDictionary.get(girlId) != undefined) ? girlDictionary.get(girlId).shards : 0;
                                let name = (girlDictionary.get(girlId) != undefined) ? girlDictionary.get(girlId).name : '';
                                $($('.hh_tooltip_new .slot_girl .girl_ico .shards_troll')[l]).remove();
                                $($('.hh_tooltip_new .slot_girl .girl_ico')[l]).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 .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) {
                observer.observe($('.page-pachinko')[0], {childList: true, subtree: true, attributes: false});
            }

            else if (CurrentPage.indexOf('tower-of-fame') != -1) {
                observer.observe($('.page-leaderboard')[0], {childList: true, subtree: true, attributes: false});
            }
        }, 200);
    }

    function displayClubChampionGirlsShards() {
        setTimeout(function() {
            if(!$('.girl-shards-reward-wrapper').length) return;

            let girls = $('.girl-shards-reward-wrapper');
            for (let k=0; k < girls.length; k++) {
                let idGirlStr = $('.girl-shards-reward-wrapper:nth-child(' + (k+1) + ') .girl-shards-slot 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 = (girlDictionary.get(girlId) != undefined) ? girlDictionary.get(girlId).shards : 0;
                let name = (girlDictionary.get(girlId) != undefined) ? girlDictionary.get(girlId).name : '';
                $('.girl-shards-reward-wrapper:nth-child(' + (k+1) + ') .girl-shards-slot').append('<div class="club_shards" shards="' + shards + '" name="' + name + '">'
                                                                                                   + '<p id="club_shard_number" style="position: relative; bottom: 6.1em; 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: -11px; 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>');
            }
        }, 200);
    }

    function displayLeagueGirlShards() {
        setTimeout(function() {
            if(!$('.leagues_girl_reward_container .girl_ico').length) return;

            let idGirlStr = $('.leagues_girl_reward_container .girl_ico 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 = (girlDictionary.get(girlId) != undefined) ? girlDictionary.get(girlId).shards : 0;
            let name = (girlDictionary.get(girlId) != undefined) ? girlDictionary.get(girlId).name : '';
            $('.leagues_girl_reward_container .girl_ico').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: 25px; margin-left: -2px; width: 15px; height: 15px;"></span>'
                                                                 + '<p id="shard_number_tooltip" style="position: absolute; bottom: -1.3em; 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: 0px; font-size: 9px;">'
                                                                 + '<span>' + shards + '</span>'
                                                                 + '</p></div>');
        }, 200)
    }

    function updateTrollGirlsShards() {
        $(document).ajaxComplete(function(evt, xhr, opt) {
            if(opt.data == undefined) 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 != undefined) {
                        response.rewards.data.shards.forEach(function(shard) {
                            let idGirl = shard.id_girl;
                            let newShards = shard.value;
                            let name = (girlDictionary.get(idGirl) == undefined) ? '' : girlDictionary.get(idGirl).name;
                            let girlData = {name: name, shards: Math.min(newShards, 100)}
                            girlDictionary.set(idGirl, girlData);
                        });
                        localStorage.HHPNMap = JSON.stringify(Array.from(girlDictionary.entries()));
                    }
                    else return;
                }
            }
        })
    }

    function updateClubChampionGirlsShards() {
        if ($('.shards_wrapper').length == 0) return;

        for (var l=2; l <= $('.shards_wrapper')[0].children.length; l++) {
            let idGirlStr = $('.girl-shards-slot:nth-child(' + l + ') 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 = (girlDictionary.get(idGirl) == undefined) ? '' : girlDictionary.get(idGirl).name;
            let newShards = parseInt($('.girl-shards-slot:nth-child(' + l + ') .shards').attr('shards'), 10);
            let girlData = {name: name,
                            shards: Math.min(newShards, 100)}
            girlDictionary.set(idGirl, girlData);
        }
        localStorage.HHPNMap = JSON.stringify(Array.from(girlDictionary.entries()));

        $('.club_shards').remove();
        displayClubChampionGirlsShards();
    }

    function updateLeagueGirlShards() {
        let observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if ($('.shards_wrapper').length == 0) return;

                let idGirlStr = $('.girl-shards-slot 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 = (girlDictionary.get(idGirl) == undefined) ? '' : girlDictionary.get(idGirl).name;
                let newShards = parseInt($('.girl-shards-slot .shards').attr('shards'));
                let girlData = {name: name, shards: Math.min(newShards, 100)}
                girlDictionary.set(idGirl, girlData);

                localStorage.HHPNMap = JSON.stringify(Array.from(girlDictionary.entries()));
            })
        })

        observer.observe($('#reward_holder .container .scrolling_area')[0], {childList: true, attributes: false});
    }
}

//Remove button to access to club champion's positions during cooldown + add some datas about participation of club members
if (CurrentPage == "/clubs.html" && $('.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 = $('#club_champions_body_table > tbody:nth-child(1)')[0].children.length;
    let club_members = $('#members table tbody tr').length;

    function calculateParticipation() {
        setTimeout(function() {
            let championImpress = parseInt((JSON.parse($('.club_champions_bar_container').attr('champion-healing-tooltip')).impression_info).split('/')[1].trim().replace(/[^0-9]/gi, ''), 10);
            let list = $('#club_champions_body_table .impression')
            for (let j=0; j<list.length; j++) {
                let impress = parseInt(list[j].attributes[1].value.replace(/[^-0-9]/gi, ''), 10);
                if (impress <= 0) {
                    participants--;
                }
            }
            for (let i=0; i<list.length; i++) {
                let impress = Math.max(0, parseInt(list[i].attributes[1].value.replace(/[^-0-9]/gi, ''), 10));
                let percentage = Math.floor((impress/championImpress)*10000)/100;
                let shards = Math.ceil(percentage - 0.501) + Math.round(0.6 * Math.sqrt(parseInt(participants, 10)));
                let textImpress = $('#club_champions_body_table tbody tr:nth-child(' + (i+1) + ') > td:nth-child(4)')[0].innerText.trim();

                let newTextImpress = textImpress.concat(' / ', nThousand(percentage), '%');
                $('#club_champions_body_table tbody tr:nth-child(' + (i+1) + ') > td:nth-child(4)').empty();
                $('#club_champions_body_table tbody tr:nth-child(' + (i+1) + ') > td:nth-child(4)').append('<div>' + newTextImpress + '</div>');
                $('#club_champions_body_table tbody tr:nth-child(' + (i+1) + ') > td:nth-child(4)').append('<div>' + shards + ' <span class="shard"></span></div>');

                if ($('#club_champions_body_table tbody tr:nth-child(' + (i+1) + ')').attr('class') == "personal_highlight" && $('.girl-shards-slot .shards p span').length == 2) {
                    $('.girl-shards-slot .shards p span')[0].innerText = parseInt($('.girl-shards-slot .shards p span')[0].innerText, 10) != 100 ? shards : $('.girl-shards-slot .shards p span')[0].innerText;
                    $('.girl-shards-slot .shards p span')[1].innerText = parseInt($('.girl-shards-slot .shards p span')[1].innerText, 10) != 100 ? shards : $('.girl-shards-slot .shards p span')[1].innerText;
                }
            }
        }, 200)
    }

    function highlightMembersParticipation() {
        let clubMembers = $('#members > table > tbody > tr').toArray();
        let championPartipants = $('#club_champions_body_table > tbody > tr').toArray();
        let listChampionParticipantsId = [];
        championPartipants.forEach((participant) => {
            listChampionParticipantsId.push(participant.attributes.sorting_id.value);
        });
        clubMembers.forEach((member) => {
            if (!listChampionParticipantsId.includes(member.attributes.sorting_id.value)) {
                member.children[0].style.color = '#ffa07a';
                member.children[2].style.color = '#ffa07a';
                member.children[3].style.color = '#ffa07a';
                member.children[4].style.color = '#ffa07a';
                member.children[5].style.color = '#ffa07a';
            }
        });
    }

    calculateParticipation();

    if ($('.club_champions_timer_fight span').length) {
        highlightMembersParticipation();
    }

    let sortImpression = document.querySelector('.club_champions_head_table > thead:nth-child(1) > tr:nth-child(1) > th:nth-child(4) > span:nth-child(1)');
    sortImpression.addEventListener('click', function(){
        calculateParticipation();
    });

    let sortChallenges = document.querySelector('.club_champions_head_table > thead:nth-child(1) > tr:nth-child(1) > th:nth-child(3) > span:nth-child(1)');
    sortChallenges.addEventListener('click', function(){
        calculateParticipation();
    });

    let sortName = document.querySelector('.club_champions_head_table > thead:nth-child(1) > tr:nth-child(1) > th:nth-child(2) > span:nth-child(1)');
    sortName.addEventListener('click', function(){
        calculateParticipation();
    });

    let sortLevel = document.querySelector('.club_champions_head_table > thead:nth-child(1) > tr:nth-child(1) > th:nth-child(1) > span:nth-child(1)');
    sortLevel.addEventListener('click', function(){
        calculateParticipation();
    });

    let sortClubLevel = document.querySelector('.head_table > thead:nth-child(1) > tr:nth-child(1) > th:nth-child(1) > span:nth-child(1)');
    sortClubLevel.addEventListener('click', function(){
        if ($('.club_champions_timer_fight span').length) {
            highlightMembersParticipation();
        }
    });

    let sortClubNames = document.querySelector('.head_table > thead:nth-child(1) > tr:nth-child(1) > th:nth-child(4) > span:nth-child(1)');
    sortClubNames.addEventListener('click', function(){
        if ($('.club_champions_timer_fight span').length) {
            highlightMembersParticipation();
        }
    });

    let sortClubMojo = document.querySelector('.head_table > thead:nth-child(1) > tr:nth-child(1) > th:nth-child(5) > span:nth-child(1)');
    sortClubMojo.addEventListener('click', function(){
        if ($('.club_champions_timer_fight span').length) {
            highlightMembersParticipation();
        }
    });

    let sortClubContribution = document.querySelector('.head_table > thead:nth-child(1) > tr:nth-child(1) > th:nth-child(6) > span:nth-child(1)');
    sortClubContribution.addEventListener('click', function(){
        if ($('.club_champions_timer_fight span').length) {
            highlightMembersParticipation();
        }
    });

    function addTimeSinceStart () {
        const $timerFight = $('.club_champions_timer_fight');
        if (!$timerFight.length || !window.clubChampionsData.fight.active) {
            return;
        }

        const duration = calculateTime(window.clubChampionsData.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();

        $timerFight.append('<br/>').append(`<span>${label('clubChampDuration').replace('{{duration}}', durationString)}</span>`);
    }
    addTimeSinceStart();

    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(',','.'));
    }
    fixTimerBar();

    $('#club_champions_container .club_champions_participants_container').prepend('<div style="display: block;position: absolute;top: 15px;left: 500px;">Participants: '
                                                                                  + participants + '/' + club_members + '</div>');

    //CSS
    sheet.insertRule('#club_champions_body_table td.impression div {'
                     + 'line-height: 1.2;'
                     + 'font-size: 0.9rem;}'
                    );

    sheet.insertRule('#club_champions_body_table td.impression .shard {'
                     + 'height: 1rem;'
                     + 'width: 1rem;'
                     + 'display: inline-block;'
                     + 'background-size: 140%;'
                     + 'background-position: center;}'
                    );
}

//Add previous/next arrows in Places of Power to navigate easily between them
if (window.location.href.includes('activities.html?tab=pop&index')) {
    let currentPop = $('.pop_thumb_selected')[0].attributes.pop_id.nodeValue;
    let popList = [];
    let popAll = document.getElementsByClassName("pop_thumb");
    for (var j=0; j<popAll.length; j++) {
        var className = popAll[j].className;
        if (!className.includes('greyed')) {
            popList.push(popAll[j].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="/activities.html?tab=pop&index=' + previousPop + '" class="back_button" id="previous_pop"><span id="previous_pop_img"></span></a>');

    $('.pop_right_part a:nth-child(1)').after('<a href="/activities.html?tab=pop&index=' + nextPop + '" class="back_button" id="next_pop"><span id="next_pop_img"></span></a>');


    //CSS
    sheet.insertRule(`${mediaDesktop} {`
                     + '#previous_pop {'
                     + 'position: absolute;'
                     + 'bottom: 11px;'
                     + 'right: 224px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#previous_pop {'
                     + 'position: absolute;'
                     + 'bottom: 21px;'
                     + 'right: 227px;}}'
                    );

    sheet.insertRule('#previous_pop_img {'
                     + 'display: block;'
                     + 'width: 40px;'
                     + 'height: 40px;'
                     + 'margin: 0;'
                     + 'padding: 0;'
                     + 'background-image: url(https://cdn-icons-png.flaticon.com/64/2879/2879564.png);'
                     + 'background-size: 38px;'
                     + 'background-position: center;'
                     + 'background-repeat: no-repeat;}'
                    );


    sheet.insertRule(`${mediaDesktop} {`
                     + '#next_pop {'
                     + 'position: absolute;'
                     + 'bottom: 11px;'
                     + 'right: -56px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#next_pop {'
                     + 'position: absolute;'
                     + 'bottom: 21px;'
                     + 'right: -56px;}}'
                    );

    sheet.insertRule('#next_pop_img {'
                     + 'display: block;'
                     + 'width: 40px;'
                     + 'height: 40px;'
                     + 'margin: 0;'
                     + 'padding: 0;'
                     + 'background-image: url(https://cdn-icons-png.flaticon.com/64/2879/2879593.png);'
                     + 'background-size: 38px;'
                     + 'background-position: center;'
                     + 'background-repeat: no-repeat;}'
                    );

    sheet.insertRule('button[rel=pop_finish] {'
                     + 'margin-right: 16px;}'
                    );

    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: -15px !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;}'
                    );
}


//CSS
if ($('.script-booster-status').length == 1) {
    sheet.insertRule(`${mediaMobile} {`
                     + '.promo_profile_discount_text {'
                     + 'margin-left: 88px !important; '
                     + 'margin-top: -64px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.promo_profile_discount_text {'
                     + 'position : absolute !important;'
                     + 'top: -4px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.promo_quest_discount_text {'
                     + 'margin-left: 22px !important; '
                     + 'margin-top: -65px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.promo_quest_discount_text {'
                     + 'position : absolute !important;'
                     + 'top: -3px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '.promo_fight_discount_text {'
                     + 'margin-left: 22px !important; '
                     + 'margin-top: -64px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '.promo_fight_discount_text {'
                     + 'position : absolute !important;'
                     + 'top: -3px !important;}}'
                    );
}

sheet.insertRule(`${mediaMobile} {`
                 + '#canvas_fight_energy .energy_counter_bar .energy_counter_icon .hudBattlePts_mix_icn {'
                 + 'left: 14px;}}'
                );

sheet.insertRule(`${mediaMobile} {`
                 + '#tower_of_fame {'
                 + 'background: #222;}}'
                );

sheet.insertRule(`${mediaDesktop} {`
                 + 'body > div > header > .currency {'
                 + 'width: 192px !important;}}'
                );

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

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


//Rewards display for season fights
sheet.insertRule(`${mediaMobile} {`
                 + '.rewards_list .slot_victory_points p, .rewards_list .slot_season_xp_girl p:nth-child(3), .rewards_list .slot_season_affection_girl p:nth-child(3) {'
                 + 'font-size: 13px !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;}}'
                );


//Skip button on battle screen
if(CurrentPage.indexOf("battle") != -1) {
    if (localStorage.getItem('HHPlusPlusConfig')) {
        if (!JSON.parse(localStorage.getItem('HHPlusPlusConfig')).st_moveSkipButton) {
            sheet.insertRule('#new_battle .new-battle-buttons-container {'
                             + 'margin-top: 450px !important;}'
                            );
        }
    }
    else {
        sheet.insertRule('#new_battle .new-battle-buttons-container {'
                         + 'margin-top: 450px !important;}'
                        );
    }

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


//League display
sheet.insertRule('#leagues_left .player_block .challenge_points {'
                 + 'margin-top: 10px !important;}'
                );
sheet.insertRule('#leagues_left .player_block button.multiple-battles {'
                 + 'margin-top: 0px !important;}'
                );
sheet.insertRule('#leagues_left .player_block .challenge_points button {'
                 + 'margin-top: 0px !important;}'
                );
sheet.insertRule('#leagues_right .player_block .lead_player_profile {'
                 + 'margin-top: -5px;}'
                );

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


//CSS rule to not display the collect money animation
function moduleCollectMoneyAnimation() {
    sheet.insertRule('.collect_img {'
                     + 'display: none !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 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;'
                 + 'margin-left: 17px;}}'
                );

sheet.insertRule(`${mediaMobile} {`
                 + '#hh_hentai #pov_tab_container .potions-paths-progress-bar-section {'
                 + 'margin-top: -63px !important;}}'
                );

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


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

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


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

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


//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;'
                 + 'margin-left: 17px;}}'
                );

sheet.insertRule(`${mediaMobile} {`
                 + '#hh_hentai #pog_tab_container .potions-paths-progress-bar-section {'
                 + 'margin-top: -63px !important;}}'
                );

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

//CSS to remove scrollbars for every mission description
$('#missions > div .missions_wrap .mission_object .mission_details').css('overflow-y', 'hidden');


// Show final values when skipping battle
if(CurrentPage.indexOf("battle") != -1) {
    setTimeout(function() {
        $('#new-battle-skip-btn').show();
    }, 250);

    $(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)) {
                var 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 == undefined) return;

            var arrRounds = respBattleData.rounds;
            var rewards = respBattleData.rewards;

            var nPlayerInitialEgo = $('.new-battle-player .new-battle-hero-ego-value').data("total-ego");
            var nOpponentInitialEgo = $('.new-battle-opponent .new-battle-hero-ego-value').data("total-ego");
            var nPlayerFinalEgo = 0;
            var nOpponentFinalEgo = 0;

            var nRoundsLen = arrRounds.length;
            if(nRoundsLen >= 2) {
                var 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();

                var $playerBar = $('.new-battle-player .new-battle-hero-ego-initial-bar');
                var $playerDamageBar = $('.new-battle-player .new-battle-hero-ego-damage-bar');
                var $playerHealBar = $('.new-battle-player .new-battle-hero-ego-heal-bar');
                var $opponentBar = $('.new-battle-opponent .new-battle-hero-ego-initial-bar');
                var $opponentDamageBar = $('.new-battle-opponent .new-battle-hero-ego-damage-bar');
                var $opponentHealBar = $('.new-battle-opponent .new-battle-hero-ego-heal-bar');

                var $playerEgo = $('.new-battle-player .new-battle-hero-ego-value');
                var $opponentEgo = $('.new-battle-opponent .new-battle-hero-ego-value');
                var $playerDamageDone = $('.new-battle-opponent .new-battle-hero-damage-taken-text');
                var $opponentDamageDone = $('.new-battle-player .new-battle-hero-damage-taken-text');
                var $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');

                var strPlayerCurEgo = $playerEgo.text().split(window.GT.ego)[1].replace(/[, ]/g, "");
                var nPlayerCurEgo = nPlayerInitialEgo;
                if($.isNumeric(strPlayerCurEgo)) {
                    nPlayerCurEgo = parseInt(strPlayerCurEgo);
                }
                var strOpponentCurEgo = $opponentEgo.text().split(window.GT.ego)[1].replace(/[, ]/g, "");
                var nOpponentCurEgo = nOpponentInitialEgo;
                if($.isNumeric(strOpponentCurEgo)) {
                    nOpponentCurEgo = parseInt(strOpponentCurEgo);
                }

                var nPlayerCompleteAtk = nOpponentCurEgo - nOpponentFinalEgo;
                var nOpponentCompleteAtk = nPlayerCurEgo - nPlayerFinalEgo;
                $playerDamageDone.text(nPlayerCompleteAtk.toString());
                $opponentDamageDone.text(nOpponentCompleteAtk.toString());

                var fPlayerEgoBarWidth = nPlayerFinalEgo <= 0 ? 0 : nPlayerFinalEgo / nPlayerInitialEgo * 100.0;
                var fOpponentEgoBarWidth = nOpponentFinalEgo <= 0 ? 0 : nOpponentFinalEgo / nOpponentInitialEgo * 100.0;

                var 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 + " " + nPlayerFinalEgo.toString());
                            $(elm).velocity({ translateY: 0 }, 0)
                        }
                    }
                    }
                ];
                var 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 + " " + nOpponentFinalEgo.toString());
                            $(elm).velocity({ translateY: 0 }, 0)
                        }
                    }
                    }
                ];

                $('.velocity-animating').velocity("stop", true);
                window.newBattles.setRounds([]);
                $.Velocity.RunSequence(arrPlayerAnimationSequence);
                $.Velocity.RunSequence(arrOpponentAnimationSequence);
                setTimeout(function() {window.Reward.handlePopup(rewards)}, 800);
            });
        }
    });
}

//Display your ranking in Path of Valor or Path of Glory at the bottom of the screen if you are in the top 1000
if (CurrentPage.includes('path-of-valor') || CurrentPage.includes('path-of-glory')) {
    function displayRanking(location) {
        if ($('#' + location + '_leaderboard_tab_container .leaderboard_row.hero-rowbuild-at-bottom').length > 0) {
            return;
        }

        let i=1;
        while((($('#' + location + '_leaderboard_tab_container > #leaderboard_holder > #leaderboard_list > div.leaderboard_row:nth-child(' + i + ')').css('color') != "rgb(34, 150, 228)") && ($('#' + location + '_leaderboard_tab_container > #leaderboard_holder > #leaderboard_list > div.leaderboard_row:nth-child(' + i + ')').css('color') != "rgb(55, 160, 231)")) && (i < 1000)) {
            i++;
        }
        if (($('#' + location + '_leaderboard_tab_container > #leaderboard_holder > #leaderboard_list > div.leaderboard_row:nth-child(' + i + ')').css('color') == "rgb(34, 150, 228)") || ($('#' + location + '_leaderboard_tab_container > #leaderboard_holder > #leaderboard_list > div.leaderboard_row:nth-child(' + i + ')').css('color') == "rgb(55, 160, 231)")) {
            let player_row = $('#' + location + '_leaderboard_tab_container > #leaderboard_holder > #leaderboard_list > div.leaderboard_row:nth-child(' + i + '').clone();
            player_row.css('position', 'fixed');
            player_row.css('width', '904px');
            $('#' + location + '_leaderboard_tab_container > #leaderboard_holder > #leaderboard_list > div.leaderboard_row:nth-child(1000)').after(player_row);
        }

        //CSS
        $('#leaderboard_list')[0].children[1000].style.removeProperty('bottom');

        sheet.insertRule(`${mediaDesktop} {`
                         + '.leaderboard_row:nth-child(1001) {'
                         + 'bottom: 20px;}}'
                        );

        sheet.insertRule(`${mediaMobile} {`
                         + '.leaderboard_row:nth-child(1001) {'
                         + 'bottom: 20px;}}'
                        );
    }

    setTimeout(function(){
        let leaderboard_pov = document.querySelector('#potions-paths-tabs #pov_leaderboard_tab');
        let leaderboard_pog = document.querySelector('#potions-paths-tabs #pog_leaderboard_tab');
        leaderboard_pog.addEventListener('click', function() {
            setTimeout(function(){displayRanking('pog')}, 1000)
        });
        leaderboard_pov.addEventListener('click', function() {
            setTimeout(function(){displayRanking('pov')}, 1000)
        });
    }, 200);
}

//Change the defaut tab in Activities to Missions
function moduleActivitiesTabChoice() {
    $('#homepage').find('[rel=activities]')[0].href = "/activities.html?tab=missions";
}

//Fix a bug with decimal separator in daily goals
if (CurrentPage.indexOf('activities') > 0) {
    for(var k = 0; k < $('#daily_goals .objective-progress-bar-fill').length; k++){
        $('#daily_goals .objective-progress-bar-fill')[k].attributes.style.value = $('#daily_goals .objective-progress-bar-fill')[k].attributes.style.value.replace(',', '.');
    }
}

//Change items order on home screen
function moduleCustomizedHomeScreen() {
    let clubLink = $('.left-side-container')[0].children[7];
    clubLink.attributes.href.value = "/clubs.html"
    $('.left-side-container')[0].children[7].remove();

    let sex_god_path_link = $('.left-side-container')[0].children[6];
    let pachinkoLink = $('.left-side-container')[0].children[5];
    let tofLink = $('.left-side-container')[0].children[3];
    let haremLink = $('.left-side-container')[0].children[1];
    let marketLink = $('.left-side-container')[0].children[4];
    let activitiesLink = $('.left-side-container')[0].children[2];

    $('.left-side-container')[0].children[6].remove();
    $('.left-side-container')[0].children[5].remove();
    $('.left-side-container')[0].children[4].remove();
    $('.left-side-container')[0].children[3].remove();
    $('.left-side-container')[0].children[2].remove();
    $('.left-side-container')[0].children[1].remove();
    $('.left-side-container')[0].append(activitiesLink);
    $('.left-side-container')[0].append(haremLink);
    $('.left-side-container')[0].append(marketLink);
    $('.left-side-container')[0].append(tofLink);
    $('.left-side-container')[0].append(pachinkoLink);
    $('.left-side-container')[0].append(sex_god_path_link);
    $('.left-side-container')[0].append(clubLink);

    $('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;">');

    //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 .season-pov-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-pov-container .season-button > a > .notif-position > span, #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-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-container {'
                     + '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-container {'
                     + 'top: -10px;'
                     + 'left: 16px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .bundles .timer-container {'
                     + '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 {'
                     + 'position: absolute;'
                     + 'bottom: 81px;'
                     + 'right: -8px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .season-pov-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: 5px;'
                     + 'transform: scale(0.7);}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .bottom-container .info-container {'
                     + 'z-index: 2;'
                     + 'position: absolute;'
                     + 'right: -10px;'
                     + 'bottom: 2px;'
                     + 'transform: scale(0.68);}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_comix #homepage .bottom-container .info-container {'
                     + 'right: 35px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_comix #homepage .bottom-container .info-container {'
                     + 'right: 25px !important;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#hh_star #homepage .bottom-container .info-container {'
                     + 'right: 50px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_star #homepage .bottom-container .info-container {'
                     + 'right: 24px !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 {'
                     + 'position: fixed;'
                     + 'z-index: 1;'
                     + 'transform: scale(0.7);'
                     + 'width: max-content;'
                     + 'bottom: -10px;'
                     + 'left: -54px;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#hh_comix #homepage .social_links {'
                     + 'left: -57px !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;'
                     + 'margin-left: -15px;}'
                    );

    if (window.seasonal_event_active) {
        sheet.insertRule('#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .event-widget-container .event-widget {'
                         + 'margin-bottom: -32px;}'
                        );
    }
    else {
        sheet.insertRule('#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .event-widget-container .event-widget {'
                         + 'margin-bottom: -122px;}'
                        );
    }

    sheet.insertRule('#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-container .seasonal-event {'
                     + 'position: absolute;'
                     + 'left: -226px;'
                     + 'width: 227px;}'
                    );

    sheet.insertRule('#hh_comix #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-container .seasonal-event {'
                     + 'left: -234px !important;}'
                    );

    sheet.insertRule('#hh_hentai #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-container .seasonal-event {'
                     + 'top: 206px;}'
                    );

    sheet.insertRule('#hh_star #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-container .seasonal-event {'
                     + 'top: 132px;}'
                    );

    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 .season-pov-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 .season-pov-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 .season-pov-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;}}'
                    );

    sheet.insertRule(`${mediaDesktop} {`
                     + '#homepage .main-container .middle-container .waifu-and-right-side-container .waifu-container .animated-girl-display {'
                     + 'top: 13rem !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;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .main-container .middle-container .waifu-and-right-side-container .waifu-container .animated-girl-display {'
                     + 'top: 12.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 .season-pov-container .pov-button > a > .button-notification-icon, #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-container .season-button > a > .button-notification-icon {'
                     + 'left: 221px !important;}}'
                    );

    sheet.insertRule(`${mediaMobile} {`
                     + '#homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-container .pov-button > a > .button-notification-icon, #homepage .main-container .middle-container .waifu-and-right-side-container .right-side-container .event-container .season-pov-container .season-button > a > .button-notification-icon {'
                     + '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;}'
                    );
}

//Hide claimed rewards in season, PoV, PoG and PoA
function moduleHideClaimedRewards() {
    const POV_REM_PER_GROUP = 0.3 + 3.6; // margin-top + height
    const POV_PX_PER_GROUP = POV_REM_PER_GROUP * 16;
    const SEASON_TIER_WIDTH = 69.6;

    if(CurrentPage == "/path-of-valor.html" || CurrentPage == "/path-of-glory.html") {
        let hidden = false;
        const $groupsToHide = $('.potions-paths-tier:not(.unclaimed):has(.claimed-slot)');
        const $groupsRemaining = $('.potions-paths-tier.unclaimed');
        const claimedCount = $groupsToHide.length;
        const 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 = () => {
            if (claimedCount === 0) {
                // nothing to do
                return
            }

            $groupsToHide.addClass('script-hide-claimed');
            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};`))
            }
        }

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

    if(CurrentPage == "/season.html") {
        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), 200);
            }
        }
        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);
    }

    if(CurrentPage == "/event.html") {
        if(!$('a.active[href*="?tab=path_event_"]').length){return}

        const {bonusRewardsUnlocked} = window;

        const assertHidden = () => {
            $('.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');
                }
            })
        }
        const assertShown = () => {
            $('.nc-poa-reward-pair').removeClass('script-hide-claimed');
        }
        const fixScroll = () => {
            $('.scroll-area').getNiceScroll().resize();
        }
        assertHidden();
        fixScroll();
        const toggle = () => {
            if ($('.script-hide-claimed').length) {
                assertShown();
            } else {
                assertHidden();
            }
            fixScroll();
        }
        $('#poa-content .girls').click(()=>{toggle()});

        sheet.insertRule('.script-hide-claimed {'
                         + 'display: none;}'
                        );
    }

    if(CurrentPage == "/seasonal.html") {
        const width_px_Tweaks = 104.03;
        const start_px_Tweaks = 52;

        const width_px = 152.1;
        const start_px = 101;

        let rewards_unclaimed = 0;
        let rewards_hidden = 0;
        let scroll_width = 0;
        let scroll_width_hidden = 0;
        let scrollbar_width_new = 0;
        const scrollbar_width_init_Tweaks = 72;
        const scrollbar_width_init = 49;

        let init = true;

        const assertHidden = (shouldScroll) => {
            $('.seasonal-tier-container').each((i, el) => {
                const $reward = $(el).find('.free-slot');
                if ( $reward.hasClass('claimed-slot') ) {
                    $(el).addClass('script-hide-claimed');
                }
            })

            const $rowScroll = $('.seasonal-progress-bar-section');
            $rowScroll.getNiceScroll().resize();

            rewards_unclaimed = $('.seasonal-tier.unclaimed').length;
            rewards_hidden = $('.script-hide-claimed').length;

            if (localStorage.getItem('HHPlusPlusConfig') == undefined) {
                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);
            }
            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);
                }
            }
            $('.seasonal-progress-bar-current').css('width', scroll_width_hidden + 'px');

            function hideClaimedRewards() {
                let left = 0;
                scrollbar_width_new = parseInt($('#ascrail2000-hr .nicescroll-cursors').css('width'), 10);
                if (localStorage.getItem('HHPlusPlusConfig') == undefined) {
                    left = parseInt(152 * (scrollbar_width_new/scrollbar_width_init) * Math.max(0, (rewards_unclaimed - 3)), 10);
                }
                else {
                    if (JSON.parse(localStorage.getItem('HHPlusPlusConfig')).st_seasonalEventTweaks) {
                        left = parseInt(59 * (scrollbar_width_new/scrollbar_width_init_Tweaks) * Math.max(0, (rewards_unclaimed - 3)), 10);
                    }
                    else {
                        left = parseInt(90 * (scrollbar_width_new/scrollbar_width_init) * Math.max(0, (rewards_unclaimed - 3)), 10);
                    }
                }
                try {
                    $('.seasonal-progress-bar-section').getNiceScroll(0).doScrollLeft(left, 200);
                } catch(err) {}
            }

            if (shouldScroll) {
                if (init) {
                    setTimeout(function() {
                        $('.seasonal-progress-bar-section').getNiceScroll().resize();
                        hideClaimedRewards();
                        init = false;
                    }, 1000);
                } else {
                    hideClaimedRewards();
                }
            }
        }

        const assertShown = (shouldScroll) => {
            $('.seasonal-tier-container').removeClass('script-hide-claimed');

            $('.seasonal-progress-bar-current').css('width', scroll_width + 'px');

            const $rowScroll = $('.seasonal-progress-bar-section');
            $rowScroll.getNiceScroll().resize();

            if (shouldScroll) {
                let right = 0;
                if (localStorage.getItem('HHPlusPlusConfig') == undefined) {
                    right = parseInt((rewards_unclaimed + rewards_hidden - 3) * width_px, 10);
                }
                else {
                    if (JSON.parse(localStorage.getItem('HHPlusPlusConfig')).st_seasonalEventTweaks) {
                        right = parseInt((rewards_unclaimed + rewards_hidden - 3) * width_px_Tweaks, 10);
                    }
                    else {
                        right = parseInt((rewards_unclaimed + rewards_hidden - 3) * width_px, 10);
                    }
                }
                try {
                    $('.seasonal-progress-bar-section').getNiceScroll(0).doScrollLeft(right, 200);
                } catch(err) {}
            }
        }

        assertHidden(true);

        const toggle = () => {
            if ($('.script-hide-claimed').length) {
                assertShown(true);
            } else {
                assertHidden(true);
            }
        }
        $('#home_tab_container .girls-reward-container').click(()=>{toggle()});
    }

    //CSS
    sheet.insertRule('.script-hide-claimed {'
                     + 'display: none !important;}'
                    );
}

//Force desktop display on mobile
function moduleDesktopDisplay() {
    var 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', '');
    }

    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', '');
            }, 200);
        }, {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', '');
            }, 200);
        }, {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', '');
            }, 200);
        }, {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', '');
            }, 200);
        }, {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', '');
                }, 200);
            }, {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', '');
                }, 200);
            }, {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', '');
    }
}

if(CurrentPage == "/event.html") {
    if(!$('a.active[href*="?tab=sm_event_"]').length) return;

    const observer1 = new MutationObserver(() => {
        if(!$('#shop_tab.underline-tab').length) return;

        setTimeout(function(){
            let sultry_coins = $('.sultry-mysteries-container .sm-sidebar .dynamic-sidebar.shop-sidebar .coins-section > p .coins-amount')[0].innerHTML;
            localStorage.setItem('HHS.sultry_coins', sultry_coins);

            const observer2 = new MutationObserver(() => {
                sultry_coins = $('.sultry-mysteries-container .sm-sidebar .dynamic-sidebar.shop-sidebar .coins-section > p .coins-amount')[0].innerHTML;
                localStorage.setItem('HHS.sultry_coins', sultry_coins);
            })
            observer2.observe($('.sultry-mysteries-container .sm-sidebar .dynamic-sidebar.shop-sidebar .coins-section > p .coins-amount')[0], {childList: true});
        }, 500);
    })
    observer1.observe($('#shop_tab')[0], {attributes: true, attributeFilter: ['class']});
}