HH Unlock Images

This script unlocks images of both recruited girls and non-recruited girls.

Від 23.08.2020. Дивіться остання версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         HH Unlock Images
// @namespace    hhUnlock
// @version      1.0
// @description  This script unlocks images of both recruited girls and non-recruited girls.
// @author       YanDee
// @match        *://nutaku.haremheroes.com/*
// @match        *://*.hentaiheroes.com/*
// @grant        none
// ==/UserScript==

(function() {
    if (document.visibilityState == 'hidden' || window.location.pathname.indexOf('harem') == -1){
        return;
    }
    var curGID, curImg, totalIncome, incomeNode, vanilNode, $ = window.$, GT = window.GT;
    var girlsDataList = window.girlsDataList, number_format_lang = window.number_format_lang, number_reduce = window.number_reduce;
    var toggleMode = function(){
        sessionStorage.haremLevDispMode = (sessionStorage.haremLevDispMode != 'income') ? 'income' : 'default';
        applyMode();
    };
    var applyMode = function(){
        $('div.girls_levels > *').remove();
        if (sessionStorage.haremLevDispMode != 'default'){
            $('div.girls_levels').append(incomeNode);
            $('div.girls_levels > p:has(br)').css('margin', 0);
            return 'income';
        } else {
            $('div.girls_levels').append(vanilNode);
        }
    };
    var treatment = function(){
        curGID = $('#harem_right div.opened').attr('girl');
        if (girlsDataList[curGID].own){
            curImg = (girlsDataList[curGID].fav_graded >= 0) ? girlsDataList[curGID].fav_graded : girlsDataList[curGID].graded;
            $('#harem_right div.diamond:not([grade="' + curImg + '"])').on('click.hhUnlock', clickHandler);
            $('#harem_right div.diamond.locked').css('cursor', 'pointer');
            var totIn = (totalIncome > 1e6) ? number_reduce(totalIncome) : number_format_lang(totalIncome);
            var totDayIn = (24 * totalIncome >= 1e6) ? number_reduce(24 * totalIncome) : number_format_lang(24 * totalIncome);
            incomeNode = '<span class="hudSC_mix_icn"></span><p><span class="pompous_text">' + GT.design.haremdex_income + ': </span></p>';
            incomeNode += '<p><span class="focus_text" hh_title="' + number_format_lang(totalIncome) + ' / ' + GT.time.h + '" tooltip-id="tooltip_1"> ';
            incomeNode += totIn + ' / ' + GT.time.h + '</span><br><span class="focus_text" hh_title="' + number_format_lang(24 * totalIncome);
            incomeNode += ' / ' + GT.time.d + '" tooltip-id="tooltip_1">' + totDayIn + ' / ' + GT.time.d + '</span></p>';
            vanilNode = $('div.girls_levels > *').clone();
            $('div.girls_levels').on('click', toggleMode).css('cursor', 'pointer');
            sessionStorage.haremLevDispMode = (sessionStorage.haremLevDispMode != 'default') ? applyMode() : 'default';
        } else {
            curImg = 0;
            $('#harem_right img.avatar').css('filter', 'none');
            replaceAva(0);
            $('#harem_right div.middle_part.missing_girl').css('margin-top', '0');
            $('#harem_right img.avatar').before(getHeader()).after(getDiamondBar());
            $('#harem_right div.diamond.locked').on('click.hhUnlock', clickHandler);
        }
    };
    var clickHandler = function(){
        var nextSel = $(this);
        if (nextSel.attr('grade') != curImg){
            if (girlsDataList[curGID].own){
                curImg = nextSel.attr('grade');
                $('#harem_right div.diamond').off('click.hhUnlock');
                var favImg = (girlsDataList[curGID].fav_graded >= 0) ? girlsDataList[curGID].fav_graded : girlsDataList[curGID].graded;
                if (curImg > girlsDataList[curGID].graded || curImg == favImg){
                    replaceAva(curImg);
                }
                $('#harem_right div.diamond').off('click.hhUnlock');
                $('#harem_right div.diamond:not([grade="' + curImg + '"])').on('click.hhUnlock', clickHandler).css('cursor', 'pointer');
                nextSel.css('cursor', 'default');
            } else {
                $('#harem_right div.diamond[grade="' + curImg + '"]').removeClass('selected').addClass('locked');
                curImg = nextSel.attr('grade');
                replaceAva(curImg);
                $(this).removeClass('locked').addClass('selected');
                $('#harem_right div.diamond.locked').css('cursor', 'pointer');
                $('#harem_right div.diamond.selected').css('cursor', 'default');
                $('#harem_right div.diamond').off('click.hhUnlock');
                $('#harem_right div.diamond.locked').on('click.hhUnlock', clickHandler);
            }
        }
    };
    var getDiamondBar = function(){
        var body = '<div class="diamond-bar"><div class="diamond selected" style="cursor:default" grade="0"></div>';
        for (var i = 1; i <= (girlsDataList[curGID].Graded2.match(/<g[^>]*>[^<>]*<[^>]*\/g>/gi) || []).length; i++) {
            body += '<div class="diamond locked" style="cursor:pointer" grade="' + i + '"></div>';
        }
        body += '</div>';
        return body;
    };
    var getHeader = function(){
        var g_name = (girlsDataList[curGID].ref.full_name != undefined) ? girlsDataList[curGID].ref.full_name : girlsDataList[curGID].Name
        var g_rar = girlsDataList[curGID].rarity;
        var g_class = $('div.girls_list div[id_girl="' + curGID + '"] div.icon').attr('carac');
        var body = '<h3>' + g_name + '<span carac="class' + g_class + '"></span></h3>';
        body += '<p class="girl-rarity ' + g_rar + '"> ' + GT.design["girls_rarity_" + g_rar] + '</p>';
        return body;
    };
    var replaceAva = function(num){
        var node = $('#harem_right img.avatar').clone();
        node.attr('src', function(index, src) {
            return src.replace(/av(a|b)\d(?=\.)/g, 'ava' + num);
        });
        $('#harem_right img.avatar').replaceWith(node);
    };
    var calcTotalIncome = function() {
        totalIncome = 0;
        for (var id in girlsDataList) {
            if(girlsDataList[id].own){
                totalIncome += Math.round(girlsDataList[id].salary_per_hour);
            }
        }
    };

    var watcher = new MutationObserver(function(){
        treatment();
    });
    watcher.observe(document.querySelector('#harem_right'), {childList: true});
    calcTotalIncome();
    treatment();
})();