Greasy Fork

Greasy Fork is available in English.

Youtube.com Auto Continue Playback

auto continue when playback stops it asks to press 'yes' to keep playing, now without delay

当前为 2022-02-03 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Youtube.com Auto Continue Playback
// @namespace    q1k
// @version      2.0.0
// @description  auto continue when playback stops it asks to press 'yes' to keep playing, now without delay
// @author       q1k
// @match        *://music.youtube.com/*
// @include      *://www.youtube.com/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==


var video_player;
var user_clicked_time=0;
function addListeners() {
    video_player.addEventListener('pause', (e) => {
        if(e.srcElement.ended){
            return;
        }
        if(user_clicked_time>0){
            let temp_time=new Date().getTime();
            if(temp_time - user_clicked_time < 1000) {
                return;
            }
        }
        e.srcElement.play();
    });
    window.addEventListener('keydown', (e) => {
        if (e.target.tagName=="INPUT" || e.target.contentEditable=="true" || e.target.contentEditable==true){
            return;
        }
        else {
            user_clicked_time=new Date().getTime();
        }
    });
    window.addEventListener('mouseup', (e) => {
        if (e.which == 1) {
            user_clicked_time=new Date().getTime();
        }
    });
}

var checkElementID;
function startElementChecker(){
    if(document.domain=="music.youtube.com"){
        checkElementID = setInterval(function(){
            if ( (typeof(document.querySelector("#song-video #movie_player .html5-video-container video")) == undefined || document.querySelector("#song-video #movie_player .html5-video-container video") == null) ) {
                return;
            }
            video_player = document.querySelector("#song-video #movie_player .html5-video-container video");
            addListeners();
            clearInterval(checkElementID);
        },1000);
    } else if(document.domain=="www.youtube.com"){
        checkElementID = setInterval(function(){
            if ( (typeof(document.querySelector("#ytd-player #movie_player .html5-video-container video")) == undefined || document.querySelector("#ytd-player #movie_player .html5-video-container video") == null) ) {
                return;
            }
            video_player = document.querySelector("#ytd-player #movie_player .html5-video-container video");
            addListeners();
            clearInterval(checkElementID);
        },1000);
    }
}
startElementChecker();