有iframe界面的自动下一集
测试页面
https://www.qiju.cc/vod/play/id/356/sid/2/nid/1.html
JavaScript
下面是油猴代码,方法一采用延时器
// ==UserScript==
// @name 有iframe界面的自动下一集
// @namespace http://tampermonkey.net/
// @version 2024-11-15
// @description try to take over the world!
// @author You
// @match https://www.qiju.cc/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=qiju.cc
// @grant none
// ==/UserScript==
(function() {
'use strict';
setTimeout(function () {
let video = document.querySelectorAll('iframe')[2].contentWindow.document.querySelector('video');
video.addEventListener('ended', () => {
let 当前播放集 = document.querySelector('.box.border.on.ecnav-dt')
if (当前播放集.nextElementSibling) {
当前播放集.nextElementSibling.firstElementChild.click()
}
})
}, 5000)
})();
下面是方法二,检测iframe加载完成后
JavaScript
// ==UserScript==
// @name 有iframe界面的自动下一集
// @namespace http://tampermonkey.net/
// @version 2024-11-15
// @description try to take over the world!
// @author You
// @match https://www.qiju.cc/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=qiju.cc
// @grant none
// ==/UserScript==
(function () {
'use strict';
function gotoNext() {
// 假设你有一个 iframe 元素
let iframe = document.querySelectorAll('iframe')[2];
// 监听 iframe 的 onload 事件
iframe.onload = function () {
// 在这里执行你想要在 iframe 加载完成后执行的操作
console.log('iframe 加载完成');
// 示例:获取 iframe 中的文档对象
let iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
// 现在你可以操作 iframe 中的文档了
// 例如,获取 iframe 中的某个元素
let video = iframeDoc.querySelector('video');
video.addEventListener('ended', () => {
let currPlay = document.querySelector('.box.border.on.ecnav-dt')
if (currPlay.nextElementSibling) {
currPlay.nextElementSibling.firstElementChild.click();
}
})
};
}
//首次执行
gotoNext();
})();
阅读剩余的10%