// ==UserScript== // @name 2021华医公需课 // @namespace http://tampermonkey.net/ // @version 0.9 // @description 2021华医公需课自动听课和自动考试脚本.华医的其它课程可以自动听课,但没有自动考试. // @author han2ee // @include http://cme*huayi.com/* // @include https://cme*huayi.com/* // @run-at document-start // @grant GM_xmlhttpRequest // @grant GM.setValue // @grant GM.getValue // @grant unsafeWindow // @downloadURL none // ==/UserScript== (function() { 'use strict'; const requestAsync = function(url, data) { // console.log(data); return new Promise((resolve, reject) => { var reportAJAX_Error = (rspObj) => { console.error (`Request error: ${data}`); reject(`Request => Error ${data} RES ${rspObj.status}! ${rspObj.statusText}`); } var processJSON_Response = (rspObj) => { if (rspObj.status != 200 && rspObj.status != 304) { reportAJAX_Error (rspObj); } else { resolve(rspObj.responseText); } }; GM_xmlhttpRequest ( { method: "GET", url: url, timeout: 6000, headers: { "Referer": document.location.href, "Content-Type": "application/x-www-form-urlencoded" }, data: data, // responseType: "json", onload: processJSON_Response, onabort: reportAJAX_Error, onerror: reportAJAX_Error, ontimeout: reportAJAX_Error }); }); } const getUrlParameter = function getUrlParameter(sParam) { var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return typeof sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); } } return false; }; const findFirstLesson = function(studyImgArr) { if (studyImgArr) { for (let i = 0; i < studyImgArr.length; i++) { if (studyImgArr[i].src.endsWith("anniu_01a.gif")) { return i; } } } return -1; } const nextLesson = async function(cwid) { let cid = await GM.getValue('cid'); console.log("CID", cid); let hrefs = await GM.getValue(cid); for (let i = 0; i < hrefs.length - 1; i++) { if (hrefs[i].indexOf(cwid) != -1) { window.location = hrefs[i + 1]; } } } const wait = ms => new Promise(resolve => setTimeout(resolve, ms)); const ANSWER_DICT = { // 科技创新现状与发展趋势 '4d8f0f21-a500-4dea-971d-ad2d00e8f196' : ['gvQuestion_rbl_0_0_0'], 'f1e74f27-c0c9-4db0-a710-ad2d00e8f196' : ['gvQuestion_rbl_0_0_0'], '931ae318-bf2e-4ccd-8190-ad2d00e8f196' : ['gvQuestion_rbl_0_0_0'], '6719c552-bf16-4111-acb5-ad2d00e8f196' : ['gvQuestion_rbl_0_0_0'], 'eb0ecb02-b6dd-4d87-95f8-ad2d00e8f196' : ['1bbf2da1-f5ca-4dcb-ba6b-ad2e00bb3422', '5cdc4638-9d87-4c21-9edd-ad2e00bb3422'], '2c2ad625-6c97-49b9-b763-ad2d00e8f196' : ['gvQuestion_rbl_0_0_0'], 'ce168b7f-1a36-40ba-ae81-ad2d00ff58e3' : ['4c7a52ac-ccf4-4c10-8c15-ad2e00be0a13', 'a8fb198d-ec7a-4777-bea6-ad2e00be0a13'], 'baee2ed1-140d-4ecc-aba4-ad2d00ff58e3' : ['gvQuestion_rbl_0_3_0'], 'feed2105-bb4b-42b3-ba5b-ad2d00ff58e3' : ['a00768d8-8c06-4411-932d-ad2e00bdbf42', '181c8e7a-28d7-4ad6-8395-ad2e00bdbf42'], '321a7b59-3c4d-4717-a7c9-ad2d00ff58e3' : ['3e4854ef-8e1a-4383-aca6-ad2e00bdeaab', 'ac0bc131-3bbc-42ec-b56a-ad2e00bdeaab'], '019ea052-3cd5-4307-b593-ad2d00ff58e3' : ['gvQuestion_rbl_0_0_0'], '3ce608c2-aeaa-412e-a7c2-ad2d00fc1ef8' : ['25bd1a55-851e-4dd8-81f6-ad2e00bdc848', '5a36cd31-b353-4c17-a41d-ad2e00bdc848', '20d59ec3-03f5-4681-995e-ad2e00bdc848'], '075a9616-0449-4945-918b-ad2d00fc1ef8' : ['9244ead2-2f04-4039-bdfc-ad2e00be211c', 'c1f63dcb-67bd-43ce-a7d6-ad2e00be211c'], '7b861782-2e3f-4bbe-a292-ad2d00fc1ef8' : ['gvQuestion_rbl_0_3_0'], '7f79db95-cacc-4e28-9208-ad2d00fc0c6b' : ['gvQuestion_rbl_0_1_0'], 'c4d17528-de5a-4e6e-9565-ad2d00fc0c6b' : ['gvQuestion_rbl_0_3_0'], 'cd1e7419-e5fb-49ee-b169-ad2d00fc0c6b' : ['191ee0f8-b7d9-4cac-8b47-ad2e00bf002a', 'ee9aaeeb-6697-442f-8a13-ad2e00bf002a'], 'fea3522a-2625-45d6-b8c1-ad2d01229e06' : ['gvQuestion_rbl_0_0_0'], '3834591e-f193-4f49-8166-ad2d01229e06' : ['gvQuestion_rbl_0_0_0'], 'ecabad40-9a14-4bb5-a0ee-ad2d01226753' : ['gvQuestion_rbl_0_0_0'], '7d2b66db-b46d-4ca7-a836-ad2d01229e06' : ['gvQuestion_rbl_0_1_0'], '3d3cc7d7-6f63-4f25-a9d8-ad2d01229e06' : ['gvQuestion_rbl_0_0_0'], '091759ca-1590-423c-9059-ad2d01229e06' : ['gvQuestion_rbl_0_0_0'], '9c25c406-fb9e-4f68-9f57-ad2d01229e06' : ['32bf0ffd-5fd7-4017-813b-ad2e00bb9efc', '6a3425da-c8c3-4cb6-94ec-ad2e00bb9efc'], 'd57589d2-5760-41c5-9c60-ad2d010257b7' : ['gvQuestion_rbl_0_0_0'], '1b998761-153a-4322-9d79-ad2d010257b7' : ['gvQuestion_rbl_0_1_0'], 'b8cf1e4f-45d9-479c-947a-ad2d010257b7' : ['gvQuestion_rbl_0_0_0'], '69546b9f-de6e-4d00-8c12-ad2d010257b7' : ['gvQuestion_rbl_0_0_0'], '5c82a9ac-840b-48f5-8c1a-ad2d010257b7' : ['gvQuestion_rbl_0_0_0'], '8baab50d-5f4e-4d96-a8a9-ad2d010257b7' : ['gvQuestion_rbl_0_0_0'], '174ca960-ea0e-4d12-a76b-ad2d010257b7' : ['7b305eb5-069d-4401-b1ca-ad2e00bbb251', '976b752e-9120-4c5d-99b8-ad2e00bbb251'], '76efd366-2b6d-4f69-9e96-ad2d00e8fd5e' : ['gvQuestion_rbl_0_0_0'], 'b13165db-3c4b-454e-a0c9-ad2d00fc0044' : ['gvQuestion_rbl_0_0_0'], // 2021年公需课:人工智能发展与产业应用 // '10a6800e-a299-4d6b-bfff-ad4201246c11' : '10a6800e-a299-4d6b-bfff-ad4201246c11' : ['b39ddc18-4760-43ec-b927-ad420119d5d3', '9c834d09-cd86-4d95-955c-ad420119d5d3', 'c13a4ace-054e-4268-ba0f-ad420119d5d3', '636f9f84-84b8-4d40-9701-ad420119d5d3'], 'fc517205-1bce-456d-97ff-ad4201246c11' : ['f5e7cdb7-8567-4a7c-bccc-ad420119ed6c', 'b5a1e1e7-d8e3-4dd4-a1b2-ad420119ed6c'], '9fb9a54c-1f79-4133-baa3-ad4201246c11' : ['1b7f4e63-12c1-4d20-b59f-ad42011a0228', '173a1ffd-9e2a-45fc-8e3e-ad42011a0228'], 'a6efe4a5-0c8c-4d65-ba17-ad4201246c11' : ['1d9f66b8-c995-4f4a-b9e7-ad42011a1cbb'], '9afc6815-935c-4fc5-83b9-ad4201246c11' : ['a7d3a93e-65f0-48d9-beb5-ad42011a356a', '4a35a4a5-b04b-4ac1-86a6-ad42011a356a', 'd9c8e888-f0bb-4788-bff8-ad42011a356a', '283ea1cc-b85c-4ee9-bc5f-ad42011a356a'], '60103e2d-4708-41f2-aedc-ad4201246c11' : ['229e3748-c0c9-411c-9b6e-ad42011a4be3', '61c831be-f950-4cbf-8618-ad42011a4be3'], '8962e670-1ca8-41a3-8ef5-ad4400965d0c' : ['782e6042-932b-4b29-9ba1-ad420118bc1b'], 'feda0e56-5bd7-42ed-a122-ad4300ade7dc' : ['gvQuestion_rbl_0_0_0'], 'bcc5a989-d837-4648-8798-ad4300ade7dc' : ['gvQuestion_rbl_0_0_0'], '4cd74e16-d8ec-452e-ad81-ad4300ade7dc' : ['5a95a7e1-0bce-40f5-8477-ad4300ab716a', 'fbd0d449-3b5d-4a7e-918e-ad4300ab716a'], 'd6e2cb17-d96d-4cf1-985c-ad4300ade7dc' : ['gvQuestion_rbl_0_1_0'], 'db973b6f-2938-47fa-b097-ad4300ade7dc' : ['gvQuestion_rbl_0_1_0'], '7f77df2c-fb90-473e-9aff-ad4300f36930' : ['gvQuestion_rbl_0_0_0'], '45fa76a0-f564-4ba3-aafc-ad4300f36930' : ['gvQuestion_rbl_0_0_0'], 'b6ad40bb-d638-4d1a-8c4f-ad4300f38e8c' : ['gvQuestion_rbl_0_0_0'], '53a447f5-29f7-4856-a84d-ad4300f38e8c' : ['gvQuestion_rbl_0_0_0'], 'ebcc3dd7-2324-4ef2-a3c8-ad4300f3b798' : ['gvQuestion_rbl_0_0_0'], '08f48580-5241-4e96-b16a-ad4300f3b798' : ['gvQuestion_rbl_0_0_0'], '9c66cde2-b872-4bfe-a53a-ad4300f3b798' : ['gvQuestion_rbl_0_0_0'], 'dde1ec63-96d8-4019-a3fa-ad43010fa3de' : ['gvQuestion_rbl_0_0_0'], '0c3a22e2-9de0-4b6e-8aa3-ad43010fa3de' : ['gvQuestion_rbl_0_0_0'], '9b1475bd-3439-4c05-a27e-ad43010fa3de' : ['gvQuestion_rbl_0_0_0'], 'c9946f00-5e9b-4bd9-9926-ad4400eee181' : ['gvQuestion_rbl_0_0_0'], 'a7e754d8-81e3-4b64-a613-ad4400ac1b63' : ['gvQuestion_rbl_0_0_0'], 'a8b3ff45-f512-4501-b7d7-ad4400ac1b63' : ['b141f1eb-d0ec-42b4-ae9d-ad4300a915c2', 'a5b349aa-8e67-4dc9-9a4f-ad4300a915c2'], 'd1ef7668-f65f-4dce-850f-ad4300b26568' : ['gvQuestion_rbl_0_0_0'], 'f35ce669-3cca-4f4c-9741-ad4300b26568' : ['gvQuestion_rbl_0_1_0'], '72a29604-de18-4235-baa8-ad4300b26568' : ['gvQuestion_rbl_0_0_0'], 'fd2c49f0-8881-4d26-a867-ad4300b30118' : ['gvQuestion_rbl_0_1_0'], 'af9b0742-d7da-427f-9261-ad4300b30118' : ['gvQuestion_rbl_0_0_0'], '60faac20-deed-424a-96bb-ad4300b30118' : ['gvQuestion_rbl_0_0_0'], '304aa47a-4eb6-469d-ae30-ad4300b30118' : ['7056439d-c579-413d-93c1-ad42010ed7c3', '816d6eb5-2d8f-43bb-9f7c-ad42010ed7c3'], '877082bc-56e6-4d1a-aef7-ad4300b30118' : ['gvQuestion_rbl_0_0_0'], '291910f7-39cc-4d82-9e12-ad4300b30118' : ['gvQuestion_rbl_0_0_0'], 'd8b1be7d-2d6a-40fd-a705-ad4400965d0c' : ['gvQuestion_rbl_0_1_0'], }; // intercept alert window if (getUrlParameter('cwid') || getUrlParameter('cid')) { let alrtScope; if (typeof unsafeWindow === "undefined") { alrtScope = window; } else { alrtScope = unsafeWindow; } alrtScope.alert = function (str) { console.log ("Greasemonkey intercepted alert: ", str); }; } if (window.top !== window.self) { return; } // 单个课程页面 if (window.location.pathname == '/course_ware/course_ware_polyv.aspx') { /* // 修改播放器init参数 倍速:'speed': true 可拖动'ban_seek': false let scriptIndex = 0; new MutationObserver(function(mutations) { // check at least two H1 exist using the extremely fast getElementsByTagName // which is faster than enumerating all the added nodes in mutations let scriptList = document.getElementsByTagName('script'); if (scriptList.length > 10) { this.disconnect(); // disconnect the observer } for (; scriptIndex < scriptList.length; scriptIndex++) { let scriptEle = scriptList[scriptIndex]; if (scriptEle.innerHTML && scriptEle.innerHTML.indexOf("'speed': false")) { scriptEle.innerHTML = scriptEle.innerHTML.replace("'speed': false", "'speed': true").replace("'ban_seek': banSeek", "'ban_seek': false"); console.log("REPLACE"); this.disconnect(); break; } } }).observe(document, {childList: true, subtree: true}); */ // 拦截first,不让加载视频中间的问题 let inter = setInterval(function() { try { if (first) { first = false; console.log("FIRST:", first); setInterval(inter); } } catch (err) { console.log(err); } }, 100); let initRateFlag = true; setInterval(async function() { if (!$("#jrks")[0].getAttribute('disabled')) { // finish lesson let cwid = getUrlParameter('cwid'); if (ANSWER_DICT[cwid]) { try { let content = await requestAsync($("#jrks")[0].href, {}); if (content.indexOf("请进行课件观看学习完成后再进行考试") != -1) { window.location.reload(); // 重听 } else { window.location = $("#jrks")[0].href; // 跳到考试 } } catch (err) { console.error(err); } } else { // jump to next await nextLesson(cwid); } } if (initRateFlag) { let rate = await GM.getValue('rate', 1); if (player) { player.changeRate(rate); initRateFlag = false; } } else { await GM.setValue('rate', player.currentRate); } }, 3000); } // 考试页面 if (window.location.pathname == '/pages/exam.aspx') { setInterval(async function() { let cwid = getUrlParameter('cwid'); console.log("CWID:", cwid); let answer = ANSWER_DICT[cwid]; if (answer) { for (let item of answer) { if (item.startsWith('gvQuestion')){ $('#' + item).click(); } else { $(`[value=${item}]`).click(); } } $('#btn_submit').click(); } }, 3000); } // 考试结果页面 if (window.location.pathname == '/pages/exam_result.aspx') { setInterval(async function() { let cwid = getUrlParameter('cwid'); await nextLesson(cwid); }, 3000); } // 目录页面 if (window.location.pathname == '/pages/course.aspx') { setInterval(async function() { // console.log("relocation: ", $(".course h3 a")[toStudyIndex].href); let hrefs = $(".course h3 a:first-child"); let vals = []; for (let i = 0; i < hrefs.length; i++) { // if (hrefs[i].children[0].src.endsWith("anniu_01a.gif")) { vals.push(hrefs[i].href); // } } // console.log(vals); await GM.setValue(cid, vals); await GM.setValue('cid', cid); }, 3000); } })();