您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
优化考试宝答题界面UI,增加按键绑定
当前为
// ==UserScript== // @name 考试宝答题界面优化 // @namespace https://github.com/AliubYiero/TemperScripts // @version 1.1.11 // @description 优化考试宝答题界面UI,增加按键绑定 // @author Yiero // @match https://www.zaixiankaoshi.com/online/* // @match https://www.zaixiankaoshi.com/mnks/* // @icon https://www.zaixiankaoshi.com/favicon.ico // @license GPL // @grant GM_addStyle // ==/UserScript== "use strict"; class FunctionChainCall { callChain; constructor() { this.callChain = []; } set(fn, params = []) { this.callChain.push([fn, params]); } setList(array) { array.forEach((fn) => { if (!Array.isArray(fn)) { this.set(fn); return; } this.set(fn[0], fn[1]); }); } async call() { let returnString; while (this.callChain[0]) { if (returnString === 'stop') { return; } else if (returnString === 'skip') { this.callChain.shift(); continue; } const fn = this.callChain[0]; returnString = await fn[0].apply(null, fn[1]); this.callChain.shift(); } } } const functionChainCall = new FunctionChainCall(); class SubmitAnswerStatusChange { static isSubmit = false; static submit() { this.isSubmit = true; } static close() { this.isSubmit = false; } static fresh() { this.close(); } } class OptionObserver extends MutationObserver { constructor(Node, callback) { super(callback); super.observe(Node, { childList: true }); } } function urlJudge(urlHeader) { if (typeof urlHeader === 'string') { urlHeader = new RegExp(urlHeader); } return !!document.URL.match(urlHeader); } function removeExtraElement() { GM_addStyle(` /* 居中主容器 */ .app-main { display: flex; justify-content: center; align-items: center; padding: 0; } /* 优化主容器UI */ .middle-container { padding: 10px ${16 + 19 + 16 + 10}px; border-radius: 10px; } /* 隐藏多余元素 */ .vip-quanyi, .new-footer, .header, .answer-box-detail, .answer-box-detail, .vip-tips, .right-float-window { display: none; } `); } function isAnswerUI() { const localURL = document.URL.split('/'); console.log(localURL[localURL.length - 2]); if (['online', 'simulation'].indexOf(localURL[localURL.length - 2]) === -1) { console.info('非答题界面,已退出'); return 'stop'; } } function setLargeFont() { const LargeFontBtn = document.querySelector('div.clearfix.font-set span:nth-of-type(3)'); LargeFontBtn.click(); } function freshOption() { new OptionObserver(document.querySelector('.qusetion-box'), e => { console.info('Change question'); SubmitAnswerStatusChange.fresh(); }); } let optionList; function getOptions() { optionList = document.querySelectorAll('.options-w > .option'); try { new OptionObserver(document.querySelector('.top-hd'), e => { new OptionObserver(document.querySelector('.options-w'), e => { console.info('Fresh Options: '); optionList = document.querySelectorAll('.options-w > .option'); }); }); } catch (e) { location.reload(); } } function bindKeyboardEvent() { try { window.addEventListener('keydown', e => { const chosenOptionNumber = parseInt(e.key) - 1; if (chosenOptionNumber >= 0 && chosenOptionNumber < optionList.length) { console.info('Enter Option Chosen'); optionList[chosenOptionNumber]?.click(); return; } const submitAnswer = document.querySelectorAll('.topic [style="clear: both;"]'); if (submitAnswer.length === 2 && !SubmitAnswerStatusChange.isSubmit && ['Enter'].indexOf(e.key) !== -1) { SubmitAnswerStatusChange.submit(); submitAnswer[0].querySelector('button').click(); return; } SubmitAnswerStatusChange.fresh(); if (['ArrowLeft'].indexOf(e.key) !== -1 || ['NumpadSubtract'].indexOf(e.code) !== -1) { document.querySelector('.next-preve > button:nth-of-type(1)').click(); } else if (['Enter', '+', 'ArrowRight'].indexOf(e.key) !== -1) { const rightBtn = document.querySelector('.next-preve > button:nth-of-type(2)'); if (rightBtn.disabled && urlJudge('https://www.zaixiankaoshi.com/mnks/simulation/')) { let submitBtn = document.querySelector('.submit-btn'); submitBtn.click(); return; } rightBtn.click(); } }); } catch (e) { console.error(e); const isReloadPage = confirm(` KeyBoard binding got an error, should fresh this page to reload? 按键绑定失败。是否需要重新刷新页面重新载入脚本? `); if (isReloadPage) { location.reload(); } } } window.onload = () => { setTimeout(() => { const fnList = [removeExtraElement, isAnswerUI, setLargeFont, freshOption, getOptions, bindKeyboardEvent]; functionChainCall.setList(fnList); functionChainCall.call(); }, 1000); };