├── .gitignore ├── readme.md └── HUSTGrabClass.js /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # mac 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## 这是一个非常简陋的HUST抢课脚本 2 | 3 | * 把js里面的东西复制到tampermonkey里面使用 4 | 5 | * 改变量xuanke来修改检索词条,例如: 6 | 7 | > var xuanke="音乐" //从包含音乐词条里面的课中抢 8 | 9 | * 有些bug由于知识储备不够无法修改(我直接遇到bug就刷新),还等后续改进 10 | -------------------------------------------------------------------------------- /HUSTGrabClass.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name dddd 3 | // @namespace xhz 4 | // @version 0.1 5 | // @author xhz.xiahou@gmail.com 6 | // @match http://wsxk.hust.edu.cn/zxqstudentcourse/courseorclassroom.action* 7 | // @icon https://www.google.com/s2/favicons?domain=hust.edu.cn 8 | // @grant unsafeWindow 9 | // ==/UserScript== 10 | var xuanke="音乐" 11 | function sleep (time) { 12 | return new Promise((resolve) => setTimeout(resolve, time)); 13 | } 14 | function aa (iframe) { 15 | var idoc=(iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document 16 | // waitForKeyElements ('[id="kcmc"]', jNd => {jNd.val("音乐")}, true); 17 | idoc.getElementById("kcmc").value=xuanke; 18 | idoc.querySelector(".searchstyle").firstElementChild.lastElementChild.click(); 19 | 20 | sleep(200).then(()=>{ 21 | iframe=document.querySelector("iframe"); 22 | idoc=(iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document; 23 | var target=idoc.getElementsByClassName("tablelist"); 24 | if (target==null) reload(); 25 | if (target.length > 0){ 26 | for (let i = 0; i < target.length; ++i) { 27 | var str=target[i].cells[9].innerText; 28 | str = str.toString().replace(/\s*/g,""); 29 | str = str.split('/'); 30 | if (!target[i].cells[2].innerText.includes(xuanke)){console.log("error "+target[i].cells[2].innerText);reload();} 31 | 32 | if (Number(str[0])!=Number(str[1])){ 33 | 34 | var iframe1=document.getElementById("state_content").firstElementChild 35 | var iwin= iframe1.contentWindow 36 | 37 | iwin.confirm = function(msg){ console.log(msg);return true;}; 38 | target[i].lastElementChild.lastElementChild.click() 39 | }else{ 40 | sleep(800).then(()=>{ 41 | //window.location.reload(); 42 | reload(); 43 | }) 44 | } 45 | } 46 | }else{ 47 | alert("no targets!") 48 | reload(); 49 | } 50 | 51 | 52 | }) 53 | } 54 | function reload(){ 55 | window.location.href="http://wsxk.hust.edu.cn/zxqstudentcourse/courseorclassroom.action" 56 | } 57 | // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js 58 | // @require https://gist.github.com/raw/2625891/waitForKeyElements.js 59 | // @grant GM_addStyle 60 | //var xuefen=target[i].cells[4].innerText.split('/')[1]; 61 | //var what2=target[i].cells[2].innerHTML; 62 | //var bianhao=what2.split('=\'+')[1]; 63 | //bianhao=bianhao.split(')')[0]; 64 | //console.log(target[i],target[i].lastElementChild.lastElementChild.id,str[0],str[1],target[i].cells[2].innerText,xuefen,bianhao) 65 | //idoc.selectKT=function () { 66 | // idoc.getElementById("ktbh").value=target[i].lastElementChild.lastElementChild.id; 67 | // idoc.getElementById("ktrl").value=str[0]; 68 | // idoc.getElementById("ktrs").value=str[1]; 69 | // idoc.getElementById("kcmc1").value=target[i].cells[2].innerText; 70 | // idoc.getElementById("kczxf").value=xuefen; 71 | // idoc.getElementById("kcbh").value=bianhao; 72 | // idoc.form.submit(); 73 | // return true 74 | //} 75 | (function() { 76 | //字符串匹配,匹配到正确页面 77 | var str=RegExp('http://wsxk.hust.edu.cn/zxqstudentcourse/courseorclassroom.action','g'); 78 | var idoc=document; 79 | while(!str.test(idoc.URL)){ 80 | alert("error "+idoc.URL); 81 | idoc=idoc.getElementById("state_content").firstElementChild.concontentDocument; 82 | } 83 | idoc.getElementById('timeslot').click(); 84 | sleep(300).then(()=>{ 85 | var iframe=idoc.querySelector("iframe"); 86 | iframe.onload=aa(iframe) 87 | }) 88 | sleep(10000).then(()=>{ 89 | reload(); 90 | }) 91 | })(); 92 | --------------------------------------------------------------------------------