Greasy Fork is available in English.

YouTube Autoplay Buttons. Adding “Play all videos” buttons back

Adds 3 buttons on each YouTube profile under Videos (All videos + shorts, All videos, Shorts only)

As of 2024-10-04. See the latest version.

// ==UserScript==
// @name         YouTube Autoplay Buttons. Adding “Play all videos” buttons back
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Adds 3 buttons on each YouTube profile under Videos (All videos + shorts, All videos, Shorts only)
// @author       Nieme
// @match        https://www.youtube.com/*
// @grant        none
// @license      GPLv2
// ==/UserScript==
 
(function() {
	'use strict';
 
	function getChannelId() {
		let cId = null;
 
		if (typeof ytInitialData !== 'undefined') {
			cId = ytInitialData?.metadata?.channelMetadataRenderer?.externalId;
		}
 
		if (!cId) {
			cId = document.querySelector('.ytp-ce-link[href]')?.href?.split('/')?.pop() ||
				  document.querySelector('[itemprop="identifier"]')?.content;
		}
 
		return cId;
	}
 
	function addCustomButtons() {
		const chipsContainer = document.querySelector('ytd-feed-filter-chip-bar-renderer #chips');
		if (chipsContainer && !document.querySelector('.custom-play-all-button')) {
			function createButton(text, playlistLinkGenerator) {
				const newButton = document.createElement('a');
				newButton.style.marginLeft = '10px';
				newButton.href = '#';
				newButton.classList.add('custom-play-all-button');
				newButton.textContent = '';
 
				const newChip = document.createElement('yt-chip-cloud-chip-renderer');
				newChip.className = 'style-scope ytd-feed-filter-chip-bar-renderer';
				newChip.setAttribute('modern', '');
				newChip.setAttribute('aria-selected', 'false');
				newChip.setAttribute('role', 'tab');
				newChip.setAttribute('tabindex', '0');
				newChip.setAttribute('chip-style', 'STYLE_DEFAULT');
 
				const newText = document.createElement('span');
				newText.textContent = text;
				newChip.appendChild(newText);
 
				newButton.appendChild(newChip);
 
				newButton.addEventListener('click', (e) => {
					e.preventDefault();
 
					const cId = getChannelId();
 
					if (cId) {
						const playlistLink = playlistLinkGenerator(cId);
						window.location.href = playlistLink;
					} else {
						console.error('Channel-ID konnte nicht abgerufen werden.');
					}
				});
 
				chipsContainer.appendChild(newButton);
			}
 
			createButton('Play Standard and Shorts together', (cId) => `https://www.youtube.com/playlist?list=UU${cId.slice(2)}`);
			createButton('Play Standard only', (cId) => `https://www.youtube.com/playlist?list=UULF${cId.slice(2)}`);
			createButton('Play Shorts only', (cId) => `https://www.youtube.com/playlist?list=UUSH${cId.slice(2)}`);
		}
	}
 
	function checkAndAddButtons() {
		if (window.location.pathname.includes('/videos')) {
			addCustomButtons();
		}
	}
 
	const observer = new MutationObserver(() => {
		checkAndAddButtons();
	});
 
	observer.observe(document, {
		childList: true,
		subtree: true
	});
 
	let oldHref = document.location.href;
	  const currentHref = document.location.href;
	  if (oldHref !== currentHref) {
		oldHref = currentHref;
		checkAndAddButtons();
	  }
})();