AREDL demon position

Show AREDL position instead of Pointercrate

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