TVer Click to Play

Stop auto-play on TVer episode pages.

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name           TVer Click to Play
// @icon           https://www.google.com/s2/favicons?domain=tver.jp&size=16
// @description    Stop auto-play on TVer episode pages.
// @description:ja TVerの自動再生をストップ(hamachi様のスクリプトをベースに修正)
// @namespace      https://bsky.app/profile/neon-ai.art
// @homepage       https://neon-aiart.github.io/
// @version        1.0
// @author         ねおん
// @match          https://tver.jp/*
// @grant          none
// @run-at         document-idle
// @license        MIT
// @copyright      ねおん (Based on code by hamachi)
// ==/UserScript==

(function() {
    'use strict';

    const regex = /https:\/\/tver\.jp\/episodes\/.+/;
    let saveURL = "";;

    const observer = new MutationObserver(() => {
        const currentURL = location.href;
        if (regex.test(currentURL)) {
            // URLが変わった場合、停止処理を再度行えるようにリセット
            if (saveURL !== location.href) {
                const video = document.querySelector("video");

                // ビデオが見つかり、かつ再生されている(または再生しようとしている)場合
                if (video && !video.paused) {
                    video.pause();
                    video.currentTime = 0;
                    // 1回止めたらこのURLでの自動停止は終了
                    saveURL = currentURL;
                    // console.log("[Debug] Auto-play stopped successfully.");
                }
            }
        } else {
            // エピソードページ以外(トップ画面など)に戻ったらリセット
            saveURL = "";
        }
    });

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