youtube continue play

When the "Video paused, do you want to continue watching?" Dialog box appears, press "Yes" automatically

Od 18.03.2020.. Pogledajte najnovija verzija.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name               youtube continue play
// @name:en            youtube continue play
// @name:zh-CN         youtube继续播放
// @name:zh-TW         youtube繼續播放
// @name:ja            youtube履歴書再生
// @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    「ビデオを一時停止しました。引き続き視聴しますか?」ダイアログボックスが表示されたら、「はい」を自動的に押します
// @namespace          https://greasyfork.org/zh-TW/users/461233-jack850628
// @version            1.13
// @author             jack850628
// @include            /^https?:\/\/(:?.*?\.?)youtube.com/.*$/
// @run-at             document-end
// @license            MIT
// ==/UserScript==

(function() {
    var isObserveYtConfirmDialogRenderer = false;
    let ytConfirmDialogRendererObserver = new MutationObserver(([{target: ytConfirmDialogRenderer}], observer) => {
        if(ytConfirmDialogRenderer.style.display != 'none'){
            ytConfirmDialogRenderer.querySelector('yt-button-renderer[dialog-confirm]').click();
        }
    });
    let pausedF = function({target: videoPlay}){
        if(!isObserveYtConfirmDialogRenderer){
            setTimeout(function(){
                let ytConfirmDialog = document.querySelector('yt-confirm-dialog-renderer');
                if(ytConfirmDialog){
                    ytConfirmDialogRendererObserver.observe(
                        ytConfirmDialog.parentElement,
                        {
                            attributes: true
                        }
                    );
                    isObserveYtConfirmDialogRenderer = true;
                }
            }, 500);
        }
    }
    function listenerVideoPlayer(){
        let videoPlay = document.querySelector('video');
        if(!videoPlay){
            return false;
        }
        videoPlay.addEventListener('pause', pausedF);
        return true;
    }
    let scriptBlocks = document.getElementsByTagName('script')[0];
	let ycpScript = document.createElement('script');
    ycpScript.setAttribute('id','ycp-script');
    ycpScript.setAttribute('ycp-data','wait');
	ycpScript.innerHTML = `
		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);
							document.querySelector('#ycp-script').setAttribute('ycp-data','ok');
							return result;
						}
					}else{
						arguments[1].onDone = () => document.querySelector('#ycp-script').setAttribute('ycp-data','ok');
					}
				}
				return window.spf._request.apply(this,arguments);
			},
			writable: true,
			configurable: true
		});
        document.querySelector('#ycp-script').setAttribute('ycp-data','ok');
	`;
    let ycpScriptObserver = new MutationObserver(([{target: ycpScript}], observer) => {
          if(ycpScript.getAttribute('ycp-data') == 'ok'){
              if(!listenerVideoPlayer()) ycpScript.setAttribute('ycp-data','wait')
              else{
                  ycpScriptObserver.disconnect();
              }
          }
    });
	if(scriptBlocks){
        ycpScriptObserver.observe(
            ycpScript,
            {
                attributes: true
            }
        );
		scriptBlocks.parentNode.insertBefore(ycpScript,scriptBlocks);
	}
})();