Leetcode Question Difficulty Hider

Hide the difficulty tag on a leetcode question page with a reveal option.

Verze ze dne 24. 05. 2024. Zobrazit nejnovější verzi.

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

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 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         Leetcode Question Difficulty Hider
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Hide the difficulty tag on a leetcode question page with a reveal option.
// @author       DoubleX
// @match        https://leetcode.com/problems/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=leetcode.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function waitForElm(selector) {
        return new Promise(resolve => {
            if (document.querySelector(selector)) {
                return resolve(document.querySelector(selector));
            }

            const observer = new MutationObserver(mutations => {
                if (document.querySelector(selector)) {
                    observer.disconnect();
                    resolve(document.querySelector(selector));
                }
            });

            observer.observe(document.body, {
                childList: true,
                subtree: true
            });
        });
    }

    function revealDiff(selector, diffcolor, difftext) {
        waitForElm(selector).then((ele) => {
            ele.style.backgroundColor = "black";
            ele.style.color = "white";
            ele.innerText = "Reveal";
            ele.style.cursor = "pointer";
            ele.toggled = false;
            ele.onclick = (e) => {
                if (ele.toggled) {
                    ele.style.backgroundColor = "black";
                    ele.style.color = "white";
                    ele.innerText = "Reveal";
                    ele.toggled = false;
                }
                else {
                    ele.style.backgroundColor = "var(--fill-secondary)";
                    ele.style.color = diffcolor;
                    ele.innerText = difftext;
                    ele.toggled = true;
                }
            }
        });
    }

    function setup(){
        revealDiff(".text-difficulty-hard", "var(--difficulty-hard)", "Hard");
        revealDiff(".text-difficulty-medium", "var(--difficulty-medium)", "Medium");
        revealDiff(".text-difficulty-easy", "var(--difficulty-easy)", "Easy");
    };

    if (document.readyState !== 'loading') {
        setup();
    } else {
        document.addEventListener('DOMContentLoaded', function () {
            setup();
        });
    }
})();