Greasy Fork is available in English.

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

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

// ==UserScript==
// @name         气象干部培训学院科学学习
// @version      3.1
// @description  气象干部培训学院科学学习20240927
// @author       20240927
// @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*
// @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 () {
	$(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 {
					$("#course_player").prop("muted", 1); //静音
					$("#ckplayer_a1").prop("muted", 1); //静音
					$("video").prop("muted", 1); //静音
					$("#msgbt").click(); //点击继续播放
					if($(".continue").css("display")!="none"){$(".user_choise").click();} //点击开始播放
					$("#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;
		}
		function postLearnTime(userId, lessonId, coursewareId, tclessonId, lessonOrigin, lessonGkey, exitplaytime, uncle) {
			if (uncle.attr("title") == "100%") {
				console.log("已完成");
				window.location.reload();
				return;
			}
			let data = {
				userId: userId,
				lessonId: lessonId,
				coursewareId: coursewareId,
				tclessonId: tclessonId,
				lessonOrigin: lessonOrigin,
				standard: "6",
				isMobile: "0",
				isPreview: "false",
				lessonGkey: lessonGkey,
				exitplaytime: exitplaytime,
				serverId: "9002",
				learntime: "120",
			};
			let url = "http://www.cmatc.cn/lms/app/lms/student/Learn/recordLearnTimePro.do";
			$.ajax({
				url: url,
				type: "POST",
				data: data,
				success: function (data) {
					console.log(data);
				},
			});
		}
		function getJindu(lessonId, tclessonId, lessonOrigin, uncle,e_index) {
			let data = {
				lessonId: lessonId,
				tclessonId: tclessonId,
				lessonOrigin: lessonOrigin,
			};
			let url = "http://www.cmatc.cn/lms/app/lms/student/Userselectlesson/commonlessonpasscond.do";
			$.ajax({
				url: url,
				type: "POST",
				data: data,
				success: function (data) {
					//console.log(data);
					let progress = "0";
					var matchReg = /(?<=学习进度为).*?(?=%,)/;
					var p = data.match(matchReg);
					progress = p?.toString() | "0";
					$("#progress"+e_index).text(progress + "%");
					$(".jindu_green").css("width", progress + "%");
					if(progress>2)uncle.attr("title", progress + "%");
				},
			});
		}
		//加装科学学习按钮
		if (url_href.indexOf("userselectlesson") != -1) {
			setTimeout(function () {
				window.location.reload();
			}, 120000);
			setTimeout(function () {
				var by = $("head").text();
				var matchReg = /(?<=userId\":\").*?(?=\",\"lessonId)/;
				var userId = by.match(matchReg);
				userId = userId?.toString();
				// window.localStorage.setItem("learningcoursenum", 0);				
				$("div.btn_box").each(function () {
					let box_html = $(this).html();
					box_html=box_html.replace(/<!--/g,"").replace(/-->/g,"");
					$(this).html(box_html);
				});
				$("a.learn").each(function () {
					var sp = $(this);
					var e_index = $(this).index();
					// 获取父元素的上一个元素
					var uncle = sp.parent().prev();
					var progress = uncle.attr("title");
					if (progress == "100%") {
						sp.text("已完成");
						return;
					}
					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");
						let msg="学习中";
						var hrefs ="#"; 
						if(progress == "0.0%"||progress == "0%"){
							msg="请先自学";
							hrefs = "http://www.cmatc.cn/lms/app/lms/student/Learn/enter.do?lessonId=" + lessonId + "&coursewareId=" + coursewareId + "&lessonGkey=" + lessonGkey + "&tclessonId=" + tclessonId + "&lessonOrigin=" + lessonOrigin;
						}else{
							postLearnTime(userId, lessonId, coursewareId, tclessonId, lessonOrigin, lessonGkey, 0, uncle);
							getJindu(lessonId, tclessonId, lessonOrigin, uncle,e_index);
							setInterval(function () {
								postLearnTime(userId, lessonId, coursewareId, tclessonId, lessonOrigin, lessonGkey, 0, uncle);
								getJindu(lessonId, tclessonId, lessonOrigin, uncle,e_index);
							}, 35000);
						}
						var spans = '<a id="myspan'+e_index+'" class="learn" target=_blank href="'+hrefs+'" style="color:red;">'+msg+'</a>';
						var spans1 = '<a id="progress'+e_index+'" class="learn" style="color:red;"">' + progress + "</a>";
						$(this).after(spans1);
						$(this).after(spans);					
					}
				});
			},5000);
		}
		if (url_href.indexOf("recordlearntime") != -1) {
			_submitLearnTime(120);
			setInterval(function () {
				_submitLearnTime(120);
			}, 35000);
		}
	});
})();