youtube繼續播放

當出現"影片已暫停,要繼續觀賞嗎?"對話方塊時自動按下"是"

目前為 2020-03-18 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name               youtube continue play
// @name:en            youtube continue play
// @name:zh-CN         youtube继续播放
// @name:zh-TW         youtube繼續播放
// @name:ja            youtube履歴書再生
// @namespace          https://greasyfork.org/zh-TW/users/461233-jack850628
// @version            1.0
// @description        When the "Video paused, do you want to continue watching?" Dialog box appears, press "Yes" automatically
// @description:en     When the "Video paused, do you want to continue watching?" Dialog box appears, press "Yes" automatically
// @description:zh-TW  當出現"影片已暫停,要繼續觀賞嗎?"對話方塊時自動按下"是"
// @description:zh-CN  当出现"影片已暂停,要继续观赏吗?"对话方块时自动按下"是"
// @description:ja    「ビデオを一時停止しました。引き続き視聴しますか?」ダイアログボックスが表示されたら、「はい」を自動的に押します
// @author             jack850628
// @include            /^https?:\/\/(:?.*?\.?)youtube.com/.*$/
// @license            MIT
// ==/UserScript==

(function() {
    let pausedF = function({target: videoPlay}){
        setTimeout(function(){
            let ytConfirmDialog = document.querySelector('yt-confirm-dialog-renderer');
            if(
                ytConfirmDialog &&
                ytConfirmDialog.parentElement &&
                ytConfirmDialog.parentElement.style.display != 'none'
            ){
                ytConfirmDialog.querySelector('yt-button-renderer[dialog-confirm]').click();
            }
        }, 500);
    }
    function listenerVideoPlayer(){
        let videoPlay = document.querySelector('video');
        if(!videoPlay){
            return;
        }
        videoPlay.addEventListener('pause', pausedF);
    }
    window.spf._request = window.spf.request;
    Object.defineProperty(window.spf, 'request', {
        value: function(){
            if(arguments[1]){
                if(arguments[1].onDone){
                    let onDone = arguments[1].onDone;
                    arguments[1].onDone = function(){
                        let result = onDone.apply(this,arguments);
                        listenerVideoPlayer();
                        return result;
                    }
                }else{
                    arguments[1].onDone = () => listenerVideoPlayer();
                }
            }
            return window.spf.script._done.apply(this,arguments);
        },
        writable: true,
        configurable: true
    });
    listenerVideoPlayer();
})();