YouTube Anti-AFK

Auto Click Continue Watching

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube Anti-AFK
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Auto Click Continue Watching
// @author       Bacon But Pro
// @match        https://www.youtube.com/*
// @run-at       document-start
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const observer = new MutationObserver(() => {
        let btn1 = document.querySelector("button.ytp-autonav-endscreen-cancel-button");
        let btn2 = document.querySelector("ytd-button-renderer#confirm-button button");

        if (btn1) {
            console.log("Anti-AFK: auto click continue button (style 1)");
            btn1.click();
        }
        if (btn2) {
            console.log("Anti-AFK: auto click continue button (style 2)");
            btn2.click();
        }

        let dialog = document.querySelector("yt-confirm-dialog-renderer");
        if (dialog) {
            console.log("Anti-AFK: remove confirm dialog");
            dialog.remove();
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });

    console.log("YouTube Anti-AFK loaded!");
})();