Greasy Fork

Greasy Fork is available in English.

样式调整粉笔

2025/3/13 09:35:25

当前为 2025-03-25 提交的版本,查看 最新版本

// ==UserScript==
// @name        样式调整粉笔
// @namespace   Violentmonkey Scripts
// @match       https://spa.fenbi.com/ti/exam/solution/1_3e_201smaa*
// @grant       none
// @version     1.0.0.1
// @match        *://www.fenbi.com/*
// @match        *://spa.fenbi.com/*
// @author      lhy
// @description 2025/3/13 09:35:25
// ==/UserScript==

// 通过创建 <style> 标签添加 CSS
const style = document.createElement('style');
style.textContent = `
  @import url('https://unpkg.com/[email protected]/dist/antd.min.css');
`;
document.head.appendChild(style);

// 加载 React 和 ReactDOM
const reactScript = document.createElement('script');
reactScript.src = 'https://unpkg.com/[email protected]/umd/react.production.min.js';
document.head.appendChild(reactScript);

const reactDOMScript = document.createElement('script');
reactDOMScript.src = 'https://unpkg.com/[email protected]/umd/react-dom.production.min.js';
document.head.appendChild(reactDOMScript);

// 加载 Ant Design
const antdScript = document.createElement('script');
antdScript.src = 'https://unpkg.com/[email protected]/dist/antd.min.js';
document.head.appendChild(antdScript);

// 等待所有脚本加载完成
const waitForScripts = () => {
  return new Promise((resolve) => {
    const check = () => {
      if (window.React && window.ReactDOM && window.antd) {
        resolve();
      } else {
        setTimeout(check, 300);
      }
    };
    check();
  });
};

waitForScripts().then(() => {
  const { message, notification } = window.antd;
  // 示例:一段时间后显示错误消息
  setTimeout(() => {
    handle();
    message.success('执行成功!');
    notification.open({
      message: '样式调整完毕!',
      description:
        '删除vip视频区域,调整资料分析布局自上而下全展开,全展开所有解析',
      onClick: () => {
        console.log('Notification Clicked!');
      },
    });
  }, 5000);
  // 页面加载完成 1 分钟后重复执行函数
  setTimeout(() => {
    handle();
    message.success('二次备用执行成功!');
  }, 10 * 1000); // 60 * 1000 毫秒即 1 分钟

});

async function handle() {
  await delVIPGuanggao();
  await openAnswer();
  await delNote();
  await ziliaofenxiDivOpen();
  await delPadding()
  console.log("执行完毕");
}

// 封装删除元素的函数
function removeElements(selector) {
  const elements = document.querySelectorAll(selector);
  elements.forEach((element) => {
    if (element.parentNode) {
      element.parentNode.removeChild(element);
    }
  });
}

// 封装移除样式属性的函数
function removeStyleProperties(selector, properties) {
  const elements = document.querySelectorAll(selector);
  elements.forEach((element) => {
    properties.forEach((property) => {
      element.style.removeProperty(property);
    });
  });
}

// 封装设置样式属性的函数
function setStyleProperties(selector, property, value) {
  const elements = document.querySelectorAll(selector);
  elements.forEach((element) => {
    element.style[property] = value;
  });
}

function delVIPGuanggao() {
  removeElements('.solution-video-container, .solution-title-container');
}

function openAnswer() {
  removeStyleProperties('.result-common-container', ['height']);
}

function delNote() {
  removeElements('[id^="section-note-"]');
}

function ziliaofenxiDivOpen() {
  removeStyleProperties('.resizable-container', ['height']);
  setStyleProperties('.resizable-container', 'flexDirection', 'column');
  removeStyleProperties('.nz-resizable.left', ['width', 'height']);
  removeElements('.questions-anchors');
}

function delPadding(){
   const solutionMainElements = document.querySelectorAll('.solution-main');
        solutionMainElements.forEach((element) => {
            element.style.padding = '0';
            element.style.maxWidth = 'none';
        });
}