NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name zutGetCourse // @namespace http://www.xyde.net.cn/ // @version 1.2 // @description 可以快速提交选中的网课 // @author JiGuang // @license MIT // @copyright http://www.xyde.net.cn/ // @homepageURL http://www.xyde.net.cn/ // @match http://xsxk.zut.edu.cn/* // @require https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.min.js // @require https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js // @require https://unpkg.com/sweetalert/dist/sweetalert.min.js // @grant GM_log // @grant GM_getValue // @grant GM_setValue // @grant GM_notification // ==/UserScript== (function() { 'use strict'; //CSS代码 var style = document.createElement('link'); style.href = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'; style.rel = 'stylesheet'; style.type = 'text/css'; document.getElementsByTagName('head').item(0).appendChild(style); //工具类代码 function notify(message){ swal(message, { buttons: false, timer: 2000, }); } function addOne(e){ if(sessionStorage.getItem(n1)){ var data = JSON.parse(sessionStorage.getItem(n1)); if(data.indexOf(e)!== -1){ return false; } data.push(e); sessionStorage.setItem(n1,JSON.stringify(data)); return true; }else{ var res = []; res.push(e); var res_ = JSON.stringify(res); sessionStorage.setItem(n1,res_); return true; } } function getAll(){ if(sessionStorage.getItem(n1)){ return JSON.parse(sessionStorage.getItem(n1)); }else{ return []; } } function deleteAll(){ sessionStorage.removeItem(n1); } function selectAll(){ if(getAll().length == 0){ swal({ title: "请先添加课程再开始", icon: "error", }); return; } timer = setInterval(function(){ var list = getAll(); for(var i = 0; i < list.length;i++){ var addParam = buildAddVolunteerParam(list[i]); addVolunteer(addParam).done(function(resp) { console.log(resp); if(resp.code != 2){ successes++; } }) times++; } },100); } function stopSelect(){ clearInterval(timer); swal({ title: "暂停成功", icon: "success", button: "确定", }); } //全局配置 var name = '选课插件'; //存储名 var n1 = 'array'; var times = 0; var successes = 0; //timer_id var timer = 0; //下面是正式代码 if(location.href == 'http://xsxk.zut.edu.cn/xsxkapp/sys/xsxkapp/*default/index.do'){ swal({ title: "恭喜您", text: name+"开启成功,您只需要在浏览器点击选课后,根据界面开始高速选课即可。", icon: "success", button: "我知道了", }); }else{ if(location.href.indexOf('grablessons.do')!=-1){ swal({ title: "插件提示", text: "目前支持通识课选课,选课时请不要刷新网页", icon: "warning", button: "我知道了", }); //为课程创建添加按钮 setInterval(function(){ var btns = document.getElementsByClassName('cv-choice'); for(var i = 0;i < btns.length; i++){ if(btns[i].parentElement.childElementCount === 2){ var tcid = btns[i].attributes.tcid.value; var btn_i = document.createElement('button'); btn_i.type = 'button'; btn_i.style.marginTop = '10px'; btn_i.innerText = '添加至高速选课'; btn_i.classList.add('btn'); btn_i.classList.add('btn-info'); btn_i.id = tcid; btn_i.onclick = function(){ if(addOne(this.attributes.id.value)){ swal("添加成功", "您已经成功将该课程加入待选列表", "success"); }else{ swal("添加失败", "您已经添加过该课程!", "error"); } } btns[i].parentElement.appendChild(btn_i); } } },1000); //创建控制面板 var div1 = document.createElement('div'); div1.style.position = 'fixed'; div1.style.top = '10px'; div1.style.left = '10px'; div1.style.width = '200px'; div1.style.height = '380px'; div1.style.zIndex = 9999; div1.classList.add('panel'); div1.classList.add('panel-info'); var title_div = document.createElement('div'); title_div.classList.add('panel-heading'); var title_h3 = document.createElement('h3'); title_h3.classList.add('panel-title'); title_h3.innerText = name + ' - 控制面板'; var content_div = document.createElement('div'); content_div.classList.add('panel-body'); content_div.id = 'c'; title_div.appendChild(title_h3); div1.appendChild(title_div); div1.appendChild(content_div); document.body.appendChild(div1); var divx0 = document.createElement('p'); divx0.innerHTML = `<center>你好,${JSON.parse(sessionStorage.getItem('studentInfo')).name}</center>`; document.getElementById('c').parentElement.appendChild(divx0); var divx1 = document.createElement('p'); divx1.innerHTML = `<div class="alert alert-warning">已经选择 <span class="badge" id="number">-1</span> 门课程</div>`; document.getElementById('c').parentElement.appendChild(divx1); var divx2 = document.createElement('p'); divx2.innerHTML = `<center><span class="label label-primary">选课次数</span><span id="times" style="margin-left:10px;">0</span></center>`; document.getElementById('c').parentElement.appendChild(divx2); var divx3 = document.createElement('p'); divx3.innerHTML = `<center><span class="label label-success">成功次数</span><span id="successes" style="margin-left:10px;">0</span></center>`; document.getElementById('c').parentElement.appendChild(divx3); var btn_1 = document.createElement('button'); btn_1.style.width = '150px'; btn_1.style.marginLeft = '25px'; btn_1.type = 'button'; btn_1.innerText = '开始高速选课'; btn_1.classList.add('btn'); btn_1.classList.add('btn-success'); btn_1.onclick = selectAll; document.getElementById('c').parentElement.appendChild(btn_1); var btn_2 = document.createElement('button'); btn_2.style.width = '150px'; btn_2.style.marginLeft = '25px'; btn_2.style.marginTop = '10px'; btn_2.type = 'button'; btn_2.innerText = '清除选课列表'; btn_2.classList.add('btn'); btn_2.classList.add('btn-warning'); btn_2.onclick = function(){ deleteAll(); notify('删除成功'); } document.getElementById('c').parentElement.appendChild(btn_2); var btn_3 = document.createElement('button'); btn_3.style.width = '150px'; btn_3.style.marginLeft = '25px'; btn_3.style.marginTop = '10px'; btn_3.type = 'button'; btn_3.innerText = '停止高速选课'; btn_3.classList.add('btn'); btn_3.classList.add('btn-danger'); btn_3.onclick = stopSelect; document.getElementById('c').parentElement.appendChild(btn_3); var center_div = document.createElement('center'); var a1 = document.createElement('a'); a1.innerText = 'Powered By JiGuang'; a1.href = 'https://www.xyde.net.cn'; a1.style.textAlign = 'center'; center_div.appendChild(a1); document.getElementById('c').parentElement.appendChild(center_div); setInterval(function(){ document.getElementById('number').innerText = getAll().length; document.getElementById('times').innerText = times; document.getElementById('successes').innerText = successes; // var times = 0; // var successes = 0; },845); /* <div class="panel panel-info"> <div class="panel-heading"> <h3 class="panel-title">面板标题</h3> </div> <div class="panel-body"> 这是一个基本的面板 </div> </div> */ } } //思路 tcid从a标签获取,以下两步即可获取 //var addParam = buildAddVolunteerParam(tcid) //addVolunteer(addParam).done(function(resp) {console.log(resp);}) // Your code here... })();