// ==UserScript== // @name 浙里学习小助手 // @namespace https://bbs.tampermonkey.net.cn/ // @version 2.2 // @description 郑重声明:本脚本为学习油猴脚本编写使用,不得实际将其用于各类学习网站进行刷课行为,不得实际在网站上运行此代码,不得使用本脚本进行收付费活动 // @author yaxiyeye // @run-at document-start // @match https://www.zjce.gov.cn/* // @require https://scriptcat.org/lib/637/1.4.3/ajaxHooker.js // @require https://scriptcat.org/lib/1167/1.0.0/%E8%84%9A%E6%9C%AC%E7%8C%ABUI%E5%BA%93.js // @require https://scriptcat.org/lib/513/2.0.0/ElementGetter.js // @grant GM_xmlhttpRequest // @connect www.zjce.gov.cn // @connect oapi.dingtalk.com // @grant GM_setValue // @grant GM_getValue // ==/UserScript== (async function () { let user, address (window.unsafeWindow || window).CAT_UI = CAT_UI const learnstatus = GM_getValue('learnstatus') if (learnstatus == undefined) { GM_setValue('learnstatus', false) } function getUrlParams() { const urlParams = new URLSearchParams(window.location.search) const params = {} for (const [key, value] of urlParams.entries()) { params[key] = value } const regex = /\/([^/?]+)\?/ const match = window.location.href.match(regex) if (match && match[1]) { params["videoid"] = match[1] } return params } function gettoken() { let cookies = document.cookie function parseCookies() { let cookieObj = {} let cookiesArray = cookies.split(';') for (let i = 0; i < cookiesArray.length; i++) { let cookie = cookiesArray[i].trim() let [name, value] = cookie.split('=') cookieObj[name] = value } return cookieObj } let parsedCookies = parseCookies() return parsedCookies.portalToken } function getuser() { return new Promise(resolve => { const baseurl = "https://www.zjce.gov.cn/gateway/user/portal/sys/user/info" const timetemp = Date.now() let url = `${baseurl}?t=${timetemp}` const token = gettoken() const platform = GM_getValue("platform") const headers = { Accept: "application/json, text/plain, */*", "Accept-Encoding": "gzip, deflate, br, zstd", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", Authorization: token, Connection: "keep - alive", Cookie: document.cookie, Host: "www.zjce.gov.cn", Referer: "https://www.zjce.gov.cn/personalCenter/creditArchive", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0", platform: platform, "sec-ch-ua": '"Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24"', "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "Windows" } GM_xmlhttpRequest({ method: "GET", url: url, headers: headers, onload: function (response) { const data = JSON.parse(response.responseText) if (data.code === 401) { resolve(setTimeout(() => CAT_UI.Message.success(data.msg))) } else if (data.code === 0) { resolve(data.data) } } }) }) } function gettriantask() { return new Promise(resolve => { const baseurl = "https://www.zjce.gov.cn/gateway/resource/portal/userCode/trainCodeInfo" const timetemp = Date.now() let url = `${baseurl}?t=${timetemp}` const token = gettoken() const platform = GM_getValue("platform") const headers = { Accept: "application/json, text/plain, */*", "Accept-Encoding": "gzip, deflate, br, zstd", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", Authorization: token, Connection: "keep - alive", Cookie: document.cookie, Host: "www.zjce.gov.cn", Referer: "https://www.zjce.gov.cn/personalCenter/creditArchive", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0", platform: platform, "sec-ch-ua": '"Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24"', "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "Windows" } GM_xmlhttpRequest({ method: "GET", url: url, headers: headers, onload: function (response) { const data = JSON.parse(response.responseText) if (data.code === 401) { resolve(setTimeout(() => CAT_UI.Message.success(data.msg))) } else if (data.code === 0) { resolve(data.data) } } }) }) } function getTask(taskdata) { let tasknum = 0 let learnnum = 0 for (let i = 0; i < taskdata.codeRuleList.length; i++) { if (taskdata.codeRuleList[i].codeRule === '网络自学学时数') { const { examCreditStr, gainCredit } = taskdata.codeRuleList[i] tasknum = examCreditStr learnnum = gainCredit } } if (learnnum >= parseFloat(tasknum)) { return true } else { return false } } function getclasslist() { return new Promise((resolve, reject) => { const baseurl = "https://www.zjce.gov.cn/gateway/data/index/video/page?sort=DESC&page=1&limit=100" const timetemp = Date.now() let url = `${baseurl}&t=${timetemp}` const token = gettoken() const platform = GM_getValue("platform") const headers = { Accept: "application/json, text/plain, */*", "Accept-Encoding": "gzip, deflate, br, zstd", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", Authorization: token, Connection: "keep - alive", Cookie: document.cookie, Host: "www.zjce.gov.cn", Referer: "https://www.zjce.gov.cn/personalCenter/creditArchive", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0", platform: platform, "sec-ch-ua": '"Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24"', "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "Windows" } GM_xmlhttpRequest({ method: "GET", url: url, headers: headers, onload: function (response) { const data = JSON.parse(response.responseText) if (data.code === 401) { resolve(setTimeout(() => CAT_UI.Message.success(data.msg))) } else if (data.code === 0) { resolve(data.data) } } }) }) } async function opennewtab(classlist) { function getclassdata(url, headers, classuuid) { return new Promise((resolve, reject) => { GM_xmlhttpRequest({ method: "GET", url: url, headers: headers, onload: function (response) { const data = JSON.parse(response.responseText) const { videos } = data.data if (videos.length > 0) { for (let j = 0; j < videos.length; j++) { if (videos[j]?.progress === 100) { if (j === videos.length - 1) { resolve(false) } } else { const runurl = window.location.href if (runurl.indexOf('https://www.zjce.gov.cn/videos/detail') != 0) { window.open(`https://www.zjce.gov.cn/videos/detail/${classuuid}?bizType=1&playId=${videos[j]?.uuid}`, '_self') resolve("正在学习") break } } } } } }) }) } const { records } = classlist for (let i = 0; i < records.length; i++) { const classuuid = records[i].uuid const baseurl = `https://www.zjce.gov.cn/gateway/resource/portal/video/info/info?uuid=${classuuid}&bizType=1` const timetemp = Date.now() let url = `${baseurl}&t=${timetemp}` const token = gettoken() const platform = GM_getValue("platform") const headers = { Accept: "application/json, text/plain, */*", "Accept-Encoding": "gzip, deflate, br, zstd", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", Authorization: token, Connection: "keep - alive", Cookie: document.cookie, Host: "www.zjce.gov.cn", Referer: "https://www.zjce.gov.cn/personalCenter/creditArchive", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0", platform: platform, "sec-ch-ua": '"Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24"', "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "Windows" } const learn = await getclassdata(url, headers, classuuid) if (learn === "正在学习") { break } } } CAT_UI.createPanel({ appendStyle: `.arco-drawer-wrapper { position: fixed !important; }`, header: { title: CAT_UI.Space( [ CAT_UI.Icon.ScriptCat({ style: { width: "24px", verticalAlign: "middle" }, draggable: "false", }), CAT_UI.Text("浙里学习小助手", { style: { fontSize: "16px" }, }), ], { style: { marginLeft: "5px" } } ), style: { borderBottom: "1px solid var(--color-neutral-3)" }, }, render: DM, }) function DM() { const [visible, setVisible] = CAT_UI.useState(false) const [username, setusername] = CAT_UI.useState("") const [workaddress, setworkaddress] = CAT_UI.useState("") const [mubiao, setmubiao] = CAT_UI.useState("") const [yiwancheng, setyiwancheng] = CAT_UI.useState("") const [learnstatus, setlearnstatus] = CAT_UI.useState("") const [learntext, setlearntext] = CAT_UI.useState("") // let learnstatus = GM_getValue('learnstatus') CAT_UI.useEffect(() => { const ltext = GM_getValue('learnstatus') === false ? '开始学习' : '结束学习' setlearntext(ltext) const a = getuser().then(res => { setusername(res.userName) setworkaddress(res.unitPosition) user = res.userName address = res.unitPosition const b = gettriantask().then(resu => { let tasknum = 0 let learnnum = 0 for (let i = 0; i < resu.codeRuleList.length; i++) { if (resu.codeRuleList[i].codeRule === '网络自学学时数') { const { examCreditStr, gainCredit } = resu.codeRuleList[i] setmubiao(examCreditStr) setyiwancheng(gainCredit) tasknum = examCreditStr learnnum = gainCredit } } }).then(() => { const a = GM_getValue('learnstatus') if (a) { if (yiwancheng >= mubiao) { CAT_UI.Message.success(`学习完成!`) setlearntext('开始学习') GM_setValue('learnstatus', false) } else { setlearntext('结束学习') GM_setValue('learnstatus', true) main() } } }) }) }) return CAT_UI.Space([ CAT_UI.Text(`用户:${username}`, { style: { fontSize: "16px" }, }), // CAT_UI.Divider(null, { type: "horizontal" }), CAT_UI.Text(`单位:${workaddress}`, { style: { fontSize: "16px" }, }), CAT_UI.Text(`目标:${mubiao}`, { style: { fontSize: "16px" }, }), CAT_UI.Text(`当前:${yiwancheng}`, { style: { fontSize: "16px" }, }), CAT_UI.Text(`完成:${yiwancheng >= mubiao ? "已完成" : "未完成"}`, { style: { fontSize: "16px" }, }), CAT_UI.Button(learntext, { type: "primary", onClick: () => { if (GM_getValue('learnstatus') === true) { if (yiwancheng >= mubiao) { CAT_UI.Message.success(`学完了你还学什么?`) return } setlearntext('开始学习') GM_setValue('learnstatus', false) } else { setlearntext('结束学习') GM_setValue('learnstatus', true) main() } }, }), ], { direction: "vertical", }) } ajaxHooker.hook(request => { if (request.url.indexOf('https://www.zjce.gov.cn/gateway/resource/portal/pub/banner/list') != -1) { const header = request.headers const platform = header.platform GM_setValue('platform', platform) // setTimeout(() => CAT_UI.Message.success(`platform获取成功:${platform}`)) } }) async function main() { const runurl = window.location.href const userdata = await getuser() const { unitPosition, userName, uuid } = userdata const taskdata = await gettriantask() const isover = getTask(taskdata) const classlist = await getclasslist() opennewtab(classlist) } const runurl = window.location.href if (runurl.indexOf("https://www.zjce.gov.cn/videos/detail") == "0" && GM_getValue('learnstatus')) { function getVideoStatus(uuid, playid) { return new Promise(resolve => { const baseurl = "https://www.zjce.gov.cn/gateway/resource/portal/video/info/info" const timetemp = Date.now() let url = `${baseurl}?uuid=${uuid}&bizType=1&videoId=${playid}&t=${timetemp}` const token = gettoken() const platform = GM_getValue("platform") const headers = { Accept: "application/json, text/plain, */*", "Accept-Encoding": "gzip, deflate, br, zstd", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", Authorization: token, Connection: "keep - alive", Cookie: document.cookie, Host: "www.zjce.gov.cn", Referer: "https://www.zjce.gov.cn/personalCenter/creditArchive", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0", platform: platform, "sec-ch-ua": '"Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24"', "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "Windows" } GM_xmlhttpRequest({ method: "GET", url: url, headers: headers, onload: function (response) { const data = JSON.parse(response.responseText) if (data.code === 401) { resolve(setTimeout(() => CAT_UI.Message.success(data.msg))) } else if (data.code === 0) { resolve(data.data) } } }) }) } const videodiv = await elmGetter.get('video') const inter = setInterval(function () { videodiv.playbackRate = 1 videodiv.muted = true videodiv.play() }, 5000) const inter2 = setInterval(async function () { const params = getUrlParams() const videostatus = await getVideoStatus(params.videoid, params.playId) if (videostatus.progress === 100) { clearInterval(inter) clearInterval(inter2) window.open(`https://www.zjce.gov.cn/home`, '_self') } else { } }, 1000 * 60 * 10) const params = getUrlParams() const videostatus = await getVideoStatus(params.videoid, params.playId) videodiv.addEventListener("ended", async function () { const params = getUrlParams() const videostatus = await getVideoStatus(params.videoid, params.playId) if (videostatus.progress === 100) { clearInterval(inter) clearInterval(inter2) window.open(`https://www.zjce.gov.cn/home`, '_self') } else { videodiv.playbackRate = 1 videodiv.muted = true videodiv.play() } }, false) return } })()