粉笔网刷题宝

粉笔网删除不必要dom

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

// ==UserScript==
// @name         粉笔网刷题宝
// @namespace    http://tampermonkey.net/
// @version      0.0.29
// @description  粉笔网删除不必要dom
// @author       You
// @match        https://*.fenbi.com/*
// @grant        none
// @license GPLv3
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';
    const $ = window.$;
    let did = {};
    function isElementFixed(element) {
        const position = $(element).css('position');
        return position === 'fixed';
    }

    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%' });
            $('.fixedActions.bg-color-gray-bold').css({ right: 0 })

            did.xingce = false;
            shenlun();
        }

        // 窄屏下样式调整
        if($('.fb-question-material')?.length && !did.zhaiping) {
            did.zhaiping = true;
            // 调整行测状态下样式
            $('.fb-question-material').css({ margin: 12 });
            $('.material-content').css({ padding: 0 });
            $('.ques-options-dry').css({ padding: 0 });
            $('.options.font-color-gray-mid').css({ display: 'flex' });
        }

        // 我的答案
        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) {
            $(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');
                    }
                });
            })

            if(!did.addClearBtn) {
                did.addClearBtn = true;
                var newButton = $('<button>清屏</button>');
                var newInput = $('<input type="number" value="80">');

                // 在 .fixedActions.bg-color-gray-bold 的第一个子元素前插入新的 button
                $('.fixedActions.bg-color-gray-bold').children().first().before(newButton).before(newInput);

                // 为新的 button 添加点击事件处理器
                newButton.on('click', function() {
                    // 提取 .exam-content DOM 元素
                    var examContent = $('main.exam-content');
                    var inputValue = newInput.val();

                    // 清空 body 的内容
                    $('body').empty();

                    // 将 .exam-content DOM 元素插入到 body 下
                    $('body').append(examContent);
                    $('body').append(`<style>
                    .fixedActions.bg-color-gray-bold,.fb-collpase-bottom, app-side-tool,.fb-question > div:last-child[_ngcontent-fenbi-web-exams-c68],div[_ngcontent-fenbi-web-exams-c69] > div[_ngcontent-fenbi-web-exams-c69],.content.font-color-gray-mid>p.ques-type {
                    display: none;
                    }

                    .fb-question-options.fenbi-ng-utils > div[_ngcontent-fenbi-web-exams-c40] {
padding: 16px 0 0 0;
margin-bottom: ${inputValue}px;
                    }

                    .options.font-color-gray-mid {
display: flex;
justify-content: space-between;
    flex-wrap: wrap;
                    }

                    .options.font-color-gray-mid > li {
margin: 0 !important;
                    }
                    [_nghost-fenbi-web-exams-c40] p {
                    font-weight: normal;
                    }
                    </style>`);
                    window.scrollTo(0, document.body.scrollHeight);
                });
            }
        }
    });

    // 模考大赛
    cbs.push((node)=> {
        const mokaoLeft = $('.exam-post-nav');
        if(mokaoLeft?.length && !did.mokao) {
            did.mokao = true;
            $(mokaoLeft).css({ left: 0, top: 0 });
            const detailContent = $('.solution-detail.clear-float');
            $(detailContent).css({ width: '100%' });
            $(detailContent).find('.options.ng-star-inserted').css({ display: 'flex', 'justify-content': 'space-between', 'flex-wrap': 'wrap' });
            $(detailContent).find('.exam-main-content.ng-tns-c3-0.ng-star-inserted').css({ width: 'calc(100% - 302px)' })
            $('.practice-header').hide();
        }
    })

    const dealWidth = () => {
        // 创建一个CSS规则字符串
        const cssRules = `
  @media (max-width: 1000px) {
    .exam-content {
      width: calc(100% - 45px) !important;
    }
    #app-practice {
      min-width: 100% !important;
    }
    .tools-container {
left: 0;
    }
    .fb-collpase-bottom {
left: 0;
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或关注我们的公众号极客氢云获取最新地址