AREDL demon position

Show AREDL position instead of Pointercrate

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         AREDL demon position
// @namespace    algolineu
// @version      1.0
// @description  Show AREDL position instead of Pointercrate
// @author       You
// @match        https://gdbrowser.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=aredl.net
// @grant        GM_xmlhttpRequest
// @connect      api.aredl.net
// @run-at       document-end
// @license      MIT
// ==/UserScript==


(async function() {
    'use strict';

    const match = location.pathname.match(/^\/(\d+)$/);
    if (!match) return;

    const starsElement = document.querySelector("h1.smaller.inline.stars");
    if (!starsElement || starsElement.innerHTML.trim() !== "10") return;

    const id = match[1];
    const data = await fetchAREDLinfos(id);

    let listPositionElement = document.querySelector('h1.smaller.inline.demonList');
    let listPositionImage = document.querySelector('img.inline.demonList');
    if ( data.position == null ) {
        if (listPositionImage) {
            listPositionImage.title = "Pointercrate position";
        }
        return;
    }
    if (!listPositionElement)
    {
        const starsBreakElement = document.querySelector("br.stars");

        listPositionElement = document.createElement('h1');
        listPositionElement.classList.add("smaller", "inline", "demonList");
        listPositionElement.style = "transform: scale(0.9);";

        //<img class="inline demonList" src="../assets/demon.png" height="4.5%;" style="transform: translateY(-7%); margin-left: 1.5%;">

        listPositionImage = document.createElement('img');
        listPositionImage.classList.add("inline", "demonList");
        listPositionImage.src = "../assets/demon.png";
        listPositionImage.setAttribute("height", "4.5%");
        listPositionImage.style = "transform: translateY(-7%); margin-left: 1.5%;";

        starsBreakElement.insertAdjacentElement('afterend', listPositionElement);
        listPositionElement.insertAdjacentElement('afterend', listPositionImage);
    };

    const difficultyTextElement = document.querySelector('#difficultytext');


    if ( data.position > 150 )
    {
        listPositionImage.title = "AREDL position (click to open)";
        // listPositionImage.src = "https://aredl.net/favicon.ico";

        listPositionImage.addEventListener('click', () => {
            window.open('https://aredl.net/list/' + id, '_blank');
    });

    }
    else
    {
        listPositionImage.title = "Pointercrate position (click to open)";
        // listPositionImage.src = "../assets/difficulties/demon-extreme.png";

        listPositionImage.addEventListener('click', () => {
            window.open('https://pointercrate.com/demonlist/' + data.position, '_blank');
    });

    }

    listPositionElement.textContent = `#${data.position}`;

    if ( data.description != null )
    {
        listPositionElement.title = data.description;
        listPositionElement.classList.add("help");
    }

    if ( data.nlw_tier != null )
    {

        difficultyTextElement.textContent = data.nlw_tier;
        const tierColors = {
            "Fuck": "#000000",

            "Beginner": "#4a86e8",
            "Easy": "#00ffff",
            "Medium": "#00ff00",
            "Hard": "#ffff00",
            "Very Hard": "#ff9900",
            "Insane": "#ff0000",
            "Extreme": "#ff00ff",
            "Remorseless": "#9900ff",
            "Relentless": "#b087eb",
            "Terrifying": "#f19eea",
            "Catastrophic": "#ea6661",
            "Inexorable": "#ffc183",
            "Excruciating": "#ffe599",
            "Merciless": "#a7e58d",
            "Monstrous": "#5bad96",
            "Apocalyptic": "#528cb1",
            "Demonic": "#6d6ab0",
            "Menacing": "#9452a2",
            "Unreal": "#913869",
            "Nightmare": "#832828",
        };

        difficultyTextElement.style.color =
            tierColors[data.nlw_tier] ?? "#FFFFFF";
    }
})();

function fetchAREDLinfos(id) {
    return new Promise(resolve => {
        GM_xmlhttpRequest({
            method: "GET",
            url: "https://api.aredl.net/v2/api/aredl/levels/" + id,
            headers: { "Accept": "application/json" },
            onload: function(response) {
                try {
                    const data = JSON.parse(response.responseText);
                    resolve(data);
                } catch (e) {
                    console.error("Failed to parse JSON:", e);
                    resolve(null);
                }
            },
            onerror: () => resolve(null)
        });
    });
}