TVer click play

Tverの再生画面をクリックして、再生開始・停止を行えるようにします

// ==UserScript==
// @name        TVer click play
// @namespace   TVer click play
// @match       https://tver.jp/*
// @grant       none
// @version     1.0
// @author      chimaha
// @description Tverの再生画面をクリックして、再生開始・停止を行えるようにします
// @license     MIT license
// @icon        https://tver.jp/favicon.ico
// @compatible  firefox
// @compatible  chrome
// ==/UserScript==

"use strict";

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

const observer = new MutationObserver(() => {
    if (regex.test(location.href)) {
        if (saveURL && saveURL != location.href) {
            isValid = false;
        }
    
        // 再生終了時に実行
        if (document.querySelector('.big-play-button_host__z6CnM')) {
            isValid = false;
        }
        
        const target = document.querySelector(".controller_container__PMXA9");
        if (target && !isValid) {
            saveURL = location.href;
            isValid = true;
            const video = document.querySelector("video");
            const playerCover = document.querySelector('#player-cover');

            document.querySelector('.progress_container__C3IB_').style.margin = "5px 8px 0px";
            target.insertAdjacentHTML('afterbegin', '<div id="player-cover" style="z-index: -1; height: 100%; width: 100%;"></div>');

            playerCover.addEventListener("click", () => {
                if (video.paused) {
                    video.play();
                } else {
                    video.pause();
                }
            });
        }
    }
});
const config = { childList: true, subtree: true };
observer.observe(document.getElementById("__next"), config);