Melvor Completion Log Helper

The completion logs now show images of undiscovered items/monsters/pets, including those entities that do not count towards completion.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Melvor Completion Log Helper
// @namespace   http://tampermonkey.net/
// @version     0.7.1
// @description The completion logs now show images of undiscovered items/monsters/pets, including those entities that do not count towards completion.
// @author		GMiclotte
// @include		https://melvoridle.com/*
// @include		https://*.melvoridle.com/*
// @exclude		https://melvoridle.com/index.php
// @exclude		https://*.melvoridle.com/index.php
// @exclude		https://wiki.melvoridle.com/*
// @exclude		https://*.wiki.melvoridle.com/*
// @inject-into page
// @noframes
// @grant		none
// ==/UserScript==
/* jshint esversion: 6 */

// Thanks to Breindahl#2660 for the original implementation
// Big thanks to Visua#9999 for helping with parts of the code and troubleshooting

((main) => {
    const script = document.createElement('script');
    script.textContent = `try { (${main})(); } catch (e) { console.log(e); }`;
    document.body.appendChild(script).parentNode.removeChild(script);
})(() => {

    function patchCode(code, additionalPatch) {
        code = code.toString();
        code = code.replace(/!items\[[a-zA-Z]*\].ignoreCompletion/g, 'true');
        code = code.replace(/!MONSTERS\[[a-zA-Z]*\].ignoreCompletion/g, 'true');
        code = code.replace(/!PETS\[[a-zA-Z]*\].ignoreCompletion/g, 'true');
        if (additionalPatch !== undefined) {
            code = additionalPatch(code);
        }
        return code.replace(/^function (\w+)/, 'window.$1 = function');
    }

    const toPatch = [
        filterItemLog,
        createItemLogTooltip,
        createMonsterLogTooltip,
        createPetLogTooltip,
    ];

    function additionalPatchApplyCompletionLogEntryElement(code) {
        code = code.split(/Element\(-8,/);
        for (let i = 1; i < code.length; i++) {
            code[i] = code[i].replace(';', `; const htmlIdx = html.lastIndexOf('<img ') + 5; html = html.substring(0, htmlIdx) + 'style="opacity: 25%"' + html.substring(htmlIdx); `);
        }
        return code.join('Element(id,');
    }

    function startCompletionLogHelper() {
        // patch functions
        toPatch.forEach(x => eval(patchCode(x)));
        eval(patchCode(applyCompletionLogEntryElement, additionalPatchApplyCompletionLogEntryElement));

        // reset loaded variables
        itemLogLoaded = false;
        monsterLogLoaded = false;
        petLogLoaded = false;

        // build Monster and pet logs
        buildMonsterLog();
        buildPetLog();

        // logging
        console.log('Melvor Completion Log Helper Loaded');
    }

    function loadScript() {
        if (typeof confirmedLoaded !== typeof undefined && confirmedLoaded) {
            clearInterval(scriptLoader);
            startCompletionLogHelper();
        }
    }

    const scriptLoader = setInterval(loadScript, 200);
});