取消爱奇艺暂停广告

fuck爱奇艺暂停广告

// ==UserScript==
// @name         取消爱奇艺暂停广告
// @namespace    http://bmmmd.com/
// @version      0.5
// @description  fuck爱奇艺暂停广告
// @match        https://www.iqiyi.com/*
// @run-at       document-idle
// @license      GPL v3
// ==/UserScript==

(function () {
    'use strict';

    const observer = new MutationObserver(() => {
        const btnplaypause = document.querySelectorAll('[data-player-hook="btnplaypause"]');
        if (btnplaypause.length == 0) { return; }
        observer.disconnect();
        const video = document.querySelector("video");
        // 点击视频
        video.addEventListener("click", (event) => {
            video.paused ? video.play() : video.pause();
            event.stopPropagation();
        }, true);
        // 暂停按钮
        btnplaypause.forEach((items) => {
            items.addEventListener("click", (event) => {
                video.paused ? video.play() : video.pause();
                event.stopPropagation();
            }, true);
        });
        // 空格
        document.addEventListener("keydown", (event) => {
            if (event.code == "Space" && event.target.tagName != "INPUT") {
                video.paused ? video.play() : video.pause();
                event.stopPropagation();
            }
        }, true);
    });
    const target = document.querySelector('#flashbox');
    target && observer.observe(target, { childList: true, subtree: true });
})();