Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save senthilmpro/81db5bae09e68174a5d35f038b9b1b6d to your computer and use it in GitHub Desktop.
Save senthilmpro/81db5bae09e68174a5d35f038b9b1b6d to your computer and use it in GitHub Desktop.
youtube channel all videos as playlist userscript
// ==UserScript==
// @name yt-channel-playlist
// @namespace http://tampermonkey.net/
// @version 2024-09-15
// @description try to take over the world!
// @author senthilmpro
// @match https://www.youtube.com/@*
// @match https://www.youtube.com/*/
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// @run-at document-end
// ==/UserScript==
(function () {
'use strict';
// go to channel home page (not any other subtab)
const getChannelId = () => {
let scripts = Array.from(document.querySelectorAll('script'));
let script = scripts.filter(x => x.innerHTML?.includes('externalId'))
let channelId = script[0]?.innerHTML?.split("externalId")[1].split(",")[0]?.replace(":", '')?.replaceAll('"', '');
if (channelId.substring(0, 2) === 'UC') {
return channelId;
} else {
console.log("INVALID channelId");
}
return null;
}
const updateChannelPlaylistId = () => {
const channelId = getChannelId();
if(!channelId) {
console.log("ERROR: channelId not found");
return;
}
let newChannelId = 'UU' + channelId.substring(2);
let playlistUrl = `https://www.youtube.com/playlist?list=${newChannelId}`;
console.log(playlistUrl);
// redirect
window.location.href = playlistUrl;
}
const appendButtonToPageHeader = () => {
let button = document.createElement('button');
button.innerText = 'Load as Playlist';
button.className = "btn";
button.style.height = '30px';
button.style.width = '100px';
button.style.color = 'black';
button.style.border = '1px solid red';
button.onclick = () => {
updateChannelPlaylistId();
}
let parentElement = document.querySelector("[id^=page-header]");
let headerEl = parentElement.querySelector('.page-header-view-model-wiz__page-header-headline-info');
headerEl.insertBefore(button, headerEl.children[0]);
}
setTimeout(() => {
appendButtonToPageHeader();
}, 1000);
// Your code here...
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment