hnkfdx
// ==UserScript==// @name autoplay-kfdx// @namespace http://tampermonkey.net/// @version 0.1// @description hnkfdx// @author qiu6406,guaxiangdeba// @match http://www.hnsydwpx.cn/*// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js// @icon https://www.google.com/s2/favicons?domain=ischinese.cn// @grant GM_addStyle// @grant GM_setValue// @grant GM_getValue// ==/UserScript==var sections = document.getElementsByClassName("sectionNum");var items = document.getElementsByClassName("buyCourse_itemMain")var cursec = 0;var txt;var study_css = ".egg_study_btn{outline:0;border:0;position:fixed;top:5px;left:5px;padding:12px 20px;border-radius:10px;cursor:pointer;background-color:#fff;color:#d90609;font-size:18px;font-weight:bold;text-align:center;box-shadow:0 0 9px #666777}.egg_manual_btn{transition:0.5s;outline:none;border:none;padding:12px 20px;border-radius:10px;cursor:pointer;background-color:#e3484b;color:rgb(255,255,255);font-size:18px;font-weight:bold;text-align:center;}.egg_auto_btn{transition:0.5s;outline:none;border:none;padding:12px 20px;border-radius:10px;cursor:pointer;background-color:#666777;color:rgb(255,255,255);font-size:18px;font-weight:bold;text-align:center;}.egg_setting_box{position:fixed;top:70px;left:5px;padding:12px 20px;border-radius:10px;background-color:#fff;box-shadow:0 0 9px #666777}.egg_setting_item{margin-top:5px;height:30px;width:140px;font-size:16px;display:flex;justify-items:center;justify-content:space-between}input[type='checkbox'].egg_setting_switch{cursor:pointer;margin:0;outline:0;appearance:none;-webkit-appearance:none;-moz-appearance:none;position:relative;width:40px;height:22px;background:#ccc;border-radius:50px;transition:border-color .3s,background-color .3s}input[type='checkbox'].egg_setting_switch::after{content:'';display:inline-block;width:1rem;height:1rem;border-radius:50%;background:#fff;box-shadow:0,0,2px,#999;transition:.4s;top:3px;position:absolute;left:3px}input[type='checkbox'].egg_setting_switch:checked{background:#fd5052}input[type='checkbox'].egg_setting_switch:checked::after{content:'';position:absolute;left:55%;top:3px}";GM_addStyle(study_css);//页面判断function checkUrl() {if (window.location.href.indexOf('center.html') > 0) {//课程页面console.log("首页");return 1;} else if (window.location.href.indexOf('course.html') > 0) {//课程列表页面console.log("列表页面");return 2;} else if (window.location.href.indexOf('getcourseDetails') > 0) {//播放详情页面console.log("播放详情页面 ");return 3;} else if (window.location.href.indexOf('play.html') > 0) {//播放详情页面console.log("课程页面 ");return 4;} else {return -1;}}//获取课程位置并跳转function getPlayItem() {console.log($(".classItem button").length);if($(".classItem button").length){console.log('点击开始学习');if($(".percent span")[0].innerHTML=='100%'){ $(".classItem button")[1].click();}else{$(".classItem button")[0].click()}}}//等待播放完成function waitingClose() {return new Promise( resolve => {let doing = setInterval(function(){console.log( $("#progressshow")[0].innerText );window.scroll({top: Math.random()*500,behavior: 'smooth'});if( $("#progressshow")[0].innerText == '100%' ){clearInterval(doing);resolve('本课学习完成')}},180000)})}//点击开始学习function check() {if(GM_getValue("start")){let i = 0;for(i ; i < $(".progressNum").length ; i++ ){if( $(".progressNum")[i].innerText == '100%' ) continue;console.log("第"+i+"节学习"+$(".progressNum")[i].innerText);$(".classItem")[i].childNodes[3].click();break;}}}//添加控制按钮function addButton(){var button = document.createElement("button"); //创建一个提示框按钮button.id = "id001";GM_getValue("start") == 1 ?button.textContent = "正在自动学习!" : button.textContent = "开始学习";button.className = "egg_study_btn egg_menu";button.onclick = function (){if ( button.textContent == "开始学习") {button.textContent = "正在自动学习!";GM_setValue("start",1);if( checkUrl() == 1 ){window.location.href='http://www.hnsydwpx.cn/template/center/course/course.html';}} else {button.textContent = "开始学习";GM_setValue("start",0);}}var x = document.getElementsByTagName("body")[0];x.append(button);}//初始化async function init() {switch (checkUrl()) {case -1:console.log("未找到正确页面");break;case 1://首页addButton();if( GM_getValue("start") ){window.location.href='http://www.hnsydwpx.cn/template/center/course/course.html';}break;case 2://列表页面addButton();if( GM_getValue("start") ){setInterval(getPlayItem,1000);}break;case 3://播放详情addButton();await waitingClose();$('#TnavUlId li')[7].click();break;case 4://课程页面addButton();setInterval(check,1000);break;}}window.onload = (event) => {init();};///template/center/course/course.html