气象干部培训学院科学学习

气象干部培训学院科学学习20231007

// ==UserScript==
// @name         气象干部培训学院科学学习
// @version      2.8
// @description  气象干部培训学院科学学习20231007
// @author       20231007
// @match        http://*.cmatc.cn/*
// @match        http://*.cma.cn/*
// @match        https://*.cmatc.cn/*
// @match        https://*.cma.cn/*
// @license      GPL-3.0 License
// @exclude      http://www.cmatc.cn/lms/app/lms/lesson/Lesson/studentSelectLesson.do*
// @exclude      http://www.cmatc.cn/lms/app/tms/trainclass/Trainclass/trainclassIndex.do*
// @exclude      http://www.cmatc.cn/lms/framebase/scripts/my97datepicker/my97datepicker.htm*
// @exclude      http://www.cmatc.cn/lms/app/lms/student/learn/exitlesson.do*
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js
// @namespace    http://www.cmatc.cn/lms/app/lms/lesson/Lesson/studentSelectLesson.do
// @home-url     https://greasyfork.org/zh-CN/scripts/452787
// @grant        unsafeWindow
// ==/UserScript==

(function () {
// 	window.unsafeWindow.open = function (url, name, features) {
// 		window.open(url, "_blank");
// 		return undefined;
// 	};
// 	if (typeof _openFullWindowCenter != "undefined") {
// 		const _openFullWindowCenterOrignal = _openFullWindowCenter;
// 		_openFullWindowCenter = function (url, winName, scrollbars, title) {
// 			return _openFullWindowCenterOrignal(url, "_blank", scrollbars, undefined);
// 		};
// 	}
// 	if (typeof startLesson !== "undefined") {
// 		startLesson = function () {
// 			return _learncondition.apply(this, arguments);
// 		};
// 	}
	$(document).ready(function () {
		var userid = window.localStorage.getItem("userid");
		var password = window.localStorage.getItem("password");
		var url_href = window.location.href.toLowerCase();
		console.log("气象干部培训学院科学学习", url_href);
		var clearDiv =
			"<div id='studentId' style='width:250px;font-size:12px;background-color:#fff;border:#ccc solid 1px;position:fixed;left:3px;top:3px;z-index:9999'>";
		clearDiv += "当前ID号:" + userid + "</div>";
		$("body").append(clearDiv);
		function autoLogin() {
			$("#txtusername1").val(userid);
			$("#txtpassword1").val(password);
			$("input[name='submxxit']").click();
			dologin();
		}
		$("#fm1").submit(function (e) {
			userid = $("#txtusername1").val();
			password = $("#txtpassword1").val();
			window.localStorage.setItem("userid", userid);
			window.localStorage.setItem("password", password);
			console.log("账号密码" + userid + "," + password);
		});
		$('input[name="submxxit"]').click(function () {
			userid = $("#txtusername1").val();
			password = $("#txtpassword1").val();
			window.localStorage.setItem("userid", userid);
			window.localStorage.setItem("password", password);
			console.log("账号密码" + userid + "," + password);
		});
		//登录页面自动登录
		if (url_href.indexOf("sso/login") != -1) {
			if ($("#msg").text().indexOf("登录成功") != -1) {
				window.location.href =
					"http://www.cmatc.cn/lms/app/lms/student/Userdashboardinfo/show.do";
			} else {
				$("body").append(clearDiv);
				if (userid == null || userid == "null" || userid == "") {
					console.log("ID为空");
					return;
				}
				$("#txtusername1").val(userid);
				$("#txtpassword1").val(password);
				hintMsg();
			}
		}
		var tt = 20;
		function hintMsg() {
			if (tt === 0) {
				autoLogin();
				return;
			} else {
				tt--;
				$("input.btn-submit").val(tt + "秒后将自动登录");
			}
			setTimeout(function () {
				hintMsg();
			}, 1000);
		}
		if (url_href.indexOf("/index/index.shtml") != -1) {
			var loginMsg = $("#loginMsg").text();
			setTimeout(function () {
				window.location.href =
					"http://www.cmatc.cn/lms/app/tms/sfi/StudyContent/year.do";
			}, 120000);
			if (loginMsg == "用户登录") {
				window.location.href =
					"http://www.cmatc.cn/sso/login?service=http%3A%2F%2Fwww.cmatc.cn%2Flms%2Fj_spring_cas_security_check";
			}
		}
		//学员首页120秒跳转个人信息,跳来跳去不掉线loginMsg
		if (url_href.indexOf("userdashboardinfo/show.do") != -1) {
			//console.log("StudyContent");
			var loginMsg1 = $("#loginMsg").text();
			setTimeout(function () {
				window.location.href =
					"http://www.cmatc.cn/lms/app/tms/sfi/StudyContent/year.do";
			}, 120000);
			if (loginMsg1 == "用户登录") {
				window.location.href =
					"http://www.cmatc.cn/sso/login?service=http%3A%2F%2Fwww.cmatc.cn%2Flms%2Fj_spring_cas_security_check";
			}
		}
		//个人中心120秒跳转个人信息,跳来跳去不掉线
		if (url_href.indexOf("studycontent/year.do") != -1) {
			//console.log("StudyContent");
			var loginMsg2 = $("#loginMsg").text();
			setTimeout(function () {
				window.location.href =
					"http://www.cmatc.cn/lms/app/tms/sfi/StudyContent/year.do";
			}, 120000);
			if (loginMsg2 == "用户登录") {
				window.location.href =
					"http://www.cmatc.cn/sso/login?service=http%3A%2F%2Fwww.cmatc.cn%2Flms%2Fj_spring_cas_security_check";
			}
		}
		//个人信息120秒跳转个人中心,跳来跳去不掉线
		if (url_href.indexOf("student/self.do") != -1) {
			//console.log("self");
			var loginMsg3 = $("#loginMsg").text();
			setTimeout(function () {
				window.location.href =
					"http://www.cmatc.cn/lms/app/tms/sfi/StudyContent/year.do";
			}, 120000);
			if (loginMsg3 == "用户登录") {
				window.location.href =
					"http://www.cmatc.cn/sso/login?service=http%3A%2F%2Fwww.cmatc.cn%2Flms%2Fj_spring_cas_security_check";
			}
		}
		//个人信息120秒跳转个人中心,跳来跳去不掉线
		if (url_href.indexOf("student/userdashboardinfo/showtrainclass.do") != -1) {
			//console.log("self");
			let loginMsg4 = $("#loginMsg").text();
			setTimeout(function () {
				window.location.href =
					"http://www.cmatc.cn/lms/app/tms/sfi/StudyContent/year.do";
			}, 120000);
			if (loginMsg4 == "用户登录") {
				window.location.href =
					"http://www.cmatc.cn/sso/login?service=http%3A%2F%2Fwww.cmatc.cn%2Flms%2Fj_spring_cas_security_check";
			}
		}
		var errorMsgCount = 0;
		//防止出现“点击继续观看”
		if (
			url_href.indexOf("enterurl") != -1 ||
			url_href.indexOf("stream2") != -1 ||
			url_href.indexOf("resource/course") != -1 ||
			url_href.indexOf("exitplaytime") != -1 ||
			document.getElementsByTagName("video").length > 0
		) {
			console.log("这是学习的页面");
			$("#studentId").text("10秒后自动开始");
			setInterval(function () {
				try {
					$("#msgbt").click(); //点击继续播放
					$(".user_choise").click(); //点击开始播放
					$("#course_player").prop("muted", 1); //静音
					$("#ckplayer_a1").prop("muted", 1); //静音
					$("video").prop("muted", 1); //静音
					$("#studentId").text("已开启:自动静音、自动点击继续观看");
				} catch (err) {
					errorMsgCount = errorMsgCount + 1;
					if (errorMsgCount <= 3) console.log(err);
				}
			}, 10000);
		}
		function getQueryVariable(urlStr, variable) {
			var vars = urlStr.split("&");
			for (var i = 0; i < vars.length; i++) {
				var pair = vars[i].split("=");
				if (pair[0] == variable) {
					return pair[1];
				}
			}
			return false;
		}
		//加装科学学习按钮
		if (url_href.indexOf("userselectlesson") != -1) {
			//var by=$("body").text();
			//var matchReg = /(?<=lessonGkey).*?(?=coursewareGkey)/;
			//var lessonGkey=by.match(matchReg);
			//lessonGkey=lessonGkey.toString().replace(/[&=]/g,"");
			//console.log('lessonGkey:'+lessonGkey);
            window.localStorage.setItem("learningcoursenum",0);
			$("a.learn").each(function () {
				var sp = $(this);
				if (sp.text() == "学习") {
					sp.text("学习");
					//   sp.css("background-color", "grey");
					//sp.css("display","none");
					var onclck_str = sp.attr("onclick");
					var msgs = onclck_str.substring(23, onclck_str.length - 2);
					var lst = msgs.split(",");
					var lessonId = lst[0].replace(/\'/g, "");
					var coursewareId = lst[1].replace(/\'/g, "");
					var lessonGkey = lst[2].replace(/\'/g, "");
					var tclessonId =
						getQueryVariable(url_href, "tclessonid") == false
							? 0
							: getQueryVariable(url_href, "tclessonid");
					var lessonOrigin =
						getQueryVariable(url_href, "lessonorigin") == false
							? "selflearn"
							: getQueryVariable(url_href, "lessonorigin");
					var hrefs =
						"http://www.cmatc.cn/lms/app/lms/student/Learn/enter.do?lessonId=" +
						lessonId +
						"&coursewareId=" +
						coursewareId +
						"&lessonGkey=" +
						lessonGkey +
						"&tclessonId=" +
						tclessonId +
						"&lessonOrigin=" +
						lessonOrigin;
					var spans =
						'<a class="learn" style="color:red;" target=_blank href="' +
						hrefs +
						'">科学学习</a>';
					$(this).after(spans);
				}
			});
			//   setInterval(function () {
			//     try {
			//       let by = $("body").text();
			//       let matchReg = /(?=您当前的学习进度为).*?(?=%)/;
			//       let point = by.match(matchReg);
			//       point = $.trim(point.toString().replace(/您当前的学习进度为/g, ""));
			//       console.log("您当前的学习进度为:" + point);
			//       if (point && point != "100.0") updateprogress();
			//     } catch (err) {}
			//   }, 55000);
		}
		if (url_href.indexOf("recordlearntime") != -1) {
			//   setTimeout(function () {
			//     let everyTime = _random(300, 480);
			//     let interval = _random(20000, 30000);
			//     console.log("每次提交秒数", everyTime, "频率", interval);
			//     setInterval(function () {
			//       console.log("提交时间");
			//       _submitLearnTime(everyTime);
			//       _exitLessonSubmit();
			//     }, interval);
			//   }, 12000);
		}
	});
})();