// ==UserScript== // @name 英华网课课助手 // @namespace http://tampermonkey.net/ // @homepageURL https://greasyfork.org/zh-CN/scripts/427889-%E8%8B%B1%E5%8D%8E%E7%BD%91%E8%AF%BE%E8%AF%BE%E5%8A%A9%E6%89%8B // @version 0.2.3.Beta // @description 自动连播网课 // @author little3022 // @license GNU GPL v2.0 // @match *://mooc.yinghuaonline.com/user/node?* // @match *://mooc.yinghuaonline.com/* // @grant none // @downloadURL https://update.greasyfork.icu/scripts/427889/%E8%8B%B1%E5%8D%8E%E7%BD%91%E8%AF%BE%E8%AF%BE%E5%8A%A9%E6%89%8B.user.js // @updateURL https://update.greasyfork.icu/scripts/427889/%E8%8B%B1%E5%8D%8E%E7%BD%91%E8%AF%BE%E8%AF%BE%E5%8A%A9%E6%89%8B.meta.js // ==/UserScript== // 音效 var beepURL = "https://downsc.chinaz.net/Files/DownLoad/sound1/202103/14039.mp3"; class OcTip { /** * 类名: OcTip * 说明: 提示框类. 可同时显示一些顺序排列的提示框. * 初始化参数: * parent: 父元素 **/ constructor(parent) { this.parent = parent; this.HTML = document.createElement("div"); this.queue = []; this.mainTimer = 0; this.paused = false; this.mtID = null; this.init(); } init() { this.HTML.className = 'oc-container'; this.parent.appendChild(this.HTML); //绑定事件 this.HTML.onmouseover = () => {this.paused = true;}; this.HTML.onmouseleave = () => {this.paused = false;}; //添加公共样式 var elStyle = document.createElement("style"); elStyle.innerHTML = '.oc-container {z-index: 9999;position: relative;top: calc((100% - var(--height, 32px)) / 2);left: calc((100% - var(--width, 64px)) / 2);overflow: hidden;}.oc-tip {outline: 3px solid #ffff00;margin: 9px;border: 2px dashed #ffaa00;padding: 6px;background-color: #ffff00;overflow: hidden;transition: opacity 1s;}.oc-tip:hover {transition: opacity 0s;}.oc-tip .title,.oc-tip .content {margin: 0;vertical-align: middle;overflow: auto;}.oc-tip .title {overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}'; this.HTML.appendChild(elStyle); //设置主时钟 !this.mtID && (this.mtID = setInterval(() => { this._handleQueue(); //刷新大小及位置 { let maxWidth = parseInt(this.parent.offsetWidth * 0.8); let maxHeight = parseInt(this.parent.offsetHeight * 0.8); this.HTML.style.maxWidth = (maxWidth >= 64 ? maxWidth : 64) + 'px'; this.HTML.style.maxHeight = (maxHeight >= 64 ? maxHeight : 64) + 'px'; } this.HTML.style.setProperty("--width", this.HTML.offsetWidth + "px"); this.HTML.style.setProperty("--height", this.HTML.offsetHeight + "px"); //刷新时钟 (!this.paused) && (this.mainTimer += 100); }, 100)); } append(text, title = null, delay = 1200) { /** * 成员函数名: append() * 说明: 显示一个显示 3s 的提示性文本框, 可包含标题及文本. * 参数: * text: 显示文本 * title: 标题(默认不显示) **/ var elTip = document.createElement('div'); var elContent = document.createElement("p"); elTip.className = "oc-tip"; elContent.className = 'content'; //设置标题 if (title) { let elTitle = document.createElement("h3"); elTitle.className = 'title'; elTitle.innerHTML = title; elTitle.title = title; elTip.appendChild(elTitle); } //设置内容 elContent.innerHTML = text; elContent.title = text; elTip.appendChild(elContent); //添加悬停事件 elTip.onmouseover = () => {elTip.style.opacity = 1;}; this._insertQueue(elTip, delay); return true; } destroy() { /** * 成员函数名: destroy() * 说明: 清除成员内容, 释放内存. * 参数: * parent: 父元素 * text: 显示文本 * title: 标题(默认不显示) **/ this.HTML && this.parent.removeChild(this.HTML); this.HTML = null; this.queue = []; this.mtID && clearInterval(this.mtID); return true; } _insertQueue(elTip, duration) { duration = parseInt(duration / 100) * 100; this.queue.push({ inTime: this.mainTimer, outTime: this.mainTimer + duration, display: false, elTip: elTip }); } _handleQueue() { this.queue.forEach((obj, index, queue) => { if(!obj.display && obj.inTime >= this.mainTimer) { this.HTML.appendChild(obj.elTip); obj.display = true; } else if(obj.display && this.mainTimer == obj.outTime) { //淡出效果 obj.elTip.style.opacity = 0; } else if(obj.display && this.mainTimer >= obj.outTime + 1000) { this.HTML.removeChild(obj.elTip); obj.display = false; obj.elTip = null; queue.splice(index, 1); } }); } } class Course { constructor(courseId) { this.prefixURL1 = 'https://mooc.yinghuaonline.com'; this.prefixURL2 = 'https://mooc.yinghuaonline.com/user/study_record.json?courseId='; this.index = -1; //本视频索引 this.nodeId = ""; this.chapterId = ""; this.courseId = courseId; this.title = ""; //课程名 this.name = ""; //json 视频名 this.viewCount = 0; //json 观看次数 this.duration = 0; //json 视频播放时长 this.videoDuration = 0; //json 视频总时长 this.state = ""; this.finished = false; //是否完成播放 this.url = ""; //json 本页面地址 this.pageInfo = { keyName: null, page: -1, pageCount: -1, recordsCount: -1, onlyCount: -1, pageSize: -1 } this.errCode = 0; this.errMsg = ""; this._urls = []; //本次所有视频 HTML a 对象 this._json = null; //请求的课程 json this._tID = Math.floor(Math.random() * (1622097000000 - 1622097888888)) + 1622097000000; //请求 json 所用 ID this.init(); } init() { //单独获取标题 this.title = document.querySelector('#wrapper > div.curPlace > div.center > a:nth-child(3)').innerText; this.parseIndex(); this.requireJson(); this._updateProperty(); } parseIndex() { //分析当前视频索引 if(this.index != -1) return; //解析本地 HTML 列表 var obj = document.querySelectorAll("div.nwrap > div > div.detmain-navs > div.detmain-navlist > div.group.two > div.list > div > a"); for(let [k, v] of obj.entries()) { if(/.*章.*测.*/.test(v.innerText)) continue; else { v.href = `https://mooc.yinghuaonline.com/user/node?courseId=${this.courseId}&chapterId=${this.chapterId}&nodeId=${/nodeId=(\d+)/.exec(v.href)[1]}`; this._urls.push(v); } } //获取视频索引 for(let i = 0; i < this._urls.length; i++) { if(this._urls[i].className == "on") { this.index = i; return i; } } this.index = -1; return -1; } requireJson() { //请求视频列表 var xhttp = new XMLHttpRequest(); var page = 0; page = parseInt((this.index + 20) / 20); xhttp.onreadystatechange = () => { if(xhttp.readyState == 4 && xhttp.status == 200) { this._json = JSON.parse(xhttp.response); } else if(xhttp.readyState == 4 && xhttp.status == 0) { this.errorCode = 404; if(this._json.status && this._json.status == false) { this.errorMsg = `Error: [${this.errorCode}] ${JSON.parse(xhttp.response).msg}`; } else { this.errorMsg = `Error: [${this.errorCode}] 课程信息请求失败!}`; } } }; xhttp.open("GET", this.prefixURL2 + this.courseId + "&page=" + page + "&_=" + this._tID++, false); xhttp.send(); return this._json; } refresh() { //刷新当前课程信息 var json = null; if(this.parseIndex() != -1 && this.requireJson()) { this._updateProperty(); return true; } else { return false; } } _updateProperty() { //设置属性 this.id = this._json.list[this.index % 20].id; this.chapterId = this._json.list[this.index % 20].chapterId; this.courseId = this._json.list[this.index % 20].courseId; this.name = this._json.list[this.index % 20].name; this.viewCount = parseInt(this._json.list[this.index % 20].viewCount); this.duration = parseInt(this._json.list[this.index % 20].duration); this.videoDuration = parseSec(this._json.list[this.index % 20].videoDuration); this.state = /(未学完|未学|已学)/.exec(this._json.list[this.index % 20].state)[0]; if(this.state == "已学") this.finished = true; this.url = this.prefixURL1 + this._json.list[this.index % 20].url; this.pageInfo = this._json.pageInfo; // 保存 json 至本地(SKM_courseId_page_recordsCount_pageSize) writeSessionStorage(`SKM_${this.courseId}_${this._json.pageInfo.page}_${this._json.pageInfo.recordsCount}_${this._json.pageInfo.pageSize}`, JSON.stringify(this._json), true); } } class YHAssistant { constructor() { this.HTML = document.createElement("div"); this.baseInfo = null; this.mainTimer = 0; //主时钟 this.currentDuration = -1; //观看时长 this.countdown = -1; //倒计时 this.course = null; //自定义课程对象 this.elTable = null; //HTML 表格对象 this.video = null; //HTML 视频对象 this.autoplay = true; this.onduty = false; //是否值守 this.ocTip = null; this._timer1 = 0; //值守计时器 this._timer2 = 0; //播放时长计时器(非Interval) this._mtID = null; //主时钟 ID this._tID1 = null; //值守计时器 ID this._fg1 = false; //已切换背景 this._fg2 = false; //倒计时为 0 this._fg3 = false; //暂停计时 this._pageOther = false; //是否为其他页面 if(/\w+:\/\/mooc\.yinghuaonline\.com\/user\/node\?\S+/.exec(location.href)) this.init(); else { this.initOther(); this._pageOther = true; } } init() { //播放界面初始化 var elStyle = null; //添加 innerHTML this.HTML.className = "YHAssistant"; this.HTML.innerHTML += '

Title

Name

观看次数 Data
观看时长 Data
视频时长 Data
剩余时长 Data
状态 Data
计时 Data

注:在刚开始播放视频时请激活该页面,否则将导致计时系统失效。

'; //添加样式 elStyle = document.createElement("style"); elStyle.innerHTML = ':root {--root-width: 230px;--root-height: 325px;}.YHAssistant {z-index: 999;position: fixed;top: 30%;left: 5px;width: 50px;height: 50px;font-size: 16px;color: black;background-color: gainsboro;transition: width .5s ease, height .5s ease;overflow: hidden;}.YHAssistant h3,.YHAssistant h4,.YHAssistant p {margin: 0;}.YHAssistant:hover {width: var(--root-width);height: var(--root-height);}.YHAssistant>.titlebar {position: relative;top: 0;left: 0;}.YHAssistant:hover .bt-menu {top: 0;left: 0;}.YHAssistant:hover .label-title {visibility: visible;}.YHAssistant:hover .menu-container {visibility: visible;}.YHAssistant:hover .info {visibility: visible;}.titlebar>.bt-menu {position: absolute;top: 6px;left: 6px;margin: 3px;width: 32px;height: 32px;vertical-align: middle;fill: currentcolor;overflow: hidden;--darkreader-inline-fill: currentcolor;transition: .2s ease;}.titlebar>.label-title {position: absolute;top: 3px;left: 42px;width: calc(100% - 110px);line-height: 32px;overflow: hidden;visibility: hidden;}.titlebar>.label-title h3 {overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}.menu-container {position: absolute;top: 6px;border-radius: 3px;padding: 3px;width: 24px;height: 24px;text-align: center;vertical-align: middle;visibility: hidden;}.menu-container:hover {background-color: rgba(128, 128, 128, 0.3);}.menu-container .bt-refresh,.menu-container .bt-audio {vertical-align: middle;fill: currentcolor;overflow: hidden;--darkreader-inline-fill: currentcolor;}.menu-container .bt-audio.true {display: none;}@keyframes rotate {from {-webkit-transform: rotate(0deg);}to {-webkit-transform: rotate(360deg);}}.menu-container:hover .bt-refresh svg {animation: rotate 2s linear infinite backwards;}.YHAssistant .info {position: relative;top: 32px;visibility: hidden;}.info .table {position: absolute;top: 15px;left: 10px;width: calc(var(--root-width) - 20px);}.info .table caption {height: 30px;}.info .table h4 {width: calc(var(--root-width) - 56px);overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}.info .table td {text-align: center;}.info .discription {position: absolute;top: 195px;left: 10px;box-sizing: content-box;border: 1px dashed red;padding: 8px;width: calc(var(--root-width) - 38px);color: #bc2352;background-color: #ecb6c5;text-decoration:line-through;overflow: hidden;opacity: 0.8;}'; this.HTML.appendChild(elStyle); //获得表格对象 this.elTable = this.HTML.querySelector("div.info > table"); //获得视频对象 this.video = document.getElementsByTagName('video')[0]; this.video.muted = true; this.video.volume = 0.3; this._bindVideoEvent(); //初始化基本信息 this.baseInfo = parseBaseInfo(); //绑定菜单按钮 this.bindBtMenu(); //绑定值守事件 this._bindOnDuty(); //绑定移动事件 bindMover(this.HTML); //初始化提示类 this.ocTip = new OcTip(this.HTML); } initOther() { //其他界面初始化 var elStyle = null; var elTitle = null; //添加 innerHTML this.HTML.className = "YHAssistant"; this.HTML.innerHTML += '

Title

Name

观看次数 Data
观看时长 Data
视频时长 Data
剩余时长 Data
状态 Data
计时 Data

注:在刚开始播放视频时请激活该页面,否则将导致计时系统失效。

'; //添加样式 elStyle = document.createElement("style"); elStyle.innerHTML = ':root {--root-width: 230px;--root-height: 325px;}.YHAssistant {z-index: 999;position: fixed;top: 30%;left: 5px;width: 50px;height: 50px;font-size: 16px;color: black;background-color: gainsboro;transition: width .5s ease, height .5s ease;overflow: hidden;}.YHAssistant h3,.YHAssistant h4,.YHAssistant p {margin: 0;}.YHAssistant:hover {width: var(--root-width);height: var(--root-height);}.YHAssistant>.titlebar {position: relative;top: 0;left: 0;}.YHAssistant:hover .bt-menu {top: 0;left: 0;}.YHAssistant:hover .label-title {visibility: visible;}.YHAssistant:hover .menu-container {visibility: visible;}.YHAssistant:hover .info {visibility: visible;}.titlebar>.bt-menu {position: absolute;top: 6px;left: 6px;margin: 3px;width: 32px;height: 32px;vertical-align: middle;fill: currentcolor;overflow: hidden;--darkreader-inline-fill: currentcolor;transition: .2s ease;}.titlebar>.label-title {position: absolute;top: 3px;left: 42px;width: calc(100% - 110px);line-height: 32px;overflow: hidden;visibility: hidden;}.titlebar>.label-title h3 {overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}.menu-container {position: absolute;top: 6px;border-radius: 3px;padding: 3px;width: 24px;height: 24px;text-align: center;vertical-align: middle;visibility: hidden;}.menu-container:hover {background-color: rgba(128, 128, 128, 0.3);}.menu-container .bt-refresh,.menu-container .bt-audio {vertical-align: middle;fill: currentcolor;overflow: hidden;--darkreader-inline-fill: currentcolor;}.menu-container .bt-audio.true {display: none;}@keyframes rotate {from {-webkit-transform: rotate(0deg);}to {-webkit-transform: rotate(360deg);}}.menu-container:hover .bt-refresh svg {animation: rotate 2s linear infinite backwards;}.YHAssistant .info {position: relative;top: 32px;visibility: hidden;}.info .table {position: absolute;top: 15px;left: 10px;width: calc(var(--root-width) - 20px);}.info .table caption {height: 30px;}.info .table h4 {width: calc(var(--root-width) - 56px);overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}.info .table td {text-align: center;}.info .discription {position: absolute;top: 195px;left: 10px;box-sizing: content-box;border: 1px dashed red;padding: 8px;width: calc(var(--root-width) - 38px);color: #bc2352;background-color: #ecb6c5;overflow: hidden;opacity: 0.8;}'; this.HTML.appendChild(elStyle); //获得表格对象 this.elTable = this.HTML.querySelector("div.info > table"); //初始化基本信息 this.baseInfo = parseBaseInfo(); //绑定移动事件 bindMover(this.HTML); //刷新课程名 elTitle = this.HTML.querySelector("div.titlebar > div > h3"); elTitle.innerText = document.querySelector('div.wrapper > div.nwrap > div > div.stuelearn-swrapper > div.stuelearn-intro > div.title').innerText.substr(5); elTitle.title = elTitle.innerText; //刷新视频名 this.elTable.caption.innerHTML = `

${null}

`; //刷新状态 this.elTable.rows[4].cells[1].innerText = '该页面不可用'; } refreshUI() { //刷新整个UI var elTitle = null; //刷新课程名 elTitle = this.HTML.querySelector("div.titlebar > div > h3"); elTitle.innerText = this.course.title; elTitle.title = this.course.title; //刷新视频名 this.elTable.caption.innerHTML = `

${this.course.name}

`; this.elTable.caption.title = this.course.name; //刷新观看次数 this.elTable.rows[0].cells[1].innerText = this.course.viewCount + 1; //刷新观看时长 this.currentDuration = this.course.duration; this.elTable.rows[1].cells[1].innerText = this.currentDuration + " s"; //刷新视频时长 this.elTable.rows[2].cells[1].innerText = this.course.videoDuration + " s"; //刷新剩余时长 this.countdown = this.course.videoDuration - this.currentDuration; (this.countdown > 0)? 1: this.countdown = 0; this.elTable.rows[3].cells[1].innerText = this.countdown + ' s'; //刷新状态 this.elTable.rows[4].cells[1].innerText = this.course.state; } _refreshTimer() { //计时并显示 //刷新观看时长 this.elTable.rows[1].cells[1].innerText = ++this.currentDuration + " s"; //刷新剩余时长 this.countdown = this.course.videoDuration - this.currentDuration; (this.countdown > 0)? 1: this.countdown = 0; this.elTable.rows[3].cells[1].innerText = this.countdown + ' s'; } _setBG() { //完成后设置背景色为绿色 if(!this._fg1 && this.course.finished) { this.HTML.style.backgroundColor = "mediumseagreen"; this._fg1 = true; } } bindBtMenu() { //绑定菜单按钮事件 var btAudioFalse = this.HTML.querySelector('div.titlebar > div:nth-child(3) > span.bt-audio.false'); var btAudioTrue = this.HTML.querySelector('div.titlebar > div:nth-child(3) > span.bt-audio.true'); var btRefresh = this.HTML.querySelector('div.titlebar > div:nth-child(4) > span.bt-refresh'); //绑定刷新按钮 btRefresh.onclick = () => { //请求数据 if(this.course.refresh()) { this.ocTip.append("刷新成功"); //更新显示 this.refreshUI(); this.course.finished && this.next(); //设置时间并播放 this.video.currentTime = this.course.duration; this.video.play(); } else { this.ocTip.append(`刷新失败, 错误码[${this.course.errCode}],
信息: ${this.course.errMsg}.`); } }; //绑定静音按钮 btAudioFalse.onclick = () => { btAudioFalse.style.display = 'none'; btAudioTrue.style.display = 'block'; this.video.muted = false; this.ocTip.append('已取消静音'); } btAudioTrue.onclick = () => { btAudioTrue.style.display = 'none'; btAudioFalse.style.display = 'block'; this.video.muted = true; this.ocTip.append("已静音."); } } _bindOnDuty() { //绑定值守事件 //执行值守时钟 !this._tID1 && (this._tID1 = setInterval(() => { this._timer1++; (this._timer1 >= 5) && (this.onduty = false); }, 1000)); //定义鼠标移动事件 document.body.onmousemove = () => { this.onduty = true; this._timer1 = 0; }; } _bindVideoEvent() { //绑定视频事件 this.video.ontimeupdate = () => { //视频播放时间改变 if(this._timer2 != parseInt(this.video.currentTime)) { //经过 1s this._timer2 = parseInt(this.video.currentTime); //刷新计时 this._refreshTimer(); if(!this._fg2 && this.countdown == 0) { //倒计时为 0 判断是否完成 this.fg2 = true; this.refreshUI(); if(this.course.refresh() && this.course.finished) { this.next(); } else { //设置时间并播放 this.video.currentTime = this.course.duration; this.video.play(); this._fg2 = false; } } } }; this.video.addEventListener('pause', () => { //视频播放暂停 var popup = document.querySelector('div.layui-layer'); if(popup && popup.querySelector('div.layui-layer-btn a').innerText == "开始播放") { //输入验证码 popup.querySelector('div.layui-layer-btn a').onclick = () => { //点击确认 if(!this.video.paused) { //验证成功 document.body.removeChild(popup); } }; !this.onduty && playBeep(); } else if(popup) { //时长上传失败 var shade = document.querySelector('div.layui-layer-shade'); shade && document.body.removeChild(shade); document.body.removeChild(popup); this.video.play(); setTimeout(()=>{this.video.paused && !this.onduty && playBeep();}, 5000); } }); this.video.addEventListener('ended', () => { //视频播放结束 if(this.course && this.course.refresh() && this.course.finished) { this.next(); } else { this.refreshUI(); this.video.currentTime = this.course.duration; this.video.play(); } }); } next() { //切换下一个 this.course && this.course._urls[this.course.index + 1].click(); } jumpNext() { //跳转至下一个未完成页面 for(let obj of this.course._json.list) { //遍历当前页状态 if(/(未学完|未学|已学)/.exec(obj.state)[0] != '已学') { let url = this.course.prefixURL1 + obj.url; location.replace(url); return true; } } //已完成当前页所有视频 if(this.course.pageInfo.page == this.course.pageInfo.pageCount) { //已完成所有视频 alert('恭喜, 您已看完所有视频啦, 再接再厉!'); } else { //播放下页首个视频 this.course._urls[this.course.pageInfo.page * this.course.pageInfo.pageSize + 1].click(); } } show() { document.body.appendChild(this.HTML); } exec() { if(this._pageOther) { this._exec(); return true; } //启动主时钟 !this._mtID && (this._mtID = setInterval(() => { //更新计时器 this.mainTimer++; this.elTable.rows[5].cells[1].innerText = `${this.mainTimer} s`; //设置背景 this._setBG() //离开前 5 秒, 每 2 秒播放提示音 !this.onduty && this._timer1 < 10 && (this._timer1 % 2 != 0) && this.video.paused && playBeep(); //离开 15-60 秒, 每 5 秒播放提示音 this._timer1 >= 15 && this._timer1 < 60 && (this._timer1 % 5 == 0) && this.video.paused && playBeep(); }, 1000)); //初始化课程对象并刷新显示 if(this.baseInfo) this.course = new Course(this.baseInfo.courseId); else alert('课程 ID 获取失败, 请重试!'); this.refreshUI(); //是否已完成 if(this.course.finished && this.autoplay) { //该视频已完成 this.jumpNext(); return true; } else if(this.course.finished && !this.autoplay) { if(confirm('恭喜, 您已经看完成这个视频了, 点击"确定"跳转至下一视频!')) { //确定 this.jumpNext() return true; } } //是否自动播放 this.autoplay && this.video.play(); return true; } _exec() { } } function parseBaseInfo() { //初始化时获得临时信息 if(!readSessionStorage('baseInfo')) { const [, courseId, , chapterId] = location.search.substr(1).split(/[=&]/); const baseInfo = {courseId, chapterId}; if(!writeSessionStorage('baseInfo', JSON.stringify(baseInfo))) return false; } return JSON.parse(sessionStorage.baseInfo); } function playBeep() { var beep = document.createElement("audio"); beep.src = beepURL; beep.play() delete beep; } function readSessionStorage(key, displace=null) { if(sessionStorage.getItem(key)) { return sessionStorage.getItem(key); } else { return displace; } } function writeSessionStorage(key, value, cover=false) { if(!sessionStorage.getItem(key) || cover) { sessionStorage.setItem(key, value); return true; } return false; } function bindMover(el) { el.onmousedown = (e) => { let disX = e.clientX - el.offsetLeft; let disY = e.clientY - el.offsetTop; document.onmousemove = function(e) { let tX = e.clientX - disX; let tY = e.clientY - disY; if (tX >= 0 && tX <= window.innerWidth - el.offsetWidth) { el.style.left = tX + 'px'; } if (tY >= 0 && tY <= window.innerHeight - el.offsetHeight) { el.style.top = tY + 'px'; } }; document.onmouseup = function(e) { document.onmousemove = null; document.onmouseup = null; }; } } function waitingUntil(call, judge=false, sensitivity=250) { if(!judge) { setTimeout(call, sensitivity); } else { waitingUntil(call, judge, sensitivity); } } function parseSec(time="") { /** * 函数名: parseSec() * 说明: 把时间格式的字符串转换为秒数.*/ let sec = 0; if(time != "" && !isNaN(Date.parse("1970-1-1 " + time))) { //判断是否是时间格式 let t = time.split(":"); sec += parseInt(t[0]) * 3600 + parseInt(t[1]) * 60 + parseInt(t[2]); } else return -1; return sec; } function formatSec(sec) { /** * 函数名: formateSec() * 说明: 把秒数转换为时间格式的字符串.*/ return (new Date(sec * 1000).toTimeString().slice(0, 8)); } (function() { 'use strict'; $(document).ready(function() { window.yha = new YHAssistant(); window.yha.show(); window.yha.exec(); }); })();