粉笔网刷题宝

粉笔网删除不必要dom

目前为 2023-11-02 提交的版本。查看 最新版本

// ==UserScript==
// @name         粉笔网刷题宝
// @namespace    http://tampermonkey.net/
// @version      0.0.16
// @description  粉笔网删除不必要dom
// @author       You
// @match        https://.*fenbi.com/*
// @include      https://www.fenbi.com/spa/tiku/exam/practice/*
// @include      https://www.fenbi.com/spa/tiku/report/exam/solution/*
// @include      https://spa.fenbi.com/*
// @grant        none
// @license GPLv3
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';
    const $ = window.$;
    let did = {};

    function shenlun(){
        // =申论=
        // 左侧题目
        const leftSubject = $('.zhenti-body-left.zhenti-body-part.bg-color-gray-light5');
        leftSubject.find('.materials-container').css({ width: '100%', padding: 12 });
        leftSubject.find('.material-content.ng-tns-c41-0').css({ width: '100%' });
        leftSubject.find('.material-content.ng-tns-c41-0').find('#material').css({ width: '100%' });

        // 右侧答案
        const rightAnser = $('.zhenti-body-right.zhenti-body-part');
        rightAnser.css({ flex: 'none' });
        rightAnser.find('.questions-container').css({ 'padding-left': '12px' });
    }


    const cbs = [];

    // customer operations
    // 处理评论的头像
    cbs.push((node) => {
        // 行测题目
        const xingCeTiMu = $(node).find("main.exam-content");
        if (xingCeTiMu?.length && !did?.xingce) {
            did.xingce = true;
            const css = { margin: 0 };
            // =行测=
            $('main.exam-content').css(css);
            $('.simple-nav-header.bg-color-gray-bold').hide();
            // 答案页选项横向展示
            const optionsCls = '.options.choice-options.font-color-gray-mid.ng-star-inserted';
            $(optionsCls).css({ display: 'flex' });

            $('.nav-coll-divider').hide();
            $('.solu-list.border-gray-light4').css({ 'margin-top': 0 });
            $('.solu-answer-text.clear-float.ng-star-inserted').hide();
            $('.bg-color-gray-light2.border-gray-light3.font-color-gray-mid.expend-btn').hide();
            // 视频隐藏
            $('.solu-list-item.video-item').css({ 'margin-bottom': 0 });
            $('.solu-list-item.video-item fb-ng-solution-detail-item').hide();
            // 答题卡移动到右下角
            // $('.fb-collpase-bottom').css({ width: 'calc(100% - 1024px)', right: 0 });
            // 因为有js动态插入的style,所以这里使用style标签
            $('<style>.fb-collpase-bottom { width: calc(100% - 1024px); right: 0; }</style>').appendTo('head');
            $('.fb-collpase-bottom.bg-color-gray-mid').css({ margin: 0, width: '100%' });

            shenlun();
        }

        // 我的答案
        const collections = $('.solution-item.bg-color-gray-bold');
        if(collections?.length && !did.collectionDid) {
            collections.each(function(){
                // 答案区块
                const solution = $(this).find('.solu-list.border-gray-light4');
                $(solution).css({ padding: 8 })
                // 收起和折叠答案
                $(solution).find('fb-ng-solution-detail-answer').hide();
                // 视频
                // $(solution).find('.video-item').hide();
                // console.log($(solution).find('.video-item fb-ng-solution-detail-item'))
            })
            did.collectionDid = true;
        }
        // 收藏按钮
        const collectionBtn = $('.solution-item.bg-color-gray-bold>app-fb-solution>fb-ng-solution > div[_ngcontent-fenbi-web-exams-c75] > div[_ngcontent-fenbi-web-exams-c75]');
        if(collectionBtn?.length && !did.collectionBtnDid) {
            collectionBtn.each(function() {
                $(this).css({ position: 'absolute', right: 0 })
                console.log(this)
            })
            did.collectionBtnDid = true;
        }
    });
    // 处理草稿纸,监听esc退出草稿纸模式
    cbs.push((node)=> {
        const caogao = $('.draft-icon');
        if(caogao?.length) {
            console.log('草稿纸')
            $(caogao).on('click', function () {
                // 点击事件处理
                console.log('draft-icon 被点击');
                // 监听ESC按钮按下事件
                $(document).on('keydown', function (event) {
                    if (event.key === 'Escape' || event.keyCode === 27) {
                        // 如果按下了ESC键,则触发.tool-item.exit元素的点击事件
                        $('.tool-item.exit').trigger('click');
                        // 移除键盘事件监听
                        $(document).off('keydown');
                    }
                });
            })
        }
    });

    const dealWidth = () => {
        // 创建一个CSS规则字符串
        const cssRules = `
  @media (max-width: 1000px) {
    .exam-content {
      width: calc(100% - 45px) !important;
    }
    #app-practice {
      min-width: 100% !important;
    }
  }
`;

        // 创建一个新的<style>标签,并将CSS规则字符串添加到其中
        const styleTag = document.createElement('style');
        styleTag.innerHTML = cssRules;

        // 将新的<style>标签插入到HTML文档的<head>标签中
        document.head.appendChild(styleTag);
    }

    dealWidth();

    // Observe dom
    function observeDom(container) {
        function handleMutation(mutation) {
            if (mutation.type === "childList") {
                mutation.addedNodes.forEach((node) => {
                    cbs.forEach((cb) => cb(node));
                });
            }
        }

        const observer = new MutationObserver((mutations) => {
            mutations.forEach(handleMutation);
        });

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

    observeDom(document.body);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址