Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jackysee/96e9bfa80e1457668833cb7af129f808 to your computer and use it in GitHub Desktop.
Save jackysee/96e9bfa80e1457668833cb7af129f808 to your computer and use it in GitHub Desktop.
Youtube classic playlist auto next toggle
// ==UserScript==
// @name Playlist auto next toggle - youtube.com
// @namespace Violentmonkey Scripts
// @match https://www.youtube.com/watch
// @grant none
// @version 1.0
// @author -
// @description 4/24/2020, 10:01:32 AM
// ==/UserScript==
/*
For Firefox user who uses youtube classic.
A checkbox would be added to control whether to auto play next in playlist
*/
let control = document.querySelector('.playlist-nav-controls');
if(!control) {
return;
}
let k = Object.keys(window._yt_www)
.filter(key => typeof window._yt_www[key] === "function")
.find(key => String(window._yt_www[key]).split("spf.navigate").length > 1);
if(!k) {
return;
}
let ori = window._yt_www[k];
window._yt_www[k] = function() {
if(localStorage.getItem('playlistAutoplay') === 'true'){
ori.apply(this, arguments);
}
}
var cb = document.createElement('input');
cb.setAttribute('type', 'checkbox');
cb.style.verticalAlign = 'middle';
cb.checked = localStorage.getItem('playlistAutoplay') === 'true';
cb.addEventListener('change', function(){
localStorage.setItem('playlistAutoplay', cb.checked? 'true':'false');
});
var label = document.createElement('label');
label.appendChild(cb);
label.appendChild(document.createTextNode('auto next'));
label.style.paddingLeft = '8px';
control.appendChild(label);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment