Video 用于禁用YouTube';s";“上一步”自动播放功能
有没有办法使用Firefox的脚本或插件完全禁用YouTube“up next”或自动播放功能?请注意,“自动播放”这个名称很模糊。我特别指的是在当前视频播放结束后播放“建议”视频的功能。该功能经常陷入循环中,无限重复相同的两个视频。此外,它经常播放下一个视频,当我在中间写评论下面的视频。最近的UI更改破坏了我用来完成此任务的加载项。启用Cookie不是我的选择,因为我必须在这两个令人不快的选项中进行选择:Video 用于禁用YouTube';s";“上一步”自动播放功能,video,youtube,firefox-addon,greasemonkey,autoplay,Video,Youtube,Firefox Addon,Greasemonkey,Autoplay,有没有办法使用Firefox的脚本或插件完全禁用YouTube“up next”或自动播放功能?请注意,“自动播放”这个名称很模糊。我特别指的是在当前视频播放结束后播放“建议”视频的功能。该功能经常陷入循环中,无限重复相同的两个视频。此外,它经常播放下一个视频,当我在中间写评论下面的视频。最近的UI更改破坏了我用来完成此任务的加载项。启用Cookie不是我的选择,因为我必须在这两个令人不快的选项中进行选择: 保持cookies打开,并处理侵入性的“推荐”视频,这些视频会污染到当前视频一侧的链接
(function () {
'use strict';
function removeAPUN() {
var autoplaybar = document.getElementsByClassName('autoplay-bar')[0];
if (autoplaybar) {
autoplaybar.removeAttribute('class');
document.getElementsByClassName('checkbox-on-off')[0].remove();
}
}
window.addEventListener('readystatechange', removeAPUN, true);
window.addEventListener('spfdone', removeAPUN);
}())
提前谢谢 您说完全禁用该功能,所以我不确定以下内容是否100%满足您的需要,但可能会有所帮助 下面将一直查找“禁用自动播放”按钮,直到它存在,然后单击它(如果它当前设置为活动):
setTimeout(disable_autoplay, 1000);
function disable_autoplay(){
// Try to get the toggle button
var toggle_button = document.getElementById("toggle");
if (toggle_button){
if (toggle_button.hasAttribute("checked")){
// If it is checked, click it to disable autoplay
toggle_button.click();
// Retry one more time to make sure it stays disabled
setTimeout(disable_autoplay, 5000);
}
} else {
// Not found, retry
console.log("Retrying in 1s");
setTimeout(disable_autoplay, 1000);
}
}
单击按钮后,它会重试一次,我不确定是否需要,但当我手动禁用自动播放时,它有时会在片刻后重新打开,因此,这只是为了确保它不会出现。这是对我为个人使用而设计的解决方案的改编,该解决方案适用于新的和旧的youtube版面。可能有一个更简单的解决方案,但这个方案不使用间隔计时器,以避免电池耗尽
function fixAutoplayNext()
{
let autoplay = document.getElementsByClassName("autoplay-bar")[0];
if (autoplay) // old layout
{
let check = document.querySelector("#autoplay-checkbox-label > .checked");
let input = document.getElementById("autoplay-checkbox") || document.getElementById("toggle");
if (check && input)
{
if (parseInt(window.getComputedStyle(check).width, 10) > 0)
{
input.click();
}
}
// Removing the switch is optional, but I don't see a reason to leave it around.
autoplay.parentNode.removeChild(autoplay);
}
else // new layout
{
autoplay = document.getElementById("head");
if (autoplay)
{
let toggler = document.getElementById("toggle");
if (toggler && toggler.hasAttribute("checked"))
{
//toggler.click();
toggler.removeAttribute("checked");
toggler.dispatchEvent(new Event("change"));
}
// Removing the switch is optional, but I don't see a reason to leave it around.
autoplay.parentNode.removeChild(autoplay);
}
}
}
fixAutoplayNext();
// Youtube loads pages entirely using Ajax. Listening for a video to load is enough for now.
document.addEventListener("loadstart", function(e) {
if (e.target instanceof window.HTMLMediaElement)
{
window.setTimeout(fixAutoplayNext, 25);
}
}, true );
对我有用。