TVer Click to Play

Stop auto-play on TVer episode pages.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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 });
})();