Skip to content

Instantly share code, notes, and snippets.

@k98kurz
Last active August 29, 2015 14:04
Show Gist options
  • Save k98kurz/76c08ff2dbe0a479c955 to your computer and use it in GitHub Desktop.
Save k98kurz/76c08ff2dbe0a479c955 to your computer and use it in GitHub Desktop.
This makes the list autoplay toggle actually work; i.e., it is now a global setting rather than per-page clickfest.
// ==UserScript==
// @name YouTube Autoplay Toggle
// @namespace https://gist.github.com/k98kurz
// @updateUrl https://gist.githubusercontent.com/k98kurz/76c08ff2dbe0a479c955/raw/
// @version 1.2
// @description This makes the list autoplay toggle actually work; i.e., it is now a global setting rather than per-page clickfest.
// @match https://www.youtube.com/watch?v=*&list=*
// @match http://www.youtube.com/watch?v=*&list=*
// @match https://www.youtube.com/watch?list=*&v=*
// @match http://www.youtube.com/watch?list=*&v=*
// @copyright 2014+, me
// ==/UserScript==
(function (w) {
// wait until the DOM is loaded
document.addEventListener("DOMContentLoaded", function () {
// and then wait some more (because of weird youtube ajax stuff)
setTimeout( function() {
var t = document.querySelector(".toggle-autoplay");
// automatically turn off autoplay if it has been toggled appropriately
if (localStorage.disableAnnoyingAutoplay=='true'&&t.attributes['class'].value.indexOf('yt-uix-button-toggled')>=0) {
t.dispatchEvent(new MouseEvent("click"));
t.attributes['class'].value = t.attributes['class'].value.replace(' yt-uix-button-toggled', '');
}
// toggle setting
t.addEventListener("click", function(e) {
localStorage.disableAnnoyingAutoplay = (localStorage.disableAnnoyingAutoplay=='true' ? 'false' : 'true');
});
}, 1000);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment