TVer Click to Play

Stop auto-play on TVer episode pages.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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 });
})();