您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
粉笔网优化布局,清屏快速生成pdf
当前为
// ==UserScript== // @name 粉笔网刷题宝 // @namespace http://tampermonkey.net/ // @version 0.0.50 // @author binyellow // @icon https://nodestatic.fbstatic.cn/weblts_spa_online/page/assets/fenbi32.ico // @defaulticon 粉笔网优化布局,清屏快速生成pdf // @match *.fenbi.com/* // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.js // @grant GM_addStyle // @grant GM_getValue // @grant GM_setValue // @grant GM_xmlhttpRequest // @description 粉笔网优化布局,清屏快速生成pdf // ==/UserScript== (function ($) { 'use strict'; const processCls = `__binyellow__processed__`; function processElements(selector, callback) { function checkForMatchingNode(nodes) { for (const node of nodes) { if (node.matches && node.matches(selector)) { callback(node); return true; } if (node.querySelectorAll) { const matchingDescendant = node.querySelector(selector); if (matchingDescendant) { callback($(matchingDescendant)); return true; } } } return false; } const observer = new MutationObserver((mutations) => { for (const mutation of mutations) { if (mutation.type === "childList") { if (checkForMatchingNode(mutation.addedNodes)) { observer.disconnect(); break; } } } }); observer.observe(document.body, { childList: true, subtree: true }); } const mokao = () => { processElements(".exam-post-nav", (node) => { $(node).css({ left: 0, top: 0 }); const detailContent = $(".solution-detail.clear-float"); $(detailContent).css({ width: "100%" }); const optionsUl = $(detailContent).find(".options.ng-star-inserted"); $(optionsUl).css({ display: "flex", "justify-content": "space-between", "flex-wrap": "wrap" }); optionsUl.children().css("margin", "0"); $(detailContent).find(".exam-main-content.ng-tns-c3-0.ng-star-inserted").css({ width: "calc(100% - 302px)" }); $(".practice-header").hide(); $(detailContent).find(".solu-detail.ng-star-inserted").css({ margin: 0, padding: 0 }); $(detailContent).find(".nav-coll-divider.solu-divider").css({ margin: "6px 0" }); $(detailContent).find(".question-content > p:nth-child(2) > img").each(function() { var img = $(this); var width = img.width() || 0; var height = img.height() || 0; var newWidth = width * 0.6; var newHeight = height * 0.6; img.width(newWidth); img.height(newHeight); }); }); }; const caogao = () => { processElements(".draft-icon", () => { $(".draft-icon").on("click", function() { console.log("draft-icon 被点击"); $(document).on("keydown", function(event) { if (event.key === "Escape" || event.keyCode === 27) { $(".tool-item.exit").trigger("click"); $(document).off("keydown"); } }); }); }); }; var _GM_addStyle = /* @__PURE__ */ (() => typeof GM_addStyle != "undefined" ? GM_addStyle : void 0)(); var _GM_getValue = /* @__PURE__ */ (() => typeof GM_getValue != "undefined" ? GM_getValue : void 0)(); var _GM_setValue = /* @__PURE__ */ (() => typeof GM_setValue != "undefined" ? GM_setValue : void 0)(); var _GM_xmlhttpRequest = /* @__PURE__ */ (() => typeof GM_xmlhttpRequest != "undefined" ? GM_xmlhttpRequest : void 0)(); const xhrInterceptor = (rules, cb) => { var originalXHR = window.XMLHttpRequest; window.XMLHttpRequest = function() { var xhr = new originalXHR(); var originalOpen = xhr.open; xhr.open = function() { const method = arguments[0]; const url = arguments[1]; const matchedRule = rules.find((rule) => { if (typeof rule.url === "string") { return rule.url === url && (!rule.method || rule.method === method); } else if (rule.url instanceof RegExp) { return rule.url.test(url) && (!rule.method || rule.method === method); } else { return false; } }); if (matchedRule) { console.log("XHR request: " + method + " " + url); this._url = url; this._method = method; } originalOpen.apply(this, arguments); }; var originalSend = xhr.send; xhr.send = function() { const body = arguments[0]; if (this._url) { console.log(`send===>`, arguments, this._headers); this._body = body; console.log("XHR request body: " + body, this._url, this._headers); cb({ url: this._url, method: this._method, body: this._body, headers: this._headers }); } originalSend.apply(this, arguments); }; const originalSetRequestHeader = xhr.setRequestHeader; xhr.setRequestHeader = function(header, value) { if (this._url) { if (!this._headers) { this._headers = {}; } this._headers[header] = value; } originalSetRequestHeader.apply(this, arguments); }; return xhr; }; }; const kuaiSuShuaTiKey = "__kuaiSuShuaTiKey__"; const jiankong = () => { jiankongKuaiSuLianXi(); }; const jiankongKuaiSuLianXi = () => { const rules = [ { url: "https://tiku.fenbi.com/api/xingce/exercises?app=web&kav=100&av=100&hav=100&version=3.0.0.0", method: "POST" } ]; const callback = (config) => { _GM_setValue(kuaiSuShuaTiKey, config); }; xhrInterceptor(rules, callback); }; const request = (props) => { const { body, ...rest } = props; return new Promise((resolve) => { _GM_xmlhttpRequest({ onload: (data) => { resolve(data); }, method: "POST", data: typeof body === "object" && !(body instanceof FormData) ? JSON.stringify(body) : body, ...rest }); }); }; const lianxiUrl = `https://www.fenbi.com/spa/tiku/exam/practice/xingce/xingce`; 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 kuaisu = () => { processElements("main.exam-content", () => { const css = ` .solu-list-item.video-item fb-ng-solution-detail-item, .bg-color-gray-light2.border-gray-light3.font-color-gray-mid.expend-btn, .simple-nav-header.bg-color-gray-bold, .nav-coll-divider, .solu-answer-text.clear-float { display: none } main.exam-content { margin: 0 !important } .options.choice-options.font-color-gray-mid { display: flex } .solu-list.border-gray-light4 { margin-top: 0 } .solu-list-item.video-item { margin-bottom: 0 } .fb-collpase-bottom { width: calc(100% - 1024px); right: 0; } .fb-collpase-bottom.bg-color-gray-mid { margin: 0, width: 100% } .fixedActions.bg-color-gray-bold { right: 0 } `; _GM_addStyle(css); shenlun(); }); processElements(".fb-question-material", () => { $(".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", "flex-flow": "wrap" }); }); processElements(".solution-item.bg-color-gray-bold", (node) => { const solution = $(node).find(".solu-list.border-gray-light4"); $(solution).css({ padding: 8 }); $(solution).find("fb-ng-solution-detail-answer").hide(); }); processElements( ".solution-item.bg-color-gray-bold>app-fb-solution>fb-ng-solution > div[_ngcontent-fenbi-web-exams-c75] > div[_ngcontent-fenbi-web-exams-c75]", (node) => { node.css({ position: "absolute", right: 0 }); } ); processElements(".options.font-color-gray-mid", (node) => { node.css({ display: "flex", "flex-flow": "wrap", "justify-content": "space-between" }); }); processElements("app-report-header-test .exam-report", () => { $(".fixedActions.bg-color-gray-bold").removeClass(processCls); processElements(".fixedActions.bg-color-gray-bold", () => { var newButton = $("<button>重刷</button>"); $(".fixedActions.bg-color-gray-bold").children().first().before(newButton); newButton.on("click", async function() { const requestConfig = await _GM_getValue(kuaiSuShuaTiKey, null); const data = await request(requestConfig); const { id } = JSON.parse(data == null ? void 0 : data.response); location.href = `${lianxiUrl}/${id}/2`; }); }); }); }; const dealWidth = () => { 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; } } @media (min-width: 1700px) { main.exam-content { width: 1600px !important; } aside.fb-collpase-bottom { width: calc(100% - 1600px) !important; } } .collapse-content { } .collapse-title { cursor: pointer; text-decoration: underline; color: blue; } .extra-dom { position: fixed; background-color: #fff; display: flex; flex-direction: column; gap: 6px; padding: 4px; box-sizing: content-box; } .extra-dom input[type=number] { width: 100%; } `; const styleTag = document.createElement("style"); styleTag.innerHTML = cssRules; document.head.appendChild(styleTag); }; function genQuestionTypes() { const options = []; $(".chapter-control-item").each(function() { const label = $(this).find(".font-color-gray-blod").text().slice(0, 2); const items = $(this).children("div").children().length; const rangeStart = options.length > 0 ? options[options.length - 1].range[1] + 1 : 1; const rangeEnd = rangeStart + items - 1; options.push({ label, range: [rangeStart, rangeEnd] }); }); return options; } const isExam = () => { const { pathname } = location; return pathname.slice(pathname.lastIndexOf("/") + 1) === "3"; }; const fixedActions = () => { let options = []; processElements(".chapter-control-item > div:nth-child(2) > fb-ng-ans-button", () => { options = genQuestionTypes(); var newButton = $("<button>清屏</button>"); const marginLabel = '<label for="ti-jian-ju">题间距</label>'; var newInput = $('<input id="ti-jian-ju" type="number" value="180">'); const fontLabel = '<label for="zi-ti">字体</label>'; const fontInput = $('<input id="zi-ti" type="number" value="20">'); const $settingContainer = $(`<div class="collapse"> <a class="collapse-title">设置></a> <div class="collapse-content"> </div> </div>`); $settingContainer.find(".collapse-content").append(marginLabel, newInput, fontLabel, fontInput); const $checkboxContainer = $(`<div class="collapse"> <a class="collapse-title">题型></a> <div class="collapse-content"> </div> </div>`); options.forEach((option, index) => { const isChecked = option.label !== "常识"; const $checkbox = $(`<input type="checkbox" id="option-${index}" ${isChecked ? "checked" : ""} />`); const $label = $(`<label for="option-${index}">${option.label}</label>`); $checkboxContainer.find(".collapse-content").append($checkbox, $label); }); if (isExam()) { $(".fixedActions.bg-color-gray-bold").children().first().before($checkboxContainer); } const fixedActions2 = $(".fixedActions.bg-color-gray-bold"); const width = fixedActions2.outerWidth() || 0; const extraDom = $("<div>", { class: "extra-dom" }); extraDom.css({ right: width + 2, top: "10vh", width: width + 6 }); extraDom.append(newButton, $settingContainer, $checkboxContainer); $("body").append(extraDom); $(".collapse-title").on("click", function() { $(this).next(".collapse-content").slideToggle(); }); newButton.on("click", async function() { if (isExam()) { $(".exam-detail.bg-color-gray-bold > div").hide(); options.forEach((option, index) => { const $checkbox = $(`#option-${index}`); if ($checkbox.prop("checked")) { const [start, end] = option.range; for (let i = start - 1; i < end; i++) { $(".exam-detail.bg-color-gray-bold > div").eq(i).show(); } } }); } await scrollToNextImage(); var examContent = $("main.exam-content"); var inputValue = newInput.val(); var fontValue = fontInput.val(); $("body").empty(); $("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],div.ques-options-dry { 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, [_nghost-fenbi-web-exams-c40] .options-material { font-weight: normal; font-size: ${fontValue}px; } main.exam-content { margin-right: 35px !important; } .material-nav.bg-color-gray-light { display: none; } </style>`); $(".nav-coll-divider").hide(); $(".fb-question>div:last-child > button").hide(); }); }); }; function isImageLoaded(img) { if (!img.complete) { return false; } if (typeof img.naturalWidth !== "undefined" && img.naturalWidth === 0) { return false; } return true; } function delay(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); } async function scrollToNextImage() { var _a, _b; const images = $("#app-practice img").toArray().sort((a, b) => { var _a2, _b2; const aTop = ((_a2 = $(a).offset()) == null ? void 0 : _a2.top) ?? 0; const bTop = ((_b2 = $(b).offset()) == null ? void 0 : _b2.top) ?? 0; return aTop - bTop; }); const filteredImages = images.filter((image, index) => { var _a2, _b2; if (index > 0) { const prevImage = images[index - 1]; return (((_a2 = $(image).offset()) == null ? void 0 : _a2.top) ?? 0) !== (((_b2 = $(prevImage).offset()) == null ? void 0 : _b2.top) ?? 0); } return true; }); const scrollContainer = $("#fenbi-web-exams"); for (const image of filteredImages) { if (!isImageLoaded(image)) { await new Promise((resolve) => { $(image).on("load", function() { resolve(); }); }); } const imagePositionInContainer = (((_a = $(image).offset()) == null ? void 0 : _a.top) ?? 0) - (((_b = scrollContainer.offset()) == null ? void 0 : _b.top) ?? 0) + (scrollContainer.scrollTop() ?? 0); await new Promise((resolve) => { scrollContainer.animate( { scrollTop: imagePositionInContainer }, 50, function() { resolve(); } ); }); await delay(50); } } kuaisu(); caogao(); mokao(); fixedActions(); const initCbs = []; initCbs.push(dealWidth); initCbs.forEach((cb) => cb()); jiankong(); })($);