-
-
Save jeffmbellucci/8db3a8b27664dac6b8f9cf10b416b433 to your computer and use it in GitHub Desktop.
// To run, install GreaseMonkey or TamperMonkey extension in your browser | |
// Copy this code into new user script, and enable | |
// ==UserScript== | |
// @name Disable Youtube autoplay | |
// @version 1.0 | |
// @description This script turns off Youtube's newest autoplay feature after the page loads | |
// @author Jeff Bellucci | |
// @match *://www.youtube.com/* | |
// @run-at document-start | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function uncheck(toggle) { | |
if (toggle.hasAttribute('checked')) { | |
toggle.click(); | |
} | |
} | |
function disableAfterLoad() { | |
var autoplayToggle = document.getElementById('toggle'); | |
if (autoplayToggle) { | |
uncheck(autoplayToggle); | |
} else { | |
setTimeout(disableAfterLoad, 500); | |
} | |
} | |
disableAfterLoad(); | |
})(); |
@S3NTYN3L
It finally stopped working for me as well. @konomikitten's script works wonderfully.
But the mutationObserver freaks out on my side, so I replaced it with setInterval every 1 second instead and stops the script once it detects that the autoplay next has been disabled.
Here's a shortened working script that only disables autoplay next with setInterval, nothing else.
var var_interval_id = window.setInterval( function( window ) {
let a = window.document.querySelector( "button.ytp-button[data-tooltip-target-id='ytp-autonav-toggle-button']" ); // get the button
if ( a.getAttribute( "aria-label" ) == "Autoplay is on" ) {
a.click( ); // disable autoplay next if enabled
}
if ( a.getAttribute( "aria-label" ) == "Autoplay is off" ) {
window.clearInterval( var_interval_id ); // end script once done
}
}, 1024, window );
@01yakiek
That script seems to be working.
Thanks for sharing it.
The problem is that Google's horrible naming abilities have caused confusion over what is what. This, and @konomikitten's scripts only affect the button on videos as seen in @01yakiek's screenshot which is incorrectly labeled "Autoplay". In reality, that button should be labeled "Auto Advance" (which is why konomikitten calls it "Next Up"). All it does is to determine if YouTube automatically plays the next video in a playlist (or ostensibly if it moves on to the next suggested/related/recommended video). It doesn't actually control or block auto-PLAY.
If you toggle that switch, videos will still play automatically when you navigate to a video page (e.g., if you go to a playlist's page then click on one of the videos). It also doesn't stop videos from automatically playing when you view a channel page or the YouTube homepage.
The worst part is that even browsers' own autoplay controls can't block it. The Firefox devs have indicated that because of the way Google has redesigned YouTube to be "dynamic", you're not really navigating to "new" pages anymore, you're still on the same page which is just being modified with new content, therefore Firefox doesn't ask you if you want to let media play again, so if you click to allow a video to play once in a session, it's considered allowed indefinitely throughout that session. 🤦
I'm not sure anybody will be able to prevent Google from forcibly autoplaying videos and wasting CPU cycles and bandwidth and mobile data and jump-scaring people with audio and other stuff in their selfish endeavor to convince advertisers that people are "choosing" to watch the videos and ads. 😠 This requires legislation.
@Synetech it used to be called up next, they've renamed it a few times and it's extremely frustrating. As is dealing with them changing it constantly.
@S3NTYN3L
It finally stopped working for me as well. @konomikitten's script works wonderfully.
But the mutationObserver freaks out on my side, so I replaced it with setInterval every 1 second instead and stops the script once it detects that the autoplay next has been disabled.Here's a shortened working script that only disables autoplay next with setInterval, nothing else.
var var_interval_id = window.setInterval( function( window ) { let a = window.document.querySelector( "button.ytp-button[data-tooltip-target-id='ytp-autonav-toggle-button']" ); // get the button if ( a.getAttribute( "aria-label" ) == "Autoplay is on" ) { a.click( ); // disable autoplay next if enabled } if ( a.getAttribute( "aria-label" ) == "Autoplay is off" ) { window.clearInterval( var_interval_id ); // end script once done } }, 1024, window );
Thanks for the code.
But how can I make a web extension in which I can toggle the autoplay button on and off?
I have the old background.js and the script.js
I also have a "jquery-3.2.1.min.js" but I don't know what this script does.
Please help!
@JohnyP36 You need to use a script running extension. Personally, I prefer Tampermonkey, but there are a number of options out there that let you save different scripts and run them as you see fit, on a single website, on all websites, on document ready, etc, etc. They are quite powerful.
I have forked and modded this userscript due to youtube breaking stuff (You refresh the page, autoplay goes back on even if you turn it off). The autoplay got moved into html5 player, and the only way I can do it is with JQuery. My version would not allow autoplay to be turned on, it'll turn off again because of youtube bug above.
So, is there still a workable JS script as of the present?
@scrutinizer11 this one works for me https://gist.githubusercontent.com/sidneys/02a9025ae1f23aefe1f4ea02e78b0ac8/
@01yakiek
This is what I see.
Doesn't matter if I'm logged in or not.