// ==UserScript== // @name 基金业协会视频自动播放 // @namespace https://www.nekotofu.top/ // @homepage https://www.nekotofu.top/ // @version 0.9 // @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'; function observeDOM(callback) { const observer = new MutationObserver((mutationsList, observer) => { for (const mutation of mutationsList) { if (mutation.type === 'childList' || mutation.type === 'subtree') { var player = document.getElementsByTagName("video")[0]; if (player) { player.addEventListener('blur', function () { window.onblur = {} }, false); observer.disconnect(); // Stop observing once the element is found and listener is added break; } } } }); observer.observe(document.body, { childList: true, subtree: true }); } observeDOM(); 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("用户点击了通知"); }; } } sendNotification("授予通知权限") 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 } var iframe = document.querySelector('iframe'); // 定期检查 iframe 内部文档中的元素是否存在 let checkInterval = setInterval(function() { iframe = document.querySelector('iframe'); console.log(100) if(iframe){ let iframeDocument = iframe.contentDocument || iframe.contentWindow.document; let player = iframeDocument.getElementsByTagName("video")[0]; console.log('Element found:', player); // 在找到目标元素后,清除定时器 clearInterval(checkInterval); // 在此处添加你需要对目标元素进行的操作 player.muted = true; player.play(); 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(); } }) } }, 500); // 每500毫秒检查一次 if(0){ } } })();