Created
August 3, 2023 00:35
-
-
Save yuceltoluyag/36f09ad1df6a0f692a752bcbd4c08ab4 to your computer and use it in GitHub Desktop.
youtube 'Play All' button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
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