洛谷负优化插件

· · 个人记录

// ==UserScript==
// @name         洛谷页面精简助手
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  自动删除洛谷的冗余模块
// @author       Moonlighthuanxiyun
// @match        https://www.luogu.com.cn/problem/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    function cleanPage() {
        const topBar = document.querySelector('div.top-bar');
        if (topBar) topBar.remove();
        const headerLayout = document.querySelector('div.columna-content-wrap.header-layout');
        if (headerLayout) headerLayout.remove();
        const lCards = document.querySelectorAll('div.l-card');
        lCards.forEach(card => {
            if (!card.classList.contains('problem')) {
                card.remove();
            }
        });
    }
    cleanPage();
    const observer = new MutationObserver(() => {
        cleanPage();
    });
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

})();