Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save muhammetozeski/c0ca694e4f5cca4885541d7ca21cfc2c to your computer and use it in GitHub Desktop.
Save muhammetozeski/c0ca694e4f5cca4885541d7ca21cfc2c to your computer and use it in GitHub Desktop.
A simple tampermonkey script for creating a playlist for all videos of a channel. Navigate to a video and click the button inside the tampermonkey. The code is written by gpt4o
// ==UserScript==
// @name Create A playlist full fill with all videos of a channel
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Modify YouTube Channel ID and open new URL in foreground tab with button click
// @author Your Name
// @match https://www.youtube.com/*
// @grant GM_registerMenuCommand
// ==/UserScript==
(function() {
'use strict';
//Credits: https://www.youtube.com/watch?v=M-PJ10sdcYA
function main() {
const channelId = getChannelId();
if (channelId) {
const changedChannelId = changeChannelId(channelId);
const videoUrl = getVideoUrl();
if (videoUrl) {
const newUrl = constructNewUrl(videoUrl, changedChannelId);
openNewTab(newUrl);
} else {
console.log("Couldn't find the Video URL.");
}
} else {
console.log("Couldn't get the Channel ID");
}
}
function getChannelId() {
const regex = /"channelId":"([^"]*)"/;
const match = document.body.innerHTML.match(regex);
return match ? match[1] : null;
}
function changeChannelId(channelId) {
return channelId.substring(0, 1) + 'U' + channelId.substring(2);
}
function getVideoUrl() {
const regex = /watch\?v=([^&]*)/;
const match = window.location.href.match(regex);
return match ? match[0] : null;
}
function constructNewUrl(videoUrl, changedChannelId) {
return `https://www.youtube.com/${videoUrl}&list=${changedChannelId}`;
}
function openNewTab(url) {
window.open(url, '_blank').focus();
}
GM_registerMenuCommand("Create A playlist full fill with all videos of a channel", main);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment