TVer自動再生

Tverの再生画面を開いたときに、自動で再生されるようにします

// ==UserScript==
// @name        TVer自動再生
// @namespace   TVer自動再生
// @match       https://tver.jp/*
// @grant       none
// @version     1.1
// @author      chimaha
// @description Tverの再生画面を開いたときに、自動で再生されるようにします
// @license     MIT license
// @icon        https://tver.jp/favicon.ico
// @compatible  firefox
// @compatible  chrome
// ==/UserScript==

/*!
*TVer自動再生 https://greasyfork.org/ja/scripts/480743
*Copyright (c) 2023 chimaha
*Released under the MIT license.
*see https://opensource.org/licenses/MIT
*/

"use strict";

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

const observer = new MutationObserver(() => {
    if (regex.test(location.href)) {
        const playButton = document.querySelector('.big-play-button_host__z6CnM');
        if (saveURL && saveURL != location.href) { autoPlay = true; }
        if (playButton && autoPlay) {
            saveURL = location.href;
            autoPlay = false;
            playButton.click();
        }
    } else {
        autoPlay = true;
    }
});
const config = { childList: true, subtree: true };
observer.observe(document.getElementById("__next"), config);