有iframe界面的自动下一集

点击查看代码
// https://www.qiju.cc/vod/play/id/356/sid/2/nid/1.html
//这是个残次品
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()
    }
})
延时器的方案
点击查看代码
// ==UserScript==
// @name         New Userscript
// @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)
})();

最优方案
点击查看代码
// ==UserScript==
// @name         有iframe方法2
// @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();
})();






posted @ 2024-11-15 07:05  神仙不在  阅读(319)  评论(0)    收藏  举报