Skip to content

Instantly share code, notes, and snippets.

@yuceltoluyag
Created August 3, 2023 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuceltoluyag/36f09ad1df6a0f692a752bcbd4c08ab4 to your computer and use it in GitHub Desktop.
Save yuceltoluyag/36f09ad1df6a0f692a752bcbd4c08ab4 to your computer and use it in GitHub Desktop.
youtube 'Play All' button
/***
Runs properly from either a video page (watch?v) or a channel page.
Source JS (copy and paste to devtools console)
Bookmarklet (select and drag to your bookmarks bar)
javascript:void%20function(){function%20a(b,c){var%20d;return%20Object.keys(b).some(function(e){return%20e===c%3F(d=b[e],!0):b[e]%26%26%22object%22==typeof%20b[e]%3F(d=a(b[e],c),void%200!==d):void%200}),d}var%20b=a(ytInitialData,%22browseId%22);window.location.replace(%22https://youtube.com/playlist%3Flist=%22+b.replace(%22UC%22,%22UU%22))}();
Because of the nature of how this code works, I've had it take me to the incorrect playlist a couple times in testing, but seemingly every time that happens, the second try works fine.
***/
function findVal(object, key) { // https://stackoverflow.com/a/40604638
var value;
Object.keys(object).some(function(k) {
if (k === key) {
value = object[k];
return true;
}
if (object[k] && typeof object[k] === 'object') {
value = findVal(object[k], key);
return value !== undefined;
}
});
return value;
}
var channelID = findVal(ytInitialData, 'browseId');
window.location.replace("https://youtube.com/playlist?list=" + channelID.replace("UC", "UU"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment