twitchAdSkip

Bezos is already too rich;i didn't make this

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         twitchAdSkip
// @namespace    https://www.twitch.tv/
// @version      1.0
// @description  Bezos is already too rich;i didn't make this
// @author       SimpleHacker
// @match        https://www.twitch.tv/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.onload = function() {

        const dblclick = new MouseEvent('dblclick', {
            bubbles: true,
            cancelable: true,
            view: window
        });

        let options = {
            childList: true,
            subtree: true
        };

        const observer = new MutationObserver(function(mutations) {
            mutations.forEach((mutation) => {
                mutation.addedNodes.forEach((node) => {
                    let ad = node.querySelector('[data-test-selector="ad-banner-default-text"]');
                    if (ad) {
                        let resetButton = document.querySelector('[data-a-target="ffz-player-reset-button"]');

                        if (resetButton) {
                            resetButton.dispatchEvent(dblclick);
                        } else {
                            window.location.reload();
                        }
                    }
                });
            });
        });

        const target = document.querySelector('[data-a-target="video-player"]');

        observer.observe(target, options);
    }

})();