Norroth Helpers

Norroth General Purpose

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Norroth Helpers
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  Norroth General Purpose
// @author       Xortrox
// @contributor  Lats
// @match        https://www.norroth.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const moduleName = 'Norroth General Purpose';
    const version = 0.7;

    function appendCSS(css) {
        let head = document.head || document.getElementsByTagName('head')[0];
        let style = document.createElement('style');

        head.appendChild(style);

        style.type = 'text/css';
        if (style.styleSheet){
            // This is required for IE8 and below.
            style.styleSheet.cssText = css;
        } else {
            style.appendChild(document.createTextNode(css));
        }
    }

    function loadCSS() {
        appendCSS('td>a>img {border: 1px solid rgba(255,0,0,0.3) !important; }');
        appendCSS('.tab_content .scroll { height: 250px !important; }');
        appendCSS('.equipment_item, .inv_slot, .stash_slot { position: relative; }');
        appendCSS('[data-addons-quality]::after {content: attr(data-addons-quality); position: absolute; left: 0; top: 0; padding: 3px;}');
    }

    $(document).ready(() => {
        loadCSS();

        setInterval(() => {
            $('.equipment_item, .inv_slot, .stash_slot').each(function(itemIndex, item) {
                if (!this.children[0]) { return; }
                if (!this.children[0].getAttribute('content')) { return; }

                let content = this.children[0].getAttribute('content').toLowerCase();
                if (content.includes('ring') || content.includes('necklace') || content.includes('amulet')){ return; }

                if (this.getAttribute('data-addons-quality')) { return; }

                applyQualityTag(content, this);

                applyDurabilityTag(content, item);
            });
        }, 500);
    });

    function applyQualityTag(content, slot) {
        let searchTerm = 'quality:';
        let indexStart = content.indexOf(searchTerm);
        if (indexStart === -1) { return; }

        let quality = content.substr(indexStart)
        quality = quality.substr(0, quality.indexOf('<br>'));
        quality = quality.substr(searchTerm.length);
        slot.setAttribute('data-addons-quality', `Q${quality}`);
    }

    function applyDurabilityTag(content, item) {
        let searchTerm = 'durability:';

        let durStart = content.indexOf(searchTerm);
        if (durStart === -1) { return; }

        item = $(item);
        let customOverlay = item.find('.custom-overlay');
        if (customOverlay.length === 0) {
            customOverlay = document.createElement('div');
            customOverlay.setAttribute('style', 'background: transparent; position: absolute; right:0; bottom:0; padding-right: 3px; pointer-events: none;');

            let durability = content.substr(durStart)
            durability = durability.substr(0, durability.indexOf('/'));
            durability = durability.substr(searchTerm.length);

            customOverlay.innerHTML = `${durability}`;
            item.append(customOverlay);
            customOverlay = $(customOverlay);
        }
    }
})();