// ==UserScript== // @name 基金业协会视频自动播放 // @namespace https://www.nekotofu.top/ // @homepage https://www.nekotofu.top/ // @version 0.8 // @description 基金业协会视频自动下一个,但题目目前需要自己答。 // @author misaka10032w // @match *://peixun.amac.org.cn/* // @icon https://www.google.com/s2/favicons?sz=64&domain=microsoft.com // @license MIT // @grant none // @downloadURL none // ==/UserScript== (function () { 'use strict'; window.onload = function () { console.log("DOM已加载!"); window.addEventListener('blur', function () { window.onblur = {} }, false); function closePopup() { const pop = document.querySelector(".class_float"); if (pop.style.display != "none") { var close = pop.getElementsByClassName("btn-close")[0] close.click(); } } function sendNotification(title, content) { if (!("Notification" in window)) { console.log("浏览器不支持通知"); return; } if (Notification.permission !== "granted") { Notification.requestPermission().then(function (permission) { if (permission === "granted") { showNotification(); } else { console.log("用户拒绝了通知权限"); } }); } else { showNotification(); } function showNotification() { const notification = new Notification(title, { body: content, }); notification.onclick = function () { // 在这里添加点击通知后的操作 console.log("用户点击了通知"); }; } } let nowPlaying; function getCourse() { const courseList = document.querySelectorAll(".catalog-content a"); for (let i = 0; i < courseList.length; i++) { if (!courseList[i].classList.contains("studied") && !courseList[i].classList.contains("test")&& !courseList[i].classList.contains("testRev")&& !courseList[i].classList.contains("testScore")) { console.log("存在未播放的项,播放列表未完成") nowPlaying = courseList[i]; console.log(nowPlaying.textContent) if (!nowPlaying.classList.contains("cur")) { console.log("当前视频已播放完毕"); nowPlaying.click(); } return nowPlaying; } } // 所有项都已经播放,播放列表已完成 return false; } if(document.querySelectorAll(".catalog-content a").length!=0){ nowPlaying = getCourse(); if (!nowPlaying) { console.log("课程列表播放完毕") sendNotification("当前课程播放完毕!", "当前课程列表播放完毕,请切换下一个播放列表") return true } const player = document.querySelector("video"); setTimeout(() => { player.muted = true; player.play(); }, 2000) player.addEventListener("play", function () { console.log("视频开始播放"); }) player.addEventListener("pause", function () { console.log("视频暂停"); setTimeout(() => { player.play(); }, 2000) }) player.addEventListener("ended", function () { console.log("视频播放结束"); }); player.addEventListener("timeupdate", function () { const currentTime = player.currentTime.toFixed(0); const duration = player.duration.toFixed(0); console.log(`当前时间: ${currentTime} / 总时长: ${duration}`); if (currentTime == duration && nowPlaying) { setTimeout(() => { closePopup(); nowPlaying = getCourse(); if (!nowPlaying) { console.log("课程列表播放完毕!") sendNotification("当前课程播放完毕!", "当前课程列表播放完毕,请切换下一个播放列表") return true } nowPlaying.click(); }, 5000); } else if (currentTime != currentTime && player.paused) { player.play(); } }) } }; })();