hideLeetCodePlus

Hide Leetcode Plus Problems

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         hideLeetCodePlus
// @name:zh-CN   隐藏力扣Plus题目
// @namespace    mailto: [email protected]
// @version      0.4.2
// @license      MIT
// @description  Hide Leetcode Plus Problems
// @description:zh-CN 隐藏 Leetcode Plus 题目
// @author       fish-404
// @match        https://leetcode.cn/problemset/*
// @match        https://leetcode.cn/tag/*
// @match        https://leetcode.cn/problem-list/*
// @match        https://leetcode.com/problemset/*
// @match        https://leetcode.com/problem-list/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=leetcode.cn
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const url = window.location.href;
    let problemsNode, tagFlag, observer;

    const config = {
        subtree: true
        , childList: true
    };

    if (url.includes("tag")) { // problemsets with tags
        console.log("tag: true");
        const container = document.querySelector("div#lc-content");
        observer = new MutationObserver(()=>{
            let tbody = document.querySelector("tbody.ant-table-tbody");
            if (tbody) {
                const innerObserver = new MutationObserver(hidePlusProblemsWithTag);
                innerObserver.observe(container, config);
            }
        });
        observer.observe(container, config);
    }
    else {
        problemsNode = document.querySelector("div[role='table']");
        observer = new MutationObserver(hidePlusProblemsWithoutTag);
        observer.observe(problemsNode, config);
    }
})();

function hidePlusProblemsWithoutTag(mutationList, observer) {
    let preTargetRow;
    mutationList.forEach((mutation) => {
        let target;
        if (mutation.addedNodes.length > 0) {
            target = mutation.addedNodes[0];
        }
        else {
            target = mutation.target;
        }
        let curTargetRow = target.closest("div[role='row']");
        if (curTargetRow !== null && curTargetRow !== preTargetRow) {
            preTargetRow = curTargetRow;
            let searchPlus = curTargetRow.querySelector("svg.text-brand-orange");
            changeElementDisplay(curTargetRow, searchPlus === null);
        }
    });
}

function hidePlusProblemsWithTag(mutationList) {
    mutationList.forEach((mutation) => {
        console.log(mutation);
        if (mutation.addedNodes.length > 0) {
            let curTargetRow = mutation.addedNodes[0];
            let searchPlus = curTargetRow.querySelector("img[alt='plus']");
            console.log(searchPlus);
            if (searchPlus) {
                curTargetRow.style.display = "none";
            }
        }
    });
}

function changeElementDisplay(element, displayOrNot) {
    const SHOW = "flex", HIDE = "none";
    element.style.display = displayOrNot ? SHOW : HIDE;
}