// ==UserScript== // @name 传智网课答题 // @namespace http://stu.ityxb.com/writePaper/busywork/* // @version 1.7 // @description 传智教育答题 // @author 土豆 // @connect * // @match http://stu.ityxb.com/writePaper/busywork/* // @grant GM_xmlhttpRequest // @downloadURL none // ==/UserScript== var tibody;//题目数组 var total = 0;//题目总数量 var index = 0;//搜题索引自动增加 window.onload = function(){ tibody=document.getElementsByClassName("questionItem question-item-box"); total = tibody.length; kaishi(tibody[index]);//传入每道题 // 创建一个新的 div 元素 let newDiv = document.createElement("div"); // 给它一些内容 let newContent = document.createTextNode("自动答题功能并不完善,自己看着答案再选一遍,联系qq2049672011"); // 添加文本节点 到这个新的 div 元素 newDiv.appendChild(newContent); newDiv.style.position='fixed'; newDiv.style.backgroundColor='red' // newDiv.style.width='20px'; // newDiv.style.length='20px'; newDiv.style.fontSize='20px'; document.querySelector("body > div:nth-child(3) > div > div > div.main-box > div > div > header > div.header_top_mes.clearfix").appendChild(newDiv); newDiv.style.top='60px'; } function kaishi(ti){ GM_xmlhttpRequest({//油猴脚本提供的异步函数 method: 'POST', url: 'http://cx.icodef.com/wyn-nb?v=2',//网课接口 headers: { 'Content-type': 'application/x-www-form-urlencoded' }, data: 'question='+ encodeURIComponent(ti.getElementsByClassName("question-title-box")[0].innerText), timeout: 2000, onload:function(xhr) { //自动选择答案 let json=JSON.parse(xhr.responseText); let daan=json.data; if(json.code==-1)daan="答案未找到"; // console.log(xhr.responseText.code); let answerarray=daan.split('#');//答案数组 let daanlength=ti.getElementsByClassName("radio_item question-option-item-box").length;//多少个选项 for(let i=0;i'+answerarray[i]; } ti.getElementsByClassName("question-title-box")[0].innerHTML += "
答案:"+newdaan; if(index < total - 1)//继续搜索接下来的题 { setTimeout(function (){ index = index + 1; kaishi(tibody[index]); }, 1000); } } }) }