// ==UserScript== // @name 超星学习通超能小助手 // @namespace RouterCheng // @version 1.0.1 // @description 查看考试成绩,新版作业提取为Word // @author Router_Cheng // @connect cdn.jsdelivr.net // @connect mooc.xxcheng.top // @resource buildcss https://gitee.com/code-139site/speed-pages/raw/master/work_helper/Build.css // @resource getInfo https://mooc.xxcheng.top/export/setting.json // @match *://*.chaoxing.com/* // @match *://*.edu.cn/* // @run-at document-end // @grant unsafeWindow // @grant GM_xmlhttpRequest // @grant GM_setClipboard // @grant GM_addStyle // @grant GM_getResourceText // @license MIT // @downloadURL none // ==/UserScript== /** * since 2020/12/08 */ //用户配置 let config = { }; //系统配置,不要改这个,改上面的 window.helper = { url: window.location.pathname, setting:JSON.parse(GM_getResourceText('getInfo')), version:"1.0.1", pagesTools: { "/mooc2/work/view": { showTiMiList: true }, "/exam/test/reVersionPaperMarkContentNew":{ showTiMiList: true }, "/exam-stastics/stu-index":{ showScoreList:true } }, allowQuestionType: [ "单选题", "多选题", "填空题", "判断题", "简答题"//, // "名词解释", // "论述题", // "计算题", // "分录题", // "资料题", // "连线题", // "排序题", // "完型填空", // "阅读理解", // "程序题", // "口语题", // "听力题", // "共用选项题", // "其它" ] }; window.superStarHelperState = true; let buildcss=GM_getResourceText('buildcss'); window.onload = function() { if ( !helper["setting"]["isAllowUsed"] || helper["pagesTools"][helper.url] == undefined) { //console.log("helper is not working"); return; } //展示题目和答案 if (helper["pagesTools"][helper.url]["showTiMiList"]) { let currentPageAllTiMuListCode = getTiMuList(); let currentPageAllTiMuList=[]; for( let ti of currentPageAllTiMuListCode ){ switch( ti["type"] ){ case "单选题": currentPageAllTiMuList.push(parseNewQuestionChoice(ti)); break; case "多选题": currentPageAllTiMuList.push(parseNewQuestionChoice(ti)); break; case "填空题": currentPageAllTiMuList.push(parseNewQuestionGapFilling(ti)); break; case "判断题": currentPageAllTiMuList.push(parseNewQuestionYesNo(ti)); break; case "简答题": currentPageAllTiMuList.push(parseNewQuestionCommon(ti)); break; } } console.log(currentPageAllTiMuList); helper["currentPageAllTiMuList"]=currentPageAllTiMuList; let exportTiMu=[]; for( let i of currentPageAllTiMuList){ exportTiMu.push(i["export"]); } helper["exportTiMu"]=exportTiMu; if( currentPageAllTiMuList.length>0 ){ let tbody=createElementUI(); createButton(); for( let e of helper["currentPageAllTiMuList"] ){ appendTiMu(tbody,e); } document.querySelector("#download_word").style.display="block"; document.querySelector("#download_word").onclick=()=>{ loadDownWord(helper["exportTiMu"]); } document.querySelector("#helperNoticeBoard").innerHTML=helper["setting"]["helperNoticeBoard"]; } } if( helper["pagesTools"][helper.url]["showScoreList"] ){ showStuScore(); } }; /** * @param {question List Code} code * 把所有题目获取到一个数组,包括一个题型 */ function getTiMuList() { let tiMuList = null; switch (helper["url"]) { case "/mooc2/work/view": //新版学习通作业 tiMuList = findNewItem(); break; case "/exam/test/reVersionPaperMarkContentNew": tiMuList = findNewItem(); break; } return tiMuList; } /** * @param {Object} code * 新页面作业 */ function findNewItem() { let all = document.querySelectorAll(".mark_item"); let tiMuList = []; let type = null; for (let childAll of all) { for (let questionLi of childAll.children) { if (questionLi.tagName == "H2") { type = questionLi.innerText.match(/\.([^(]*)/)[1].trim(); if (!helper["allowQuestionType"].includes(type)) { break; } } else { let tmp = questionLi; tmp["type"] = type; tiMuList.push(tmp); } } } return tiMuList; } /** * 开始解析题目啦 */ //初始化新题 function initNewQuestion(code){ code.querySelector("h3").querySelector(".colorShallow").remove(); return { element:code, export:{}, type:code["type"], titleHTML:code.querySelector(".mark_name").innerHTML.match(/\d+\.(.*)/)[1].trim() } } //新选择题的解析 function parseNewQuestionChoice(code){ let ti=initNewQuestion(code); ti["answerHTMLAll"]=code.querySelector(".mark_letter"); ti["key"]=code.querySelector(".mark_answer").querySelector(".mark_key").innerText.match(/正确答案:\s?([A-Z]*)/); ti["key"]=ti["key"]?ti["key"][1]:code.querySelector(".mark_answer").querySelector(".mark_key").innerText.match(/我的答案:\s?([A-Z]*)/)[1]; ti["keyArr"]=ti["key"].split(""); ti["answerHTML"]=[]; ti["export"]["answer"]=[]; for( let ans of ti["answerHTMLAll"].children ){ let option=ans.innerHTML.match(/[^\.]*/)[0].trim() let pre=ans.innerHTML.match(/[^\.]*\.(.*)/)[1].trim(); ti["answerHTML"].push(pre); ti["export"]["answer"].push({ name:option, content:pre, isanswer:ti["keyArr"].includes(option) }); } ti["export"]["content"]=ti["titleHTML"]; ti["export"]["name"]=ti["keyArr"].length==1?"单选题":"多选题"; ti["export"]["type"]=ti["keyArr"].length==1?0:1; ti["export"]["id"]=0; return ti; } //新填空题的解析 function parseNewQuestionGapFilling(code){ let ti=initNewQuestion(code);ti["answerHTMLAll"]=code.querySelector(".mark_answer").children[0]; ti["answerCountElements"]=ti["answerHTMLAll"].querySelectorAll("dt"); if( ti["answerCountElements"].length==2 ){ let allTrueAnswer=ti["answerHTMLAll"].querySelectorAll("dl")[1].querySelectorAll("dd"); ti["keyArr"]=[]; ti["export"]["answer"]=[]; for( let answerItem of allTrueAnswer){ let key=answerItem.innerHTML.match(/\([\d]+\)(.*)/)[1].trim(); ti["keyArr"].push(key); ti["export"]["answer"].push({ content:key, name:ti["export"]["answer"].length+1 }); } }{ //没有提供正确答案的到时候在搞 } ti["export"]["content"]=ti["titleHTML"]; ti["export"]["analysis"]="无"; ti["export"]["name"]="填空题"; ti["export"]["type"]=2; ti["export"]["id"]=0; return ti; } //新判断的解析 function parseNewQuestionYesNo(code){ let ti=initNewQuestion(code); ti["answerHTMLAll"]=code.querySelector(".mark_answer").children[0]; ti["answerCountElements"]=ti["answerHTMLAll"].querySelectorAll("span"); ti["key"]=ti["answerCountElements"][(ti["answerCountElements"].length==2?1:0)].innerHTML.match(/对/)?true:false; ti["keyArr"]=[]; ti["export"]["answer"]=[]; ti["keyArr"].push(ti["key"]?"√":"×"); ti["export"]["answer"].push({ answer:ti["key"] }); ti["export"]["content"]=ti["titleHTML"]; ti["export"]["analysis"]="无"; ti["export"]["name"]="判断题"; ti["export"]["type"]=3; ti["export"]["id"]=0; return ti; } function parseNewQuestionCommon(code){ let ti=initNewQuestion(code); ti["answerHTMLAll"]=code.querySelector(".mark_answer").children[0]; ti["answerCountElements"]=ti["answerHTMLAll"].querySelectorAll("dt"); if( ti["answerCountElements"].length==2 ){ let allTrueAnswer=ti["answerHTMLAll"].querySelectorAll("dl")[1].querySelectorAll("dd"); ti["keyArr"]=[]; ti["export"]["answer"]=[]; ti["key"]=allTrueAnswer[0].innerHTML; ti["keyArr"].push(ti["key"]); ti["export"]["answer"].push({ answer:ti["key"] }); }{ //没有提供正确答案的到时候在搞 } ti["export"]["content"]=ti["titleHTML"]; ti["export"]["analysis"]="无"; ti["export"]["name"]="简答题"; ti["export"]["type"]=4; ti["export"]["id"]=0; return ti; } function createElementUI(){ let showDiv=document.createElement("div"); showDiv.innerHTML='
题号 | '+ '题目 | '+ '答案 | '+ '题型 | '+ '
---|---|---|---|
'+ ' | '+ '|||
'+ ' | '+ ''+ ' '+ ' | '+ ' '+ ' '+ '