// ==UserScript== // @name 青书网课视频-穿透iframe自动重播 // @namespace https://scriptcat.org/ // @version 1.1 // @description 穿透iframe,定时检测视频,播放完毕自动重播 // @author Me // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; // 查找所有video,包括iframe内 function getAllVideos() { let videos = Array.from(document.querySelectorAll('video')); // 遍历iframe const iframes = document.querySelectorAll('iframe'); for(let iframe of iframes){ try{ const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; const iframeVideos = iframeDoc.querySelectorAll('video'); videos = videos.concat(Array.from(iframeVideos)); }catch(e){ //跨域iframe无法读取,跳过 } } return videos; } // 检测+重播逻辑 function checkAndLoopVideo(){ const videos = getAllVideos(); videos.forEach(video=>{ if(!video) return; // 判断:播放到最后1秒内 if (!video.paused && video.currentTime >= video.duration - 1) { console.log("视频播放结束,准备重播"); video.currentTime = 0; video.play().catch(err=>{ console.log("重播失败", err); }); } }) } // 每500毫秒检测一次 setInterval(checkAndLoopVideo, 500); })();