NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name 菁优网扣题工具 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 菁优网扣题工具,现在只能扣数学部分的选择题和填空题,代码有点乱,没时间整理 // @author twjx // @match https://www.jyeoo.com/math/report/detail/* // @icon https://img.jyeoo.net/favicon3.ico // @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js // @copyright 2025, twjx (https://openuserjs.org/users/twjx) // @updateURL https://openuserjs.org/meta/twjx/菁优网扣题工具.meta.js // @downloadURL https://openuserjs.org/install/twjx/菁优网扣题工具.user.js // @license MIT // @grant none // ==/UserScript== (function() { 'use strict'; var newdata=[] Array.from(document.querySelector('#detail').children).forEach((e,h)=>{ if(isEven(h)){ newdata.push({name:e.innerText,body:null}) }else{ newdata[(h-1)/2].body=e } }) function isEven(number) { return !(number % 2); } function Multiple_choice_questionsdata(array){ const answerdiv = Array.from(array[0].children[1].children[0].children[0].children) const answer = { type:'', answer:[], true:'', } answerdiv.forEach((e)=>{ Array.from(e.children).forEach((e,h)=>{ if(e.children[0].querySelector('.img')==null){ answer.type = 'text' answer.answer.push(gettext(e.children[0])) }else{ answer.type = 'img' answer.answer.push({ answer:gettext(e.children[0]), img:e.children[0].children[0].src, }) } if(e.children[0].className=='s sh'){ answer.true = h+1 } }) }) const question = { type:'', questiontext:gettext(array[0].children[0]), questionimg:'', } if(array[0].children[0].querySelector('.img')==null){ question.type = 'text' question.questionimg=undefined }else{ question.type = 'img' question.questionimg = array[0].children[0].children[0].src } return { question:question, answer:answer, } } function Fill_in_the_blank_questions(array){ return { question:gettext(array[0].children[0]).replace(array[0].children[0].querySelector('.sanwser').textContent,'____'), answer:gettext(array[0].children[0].querySelector('.sanwser')), } } function mathjye(div){ if(div.querySelector('.msqrt')){//根号 return div.textContent }else if(div.querySelector('.mfrac')){//分式 var div1=div.querySelector('.mfrac') div.children[0].removeChild(div1) var text=div.textContent+'('+div1.querySelector('.fracZi').textContent+')/'+div1.querySelector('.fracMu').textContent div.children[0].appendChild(div1) return text } } function gettext(div){ try{ if(div.querySelector('.MathJye')){ var a=div.querySelector('.MathJye') div.querySelector('.MathJye').innerHTML=mathjye(a) var text=div.textContent Object.assign(div.querySelector('.MathJye').children,a.children) return text }else { return div.textContent } }catch(e){console.log(div)} } var dataaa={ name:document.querySelector('.paper-title').textContent.replaceAll(' ','').replaceAll('\n',''), 'Multiple_choice_questions':[], 'Fill_in_the_blank_questions':[], } window.get=function(){ Array.from(newdata[0].body.children).forEach((e)=>{ dataaa.Multiple_choice_questions.push(Multiple_choice_questionsdata(Array.from(e.children))) }) Array.from(newdata[1].body.children).forEach((e)=>{ dataaa.Fill_in_the_blank_questions.push(Fill_in_the_blank_questions(Array.from(e.children))) }) setTimeout(()=>{window.generateDocx(dataaa)},3000) } window.generateDocx=async function(dataaa) { try { const jsonData = dataaa const docxDataURL = 'data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,UEsDBAoAAAAAAIdO4kAAAAAAAAAAAAAAAAAJAAAAZG9jUHJvcHMvUEsDBBQAAAAIAIdO4kDlKA8MXAEAAHECAAAQAAAAZG9jUHJvcHMvYXBwLnhtbJ2RUW+CMBSF35fsPxDeoQXFOVMwDufTspmI89E05QLNoG3aavTfr4xF2eve7jm3PfnaQ5aXrvXOoA2XIvWjEPseCCZLLurU3xebYO57xlJR0lYKSP0rGH+ZPT6QrZYKtOVgPBchTOo31qoFQoY10FETurVwm0rqjlondY1kVXEGa8lOHQiLYoxnCC4WRAlloG6B/pC4ONv/hpaS9Xzms7gqB5yRAjrVUgvZe4/ThqW0HUE3l2xpDSaLCBoGcpC6NBkmaBhI3lBNmXX/1JsjRd64cDedOQwuSdNaU9X8mCNFCmlpW/AO+tN3QXaMtpA73KyirQGC7kaf/mX2qpDrHv53/9ccsR24bXaKsgHoTjnyyUqpljNqXd/ZYbvzPn46OUZx6MoPYzzByXETvU7ip5c8iGfPeTCdJGWwipI4wEmeTPE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1]; const arrayBuffer = Uint8Array.from(atob(base64Data), c => c.charCodeAt(0)).buffer; // 2. 加载 DOCX 到 JSZip const zip = await JSZip.loadAsync(arrayBuffer); const documentXml = await zip.file('word/document.xml').async('text'); const parser = new DOMParser(); const xmlDoc = parser.parseFromString(documentXml, 'text/xml'); const ns = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'; const body = xmlDoc.getElementsByTagNameNS(ns, 'body')[0]; // 清空原有内容 while (body.firstChild) { body.removeChild(body.firstChild); } // 分页控制参数 let currentLines = 0; const maxLinesPerPage = 35; // 根据实际模板调整(约A4纸30-40行) // 处理选择题 const mcQuestions = jsonData.Multiple_choice_questions; mcQuestions.forEach((q, index) => { const questionLines = 1 + q.answer.answer.length; // 题目+选项行数 // 智能分页判断 if (currentLines + questionLines > maxLinesPerPage) { addPageBreak(body, ns, xmlDoc); currentLines = 0; } // 添加题目 addParagraph(body, `${q.question.questiontext}`, ns, xmlDoc); // 添加选项 q.answer.answer.forEach((opt, optIndex) => { addParagraph(body, /*${String.fromCharCode(65 + optIndex)}.*/`${opt}`, ns, xmlDoc); }); currentLines += questionLines; }); // 处理填空题前分页检查 if (currentLines > 0 && currentLines + 1 > maxLinesPerPage) { addPageBreak(body, ns, xmlDoc); currentLines = 0; } // 处理填空题 const fillQuestions = jsonData.Fill_in_the_blank_questions; fillQuestions.forEach((q, index) => { const questionLines = 1; if (currentLines + questionLines > maxLinesPerPage) { addPageBreak(body, ns, xmlDoc); currentLines = 0; } addParagraph(body, `${index + 11}. ${q.question} `, ns, xmlDoc); currentLines += questionLines; }); // const serializer = new XMLSerializer(); const modifiedXml = serializer.serializeToString(xmlDoc); // 4. 更新 ZIP 内容 zip.file('word/document.xml', modifiedXml); // 5. 生成新 DOCX 并下载 const newBlob = await zip.generateAsync({ type: 'blob' }); const url = URL.createObjectURL(newBlob); const link = document.createElement('a'); link.href = url; link.download = jsonData.name+'.docx'; link.click(); URL.revokeObjectURL(url); } catch (error) { console.error('生成文档失败:', error); } } // 添加段落工具函数 function addParagraph(parent, text, ns, xmlDoc) { const p = xmlDoc.createElementNS(ns, 'w:p'); const r = xmlDoc.createElementNS(ns, 'w:r'); const t = xmlDoc.createElementNS(ns, 'w:t'); t.textContent = text; r.appendChild(t); p.appendChild(r); parent.appendChild(p); } // 添加分页符工具函数 function addPageBreak(parent, ns, xmlDoc) { const p = xmlDoc.createElementNS(ns, 'w:p'); const r = xmlDoc.createElementNS(ns, 'w:r'); const br = xmlDoc.createElementNS(ns, 'w:br'); br.setAttributeNS(ns, 'w:type', 'page'); r.appendChild(br); p.appendChild(r); parent.appendChild(p); // 添加空白段落 addParagraph(parent, '', ns, xmlDoc); } })();