// ==UserScript== // @name 遇见八三的心动瞬间 // @namespace // @version 1.3.10.20240102 // @description 学企来砍一刀 // @author 我纯f5捏 // @match https://www.cscec83.cn/user/login* // @match http://120.27.194.253/* // @match https://learn.cscec83.cn/* // @match *://*.wjx.cn/* // @match *://*.wjx.top/* // @exclude https://www.cscec83.cn/dashboard/analysis* // @compatible edge // @license // @icon https://s11.ax1x.com/2023/12/30/piOtPX9.jpg // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @require https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js // @require https://update.greasyfork.icu/scripts/447483/1071404/Boxjs.js // @require https://update.greasyfork.icu/scripts/482886/1300084/ZJEngineerBank.js // @require https://update.greasyfork.icu/scripts/482872/1299971/%E4%B8%AD%E5%BB%BA%E5%AD%A6%E4%BC%81%E6%9D%A5%E5%85%A8%E9%A2%98%E5%BA%93part1.js // @require https://update.greasyfork.icu/scripts/482873/1299972/%E4%B8%AD%E5%BB%BA%E5%AD%A6%E4%BC%81%E6%9D%A5%E5%85%A8%E9%A2%98%E5%BA%93part2.js // @require https://update.greasyfork.icu/scripts/482874/1299974/%E4%B8%AD%E5%BB%BA%E5%AD%A6%E4%BC%81%E6%9D%A5%E5%85%A8%E9%A2%98%E5%BA%93part3.js // @require https://update.greasyfork.icu/scripts/482875/1299975/%E4%B8%AD%E5%BB%BA%E5%AD%A6%E4%BC%81%E6%9D%A5%E5%85%A8%E9%A2%98%E5%BA%93part4.js // @require https://update.greasyfork.icu/scripts/482876/1299976/%E4%B8%AD%E5%BB%BA%E5%AD%A6%E4%BC%81%E6%9D%A5%E5%85%A8%E9%A2%98%E5%BA%93part5.js // @require https://update.greasyfork.icu/scripts/482877/1299978/%E4%B8%AD%E5%BB%BA%E5%AD%A6%E4%BC%81%E6%9D%A5%E5%85%A8%E9%A2%98%E5%BA%93part6.js // @require https://update.greasyfork.icu/scripts/483542/1304947/gk%E3%81%AE%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E4%B8%80%E8%A6%A7.js // @downloadURL none // ==/UserScript== /* *********************************************************** 以上参数为脚本必须读取的脚本元属性值,请勿随意改动 以下参数修改请参见语雀功能文档或者代码注释定制化修改 *********************************************************** */ (function () { 'use strict'; var oldStudyAdminRevise = true; // 控制学企来首页修改, true 为刷新; false 为不刷; var cscecAdminCount = true; // 控制主页刷新次数, true 为刷新; false 为不刷新; var rootFontSize = 46.6667; // 页面如果大小显示异常, 可尝试修改, 请勿随意变动此数值; var clickNextPage = true; // 旧版学企来部门中心默认进入第二页, false 则不翻页; var answerTimeGap = 400; // 一键做题操作间隔, 太快页面来不及响应, 太慢影响使用, 单位:ms; var loginCheck = 500; // 输入验证码后登录的间隔, 太快无法响应, 太慢影响使用, 单位:ms; var monitorGap = 400; // 控制url监控间隔, 太快会影响性能, 太慢影响使用, 单位:ms; var yourName = ""; // 问卷星填写名字 var yourApartment = "/"; // 问卷星填写部门 var yourId = ""; // 问卷星填写员工编号 var yourPost = "专业工程师"; // 问卷星填写岗位 /* *********************************************************** 以下参数为功能必须的参数初始化或功能预留,请勿随意改动 *********************************************************** */ var AllQA = AllQA1.concat(AllQA2, AllQA3, AllQA4, AllQA5, AllQA6); console.log("全题库共 " + AllQA.length + " 道题目"); var targetValues = ["您的姓名:", "您的部门:", "所属项目:", "所在岗位:"]; var rightArr = ["正确", "对", "✓", "√", "A", "a", "是"]; var wrongArr = ["错误", "错", "×", "x", "B", "b", "否"]; var questionAnswerTexts = ""; // 防止答案混淆,目前考试无答案混淆,只做预防 var questionAnswerText = ""; var clickMyPractice = true; var questionTypeText = ""; var isDraggable = false; var titleMsgAlert = ""; var innerMsgAlert = ""; var answerArray = ''; var currentUser = ""; var userRemind = ""; var currentUrl = ""; var a = ""; var b = ""; var C = ""; var d = ""; var examQuestionTypeArray = []; var oldPracticeData = []; var practiceData = []; var savedData = []; overrideOpen(); setMouseImg(); setTipsImg(); webPageWatchUrl(urlOperate); window.onload = function () { addDiv(); changeByClick(); var tipsCard = document.getElementById("tipsCard"); tipsCard.addEventListener('mouseover', displayTipsImg); tipsCard.addEventListener('mouseout', vanishTipsImg); tipsCard.addEventListener('mousemove', displayTipsImg); document.addEventListener('mousemove', mouseImgMove); document.querySelectorAll(".getQAOption")[0].addEventListener('click', getabAndToast); document.querySelectorAll(".option2")[0].addEventListener('click', function () { if (getab()) { switch (verifyUrl()) { case 1: answerQuestion(); break; case 2: answerOldQuestion(); break; default: getabAndToast(); break; } } else { getabAndToast(); } }); document.querySelectorAll(".option3")[0].addEventListener('click', function () { if (getab()) { switch (verifyUrl()) { case 1: autoAnswerQuestion(); break; case 3: try { answerOldExam(); } catch (error) { toast("未完全适配导致的问题", "请 Ctrl+S 保存页面并联系我", 2e3); } break; default: getabAndToast(); break; } } else { getabAndToast(); } }); document.querySelectorAll(".option4")[0].addEventListener('click', answerQAStarExam); document.querySelectorAll(".option7")[0].addEventListener('click', fillVerificationCode); } function answerOldQuestion() { var titleName = document.querySelector(".title"); if (titleName) { if (titleName.innerText === "每日一练" || titleName.innerText === "闯关练习") { var elements = document.getElementsByClassName("issus-item-title-text"); try { var trimmedText = trimText(elements[0].innerText); } catch (error) { } let questionAnswerBankIndex = AllQA.findIndex(function (item) { return trimText(item.question) == trimmedText; }); if (questionAnswerBankIndex !== -1 && getab()) { let questionType = getType(questionAnswerBankIndex); if (questionType.includes("单选")) { let answerSpans = Array.prototype.slice.call(document.querySelectorAll(".issus-item-answer-radio-label")); let answerArray = convertToNumbers(convertAnswerToArray(questionAnswerBankIndex)); answerSpans[answerArray[0] - 1].click(); } else if (questionType.includes("判断")) { var judgeStr = getAnswer(questionAnswerBankIndex).match(/(正确)|(错误)|[对错✓√×xABab]/g); try { let judgeStrClick = 'input[class="el-radio__original"][value=' + judgeStr + ']'; document.querySelector(judgeStrClick).click(); } catch (error) { if (rightArr.includes(judgeStr[0])) { for (let i = 0; i < rightArr.length; i++) { try { var judgeStrClick = 'input[class="el-radio__original"][value=' + rightArr[i] + ']'; document.querySelector(judgeStrClick).click(); break; } catch (error) { } } } if (wrongArr.includes(judgeStr[0])) { for (let i = 0; i < wrongArr.length; i++) { try { var judgeStrClick = 'input[class="el-radio__original"][value=' + wrongArr[i] + ']'; document.querySelector(judgeStrClick).click(); break; } catch (error) { } } } } } else if (questionType.includes("多选")) { let answerSpans = Array.prototype.slice.call(document.querySelectorAll('span.el-checkbox__input')); let arr = convertToNumbers(convertAnswerToArray(questionAnswerBankIndex)); for (var i = 0; i < arr.length; i++) { // 因为页面异步动画影响,直接点击会无法处理 (function (i) { requestAnimationFrame(function () { answerSpans[arr[i] - 1].click(); }); })(i); } } } else { toast("未找到答案", "题库无此题,请及时记录维护题库或 Ctrl+S 保存页面", 2e3); } try { let parentElement = document.querySelector('div[class="btn-content"]'); let element = parentElement.querySelector('.el-button.fr.el-button--primary.el-button--mini'); if (element === undefined || element === null) { clickSpanContainingText('结束练习'); } else { element.click(); } } catch (error) { console.log("尝试确定失败"); } } else if (titleName.innerText === "成绩结果") { if (document.querySelector(".upper-limit-tips")) { // 返回 setTimeout(function () { document.querySelector(".back").childNodes[0].click(); }, 100); toast("完成", "此练习分数已满,请选择下一项练习。", 2e3); } } else { toast("此页面未配置本功能", "请进入指定界面或关闭此脚本!", 3e3); } } else { toast("此页面未配置本功能", "请进入指定界面或关闭此脚本!", 2e3); } } function answerOldExam() { examQuestionTypeArray = getQuestionType(); for (let i = 0; i < examQuestionTypeArray.length; i++) { if (examQuestionTypeArray[i].Type.includes("单选")) { console.log("开始作答单选题"); let typeElements = document.querySelector("#app > div > div.preview-box > div.preview-main > div:nth-child(" + (i + 1) + ")"); let childrenQuestion = typeElements.getElementsByClassName("issus-item-title-text"); for (let j = 0; j < childrenQuestion.length; j++) { let questionFind = trimText(childrenQuestion[j].innerText); let questionIndex = AllQA.findIndex(function (item) { return trimText(item.question) == questionFind; }); try { if (questionIndex > -1) { let childrenAnswer = childrenQuestion[j].parentElement.nextElementSibling.getElementsByClassName(("issus-item-answer-radio-label")); let answerArray = convertAnswerArrayToDigitArray(questionIndex); setTimeout(() => { childrenAnswer[answerArray[0] - 1].click(); console.log("已作答单选题 " + (j + 1)); }, 10); } else { console.log("未获取到单选题 " + (j + 1) + " 的答案"); continue; } } catch { console.log("获取单选题 " + (j + 1) + " 答案失败"); continue; } } } else if (examQuestionTypeArray[i].Type.includes("多选")) { console.log("开始作答多选题"); let typeElements = document.querySelector("#app > div > div.preview-box > div.preview-main > div:nth-child(" + (i + 1) + ")"); let childrenQuestion = typeElements.getElementsByClassName("issus-item-title-text"); for (let j = 0; j < childrenQuestion.length; j++) { let questionFind = trimText(childrenQuestion[j].innerText); let questionIndex = AllQA.findIndex(function (item) { return trimText(item.question) == questionFind; }); try { if (questionIndex > -1) { // 获取对应题目的选项 let childrenAnswer = childrenQuestion[j].parentElement.nextElementSibling.getElementsByClassName(("issus-item-answer-radio-label")); let answerArray = convertAnswerArrayToDigitArray(questionIndex); for (let n = 0; n < answerArray.length; n++) { (function (n) { requestAnimationFrame(function () { setTimeout(() => { childrenAnswer[answerArray[n] - 1].click(); console.log("已作答多选题 " + (j + 1) + "的选项: " + n); }, 200); }); })(n); } } else { console.log("未获取到多选题 " + (j + 1) + " 的答案"); continue; } } catch { console.log("获取多选题 " + (j + 1) + " 答案失败"); continue; } } } else if (examQuestionTypeArray[i].Type.includes("判断")) { console.log("开始作答判断题"); let typeElements = document.querySelector("#app > div > div.preview-box > div.preview-main > div:nth-child(" + (i + 1) + ")"); let childrenQuestion = typeElements.getElementsByClassName("issus-item-title-text"); for (let j = 0; j < childrenQuestion.length; j++) { let questionFind = trimText(childrenQuestion[j].innerText); let questionIndex = AllQA.findIndex(function (item) { return trimText(item.question) == questionFind; }); try { if (questionIndex > -1) { let childrenAnswer = childrenQuestion[j].parentElement.nextElementSibling.getElementsByClassName(("issus-item-answer-radio")); let answerArray = getAnswer(questionIndex).match(/(正确)|(错误)|[对错✓√×xABab]/g); if (answerArray.some(item => rightArr.includes(item))) { childrenAnswer[0].firstChild.click(); } if (answerArray.some(item => wrongArr.includes(item))) { childrenAnswer[1].firstChild.click(); } console.log("已作答判断题 " + (j + 1)); } else { try { let childrenAnswer = childrenQuestion[j].parentElement.nextElementSibling.getElementsByClassName(("issus-item-answer-radio-label")); setTimeout(() => { childrenAnswer[0].firstChild.click(); }, 10); console.log("判断题蒙一个 " + (j + 1)); } catch (error) { } console.log("未获取到判断题 " + (j + 1) + " 的答案"); continue; } } catch { console.log("获取判断题 " + (j + 1) + " 答案失败"); continue; } } } else { toast("存在无法处理的题型", "请及时记录维护题库或 Ctrl+S 保存页面", 2e3); continue; } } } function answerQAStarExam() { try { if (verifyUrl() == 4) { try { document.querySelector("#q1_0").innerText = yourName; document.querySelector("#q1_1").innerText = yourApartment; document.querySelector("#q1_2").innerText = yourId; document.querySelector("#q1_3").innerText = yourPost; } catch (error) { console.log("方式一信息填写失败或部分失败,尝试使用方式二填写"); try { document.querySelector("#q1").value = yourName; document.querySelector("#q2").value = yourApartment; document.querySelector("#q3").value = yourId; document.querySelector("#q4").value = yourPost; } catch (error) { console.log("信息填写失败或部分失败"); } } var QAStarQuestion = document.querySelectorAll('.topichtml'); if (QAStarQuestion.length == 0) { QAStarQuestion = document.querySelectorAll('.topic__type-title'); } for (let j = 0; j < QAStarQuestion.length; j++) { let questionFind = trimText(QAStarQuestion[j].innerText); try { questionFind = questionFind.match(/.+?(?=【.*】$)/)[0] } catch { }; let questionIndex = AllQA.findIndex(function (item) { return trimText(item.question) == questionFind; }); if (questionIndex > -1) { let answerArray = convertAnswerArrayToDigitArray(questionIndex); for (let i = 0; i < answerArray.length; i++) { (function (i) { requestAnimationFrame(function () { setTimeout(() => { try { console.log(QAStarQuestion[j].nextElementSibling.childNodes[answerArray[i] - 1]); QAStarQuestion[j].nextElementSibling.childNodes[answerArray[i] - 1].click(); } catch (error) { try { QAStarQuestion[j].parentNode.nextSibling.childNodes[answerArray[i] - 1].click(); } catch (error) { } } try { console.log(QAStarQuestion[j].nextElementSibling.childNodes[answerArray[i] - 1].childNodes[0]); QAStarQuestion[j].nextElementSibling.childNodes[answerArray[i] - 1].childNodes[0].click(); } catch (error) { try { QAStarQuestion[j].nextSibling.childNodes[answerArray[i].childNodes[0] - 1].click(); } catch (error) { } } }, 150); }); })(i); } } else { console.log(QAStarQuestion[j] + " 未找到答案", "题库无此题,请及时记录维护题库或 Ctrl+S 保存页面"); } } } else { toast("此页面未配置本功能", "请进入指定界面或关闭此脚本!", 3e3); } } catch (error) { toast("未完全适配导致的问题", "请 Ctrl+S 保存页面并联系我", 2e3); } } function verifyUrl() { // 1 新版学企来练习 if (window.location.href.includes('https://learn.cscec83.cn/')) { return 1; // 2 旧版学企来练习 } else if (window.location.href.includes('http://120.27.194.253/')) { return 2; // 3 旧版学企来考试 } else if (window.location.href.includes('http://120.27.194.253/exam/')) { return 3; // 4 问卷星 } else if (window.location.href.includes('wjx.top/') || window.location.href.includes('wjx.cn/')) { return 4; // 5 公司登录界面 } else if (window.location.href.includes('https://www.cscec83.cn/user/login')) { return 5; } else { return false; } } function getAnswer(questionAnswerBankIndex) { return AllQA[questionAnswerBankIndex].answer; // 通过传入问题的索引来获取答案 } function getType(questionAnswerBankIndex) { return AllQA[questionAnswerBankIndex].type; } function getQuestion(questionAnswerBankIndex) { return AllQA[questionAnswerBankIndex].question; } function convertAnswerToArray(questionAnswerBankIndex) { let answerArray = getAnswer(questionAnswerBankIndex).match(/[A-Za-z]/g).map(function (val) { return val.toLowerCase(); }); return answerArray; } // 转换字母答案为数字并生成数组 function convertAnswerArrayToDigitArray(questionIndex) { let answerArray = convertAnswerToArray(questionIndex).map(char => char.charCodeAt(0) - 96); return answerArray; } // 数组中字母转换为数字 function convertToNumbers(arr) { return arr.map(function (letter) { var num = letter.charCodeAt(0) - 'a'.charCodeAt(0) + 1; return num; }); } // 点击页面具有某个文本的span function clickSpanContainingText(text) { var spans = document.getElementsByTagName('span'); for (var i = 0; i < spans.length; i++) { if (spans[i].textContent === text) { spans[i].click(); break; } } } function reviseRem() { var root = document.documentElement; var currentSize = parseFloat(window.getComputedStyle(root).fontSize); if (currentSize !== rootFontSize) { // root.style.fontSize = `${currentSize * 4}px`; root.style.fontSize = rootFontSize + "px" } } function webPageWatchUrl(watchCallback) { watchCallback(); var currentUrl = window.location.href; setInterval(function () { if (currentUrl !== window.location.href) { currentUrl = window.location.href; watchCallback(currentUrl); } }, monitorGap); } function urlOperate(url) { reviseRem(); currentUrl = window.location.href; if (currentUrl.includes('https://www.cscec83.cn/dashboard/analysis') && cscecAdminCount) { location.reload(); cscecAdminCount = false; }; if ((currentUrl === ('http://120.27.194.253/') || currentUrl === ('http://120.27.194.253/index')) && oldStudyAdminRevise) { try { let targetElement = document.querySelectorAll(".nav_item")[0]; targetElement.innerText = "科技质量"; targetElement.style.color = 'red'; targetElement.style.fontWeight = 'bold'; targetElement.parentNode.setAttribute("href", "/org/pgdJgz"); oldStudyAdminRevise = false; } catch (error) { console.log("old学企来首页科技质量修改失败"); } } if (currentUrl == 'http://120.27.194.253/org') { setApartmentCSS(); if (clickNextPage) { // 进入第二页 try { document.querySelector("#app > div > div.content > div.pagination.el-pagination.is-background > button.btn-next").click(); clickNextPage = false; } catch (error) { console.log("自动点击'我的'失败"); }; }; let departmentElement = document.querySelectorAll(".mechanism_item > .mechanism_item_title"); for (let i = 0; i < departmentElement.length; i++) { let targetElement = departmentElement[i]; if (targetElement.innerText == '科技质量部') { targetElement.style.color = 'red'; targetElement.style.fontWeight = 'bold'; }; }; }; if (currentUrl.match(new RegExp('http://120.27.194.253/org/[a-zA-Z]{6}$')) !== null) { try { if (clickMyPractice) { document.querySelector("#tab-my").click(); document.querySelector(".goods_type_list").childNodes[1].click(); clickMyPractice = false; } } catch (error) { clickMyPractice = false; }; } }; function fillVerificationCode() { if (window.location.href.includes('https://www.cscec83.cn/user/login')) { var imgSrc = document.querySelectorAll("img")[4].src; var image = new Image(); image.src = imgSrc; const { createWorker } = Tesseract; (async () => { const worker = await createWorker('eng'); const { data: { text } } = await worker.recognize(image); var inputElement = document.getElementById("inputCode"); inputElement.value = text; // 创建并触发 input 事件 var event = new Event('input', { bubbles: true, cancelable: true, }); inputElement.dispatchEvent(event); })(); setTimeout(function () { document.querySelector(".login-button").click(); }, loginCheck); } else { toast("此页面未配置本功能", "填写验证码", 2e3); return false; } } // 移动 function handleMouseDown(event) { isDraggable = true; var handleMoveDiv = document.getElementById("mainDiv"); var offsetX = event.clientX - handleMoveDiv.getBoundingClientRect().left; var offsetY = event.clientY - handleMoveDiv.getBoundingClientRect().top; // 阻止默认行为和冒泡 event.preventDefault(); event.stopPropagation(); document.addEventListener('mousemove', handleWindowMouseMove); document.addEventListener('mouseup', handleWindowMouseUp); function handleWindowMouseMove(event) { if (isDraggable) { requestAnimationFrame(() => { handleMoveDiv.style.left = event.clientX - offsetX + 'px'; handleMoveDiv.style.top = event.clientY - offsetY + 'px'; window.getSelection().empty(); }); } } function handleWindowMouseUp() { isDraggable = false; document.removeEventListener('mousemove', handleWindowMouseMove); document.removeEventListener('mouseup', handleWindowMouseUp); } } // 给所有的可选按钮增加点击事件 function changeByClick() { document.getElementById('movedCard').addEventListener('mousedown', handleMouseDown); // 给所有的图片增加点击事件(除了含有speedChoose类的) let images = document.querySelectorAll('.clickable-image'); images.forEach(image => { // 检查图片是否包含speedChoose类,如果不包含则添加点击事件 if (!image.classList.contains('speedChoose')) { image.addEventListener('click', function () { this.classList.toggle('clicked'); }); } }); // 按钮点击互斥 var speedChooses = document.querySelectorAll('.speedChoose'); speedChooses.forEach(function (box) { box.addEventListener('click', function () { // 如果当前按钮已经是点击状态,则取消点击状态,否则激活点击状态 if (box.classList.contains('clicked')) { box.classList.remove('clicked'); } else { // 点击任何一个box时,移除所有box的clicked类 speedChooses.forEach(function (otherBox) { otherBox.classList.remove('clicked'); }); box.classList.add('clicked'); } }); }); } function overrideOpen() { var open = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function () { var self = this; this.addEventListener('load', function () { var data = self.responseText; var isProfileData = (data.includes('userName') && data.includes('nickName') && data.includes('postGroup')); var isPracticeData = data.includes('testPaperTopics'); var isOldPracticeData = data.includes('loginName') && data.includes('nickname') && data.includes('userNo'); if (isProfileData || isPracticeData || isOldPracticeData) { if (isProfileData) { var profileData = profileData || []; if (!Array.isArray(profileData)) { profileData = []; } profileData = JSON.parse(data); handleProfileData(profileData); } if (isPracticeData) { practiceData = practiceData || []; if (!Array.isArray(practiceData)) { practiceData = []; } practiceData.push(JSON.parse(data)); handlePracticeData(practiceData); } if (isOldPracticeData) { oldPracticeData = oldPracticeData || []; if (!Array.isArray(oldPracticeData)) { oldPracticeData = []; } oldPracticeData.push(JSON.parse(data)); handleOldPracticeData(oldPracticeData); } } }); open.apply(this, arguments); }; } function handlePracticeData(practiceData) { return new Promise(function (resolve) { var targetArray = practiceData.find(function (response) { return response.msg === "操作成功" && response.code === 200 && response.data.testPaperTopics; }); if (targetArray) { let formattedData = outputPracticeTopics(targetArray.data); savedData = formattedData.slice(); } else { console.log('脚本未找到符合条件的题库信息'); } practiceData.length = 0; resolve(); }); } function handleProfileData(profileData) { return new Promise(function (resolve) { var targetArray = Object.values(profileData).find(function (response) { return typeof response === 'object' && response !== null; }); if (targetArray) { let result = { userName: targetArray.userName, nickName: targetArray.nickName, }; let formattedData = outputProfileDataTopics(JSON.stringify(result)); currentUser = formattedData; titleMsgAlert = currentUser.userName + " " + currentUser.nickName; } else { console.log("脚本未找到符合条件的个人信息"); } targetArray = []; resolve(); }); } function handleOldPracticeData(oldPracticeData) { return new Promise(function (resolve) { var targetArray = oldPracticeData.find(function (response) { return response.code === 200 && response !== null; }); if (targetArray) { let result = { "userName": targetArray.data.loginName, "nickName": targetArray.data.nickname, }; currentUser = result; titleMsgAlert = result.userName + " " + result.nickName; } else { console.log("脚本未找到符合条件的个人信息"); } targetArray = []; resolve(); }); } function answerQuestion() { var isQuestionFound = savedData.some((questionObject) => { return trimText(questionObject.question) == trimText(document.querySelectorAll(".el-card__body")[1].childNodes[2].innerText); }); if (isQuestionFound && getab()) { var answerList = []; let questionNumber = getQANumber(); for (let i = 0; i < savedData.length; i++) { let answerArray = savedData[i].TrueAnswer.split(','); let numericArray = answerArray.map(function (letter) { // 多减 1 个 1, 后面处理点击次序时方便 return letter.charCodeAt(0) - 65; }); answerList.push(numericArray); } try { if (answerList[questionNumber - 1].length == 1) { var targetAnswerElement = document.querySelectorAll(".el-radio-group")[0].childNodes[answerList[questionNumber - 1][0]]; if (targetAnswerElement && !targetAnswerElement.classList.contains('is-checked')) { targetAnswerElement.click(); console.log("题号 " + questionNumber + " 点选: " + String.fromCharCode((answerList[questionNumber - 1][0] + 1) + 64)); } else { console.log("用户选择过"); } } else if (answerList[questionNumber - 1].length > 1) { for (let i = 0; i < answerList[questionNumber - 1].length; i++) { (function (i) { requestAnimationFrame(function () { var targetAnswerElement = document.querySelectorAll(".el-checkbox-group")[0].childNodes[answerList[questionNumber - 1][i]]; if (targetAnswerElement && !targetAnswerElement.classList.contains('is-checked')) { targetAnswerElement.click(); console.log("题号 " + questionNumber + " 点击选项: " + String.fromCharCode((answerList[questionNumber - 1][i] + 1) + 64)); } else { console.log("用户选择过了"); } }); })(i); } } else { toast("提醒", "不在可答题的页面", 1e3); } } catch (error) { console.log("异常错误"); } } else { toast("提醒", "尝试检查权限与操作", 2e3); } } function autoAnswerQuestion() { if (getab()) { if (savedData.length == 0) { toast("未劫持到数据", "一键答题仅支持新版学企来、旧版学企来考试与问卷星", 2e3); } else { for (let i = getQANumber() - 1; i < savedData.length; i++) { try { setTimeout(function () { answerQuestion(); }, answerTimeGap * i); } catch (error) { toast("提醒", "请正常手动答题或重新进入", 2e3); } try { setTimeout(function () { document.querySelectorAll(".el-button")[0].click(); }, answerTimeGap * (i + 1 / 2)); } catch (error) { toast("提醒", "不在指定页面", 2e3); } if (i == savedData.length - 1) { toast("完成", "所有题目已完成", 2e3); } } } } else { toast("权限提醒", "请联系管理员添加权限", 2e3); } } function getab() { if (verifyUrl()) { try { var a = userList.some(function (user) { if (user.userName === currentUser.userName && user.nickName === currentUser.nickName) { return true; } else { return false; } }); } catch (error) { a = false; b = false; toast("提醒", "请从公司页面正常渠道进入", 1e3); return (a && b); } if (a) { try { var userName = userList.find(u => u.userName === currentUser.userName); var userTime = userName ? userName.time : null; } catch (error) { console.log("时长获取错误。"); return (a && b); } innerMsgAlert = ""; innerMsgAlert = verifyTime(userTime) ? verifyTime(userTime) : "  权限过期 请联系重新授权。"; return (a && verifyTime(userTime)); } else { a = false; b = false; switch (verifyUrl()) { case 4: titleMsgAlert = "Notion"; innerMsgAlert = "问卷星答题与验证码识别功能开放使用,答题请移步答题界面。"; break; case 5: titleMsgAlert = "Notion"; innerMsgAlert = "验证码识别功能与问卷星答题开放使用,答题请移步答题界面。"; break; default: innerMsgAlert = ""; for (let i = 0; i < failStringArray.length; i++) { innerMsgAlert += String.fromCharCode(failStringArray[i]); } break; } return (a && b); } } else { a = false; b = false; titleMsgAlert = "查 询 失 败"; innerMsgAlert = "请登录公司学企来后使用"; return (a && b); } } function getabAndToast() { getab(); waitToast(titleMsgAlert, innerMsgAlert, a); } function waitToast(titleText, innerText, logText) { let CustomBox = Box.mixin({ customFunction: function () { console.log(logText); }, }); let customBoxInstance = new CustomBox({ title: titleText, text: innerText, }); try { customBoxInstance.customFunction(); } catch (error) { console.log("toast 库 error"); } } function toast(title, innerText, time) { let Toast = Box.mixin({ title: title, toast: true, time: time, }); new Toast({ text: innerText }); } })();