电子科大继续教育学院自动翻页脚本

完全重写

// ==UserScript==
// @name         电子科大继续教育学院自动翻页脚本
// @namespace    http://tampermonkey.net/
// @version      1.0.4
// @description  完全重写
// @author       曦月
// @match        http://learning.uestcedu.com/*
// @match        http://ispace.uestcedu.com/*
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js
// @grant        none
// ==/UserScript==

(function() {
	//作者:曦月
	//发布时间:2020年11月18日10:17:11
	//版本:v1.0.0
	$(function () {
		if (window.location.href.includes("learning.uestcedu.com/learning3/console/")) {
			main_page()
		}else if(window.location.href.includes("ispace.uestcedu.com")){
			switch_page()
		}
	})
	function main_page() {
		$('body').append('<div id="pay_" style="top:0px;position: absolute; height: 68px;width:440px; z-index: 999;left:0px;background-color: #bd0000;line-height:68px;color:#ffffff;text-indent: 15px;">脚本运行中 v1.0.0<a target="view_window" href="https://greasyfork.org/zh-CN/scripts/391818-%E7%94%B5%E5%AD%90%E7%A7%91%E5%A4%A7%E7%BB%A7%E7%BB%AD%E6%95%99%E8%82%B2%E5%AD%A6%E9%99%A2%E8%87%AA%E5%8A%A8%E7%BF%BB%E9%A1%B5%E8%84%9A%E6%9C%AC"><img style="width:100%" src="https://i.loli.net/2020/02/06/D4vn7hrIkuasRGP.jpg"></a></div>')
		var s=document.createElement('style');
		s.innerText='#pay_:hover{overflow:visible;}#pay_{overflow:hidden;}'
		document.body.appendChild(s);
		var if_1 = $("iframe").eq(1)
		if_1[0].onload = function () {
			var has_div = $("div",if_1.contents())
			if (has_div.length > 0) {
				var get_kq = setInterval(function () {
					$("tbody tr [id='tr_tblDataList_0']",if_1.contents()).each((index, el) => {
						if ($(el).text().length > 4 && !$(el).text().includes("作业提交")) {
							$(el).parent().find("a").eq(0)[0].click()
						}
					})
				},1000)
			}else{
				let if_2 = $("frame",if_1.contents()).eq(0)
				let if_3 = $("frame",if_1.contents()).eq(1)
				let tag = 0
				let this_num = 0
				let total_time = 0
				let this_time = 0
				setInterval(function () {
					var temp_td = $("td [align='center']",if_3.contents())
					temp_td.each(function(index, el) {
						if ($(el).text().includes("已经学习完毕")) {
							next_page()
						}else if ($(el).text().includes("您正在学习")) {
							let text = $(el).clone()
							$("script",text).remove()
							text = text.text()
							tag = parseInt(text.split("本内容")[1])
							this_num = parseInt(text.split("你已累计获取")[1])
							total_time = text.split("学习了")[1].slice(0,8).split(":")
							total_time = total_time[0]*3600 + total_time[1]*60 + total_time[2]*1
							if (this_time === 0) {
								this_time = parseInt(text.split("最少要求学习")[1])
							}
							if (tag == this_num && total_time >= this_time) {
								next_page()
							}
						}
					});
				},1000)
				function next_page() {
					$("#btnNext",if_2.contents()).click()
				}
			}
		}
	}
	function switch_page() {
		let end = $("span[hd]").length-1
		let i = 0;
		setInterval(function () {
			let h1 = $("h1")
			h1.each(function(index, el) {
				if ($(el).text() === "An error occurred.") {
						window.location.reload()
				}
			});
		},3000)
		let switch_page = setInterval(function () {
			if (end === -1) {
				clearInterval(switch_page)
			}else{
				$("span[hd]")[i].click();
				if (i == end) {
					clearInterval(switch_page)
				}
				i++;
			}
		},1000)
	}
})();