// ==UserScript==
// @name YouTube Play All
// @description Adds the Play-All-Button to the videos and shorts sections of a YouTube-Channel
// @version 2024-06-18.0
// @author Robert Wesner (https://robert.wesner.io)
// @license MIT
// @namespace http://robert.wesner.io/
// @match https://*.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
document.head.insertAdjacentHTML('beforeend', ``);
let id;
const apply = () => {
let parent = location.host === 'm.youtube.com'
// mobile view
? document.querySelector('ytm-feed-filter-chip-bar-renderer > div')
// desktop view
: document.querySelector('ytd-feed-filter-chip-bar-renderer iron-selector#chips');
// See: available-lists.md
let [allPlaylist, popularPlaylist] = window.location.pathname.endsWith('/videos')
// Normal videos
// list=UULP has the all videos sorted by popular
// list=UU adds shorts into the playlist, list=UULF has videos without shorts
? ['UULF', 'UULP']
// Shorts
: ['UUSH', 'UUPS'];
parent.insertAdjacentHTML(
'beforeend',
// Check if popular videos are displayed
parent.querySelector(':nth-child(2).selected, :nth-child(2).iron-selected')
? `Play Popular`
: `Play All`,
);
};
const observer = new MutationObserver(apply);
const addButton = async () => {
observer.disconnect();
if (!(window.location.pathname.endsWith('/videos') || window.location.pathname.endsWith('/shorts'))) {
return;
}
// This check is necessary for the mobile Interval
if (document.querySelector('.play-all-button')) {
return;
}
const html = await (await fetch('.')).text();
const i = html.indexOf(' {
const button = document.querySelector('.play-all-button');
if (button) {
button.remove();
}
};
if (location.host === 'm.youtube.com') {
// The "yt-navigate-finish" event does not fire on mobile
// Unfortunately pushState is triggered before the navigation occurs, so a Proxy is useless
setInterval(addButton, 1000);
} else {
window.addEventListener('yt-navigate-start', removeButton);
window.addEventListener('yt-navigate-finish', addButton);
}
})();