// ==UserScript==
// @name YouTube - Auto Expand Subscriptions
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Automatically expands the "Show more" button in YouTube's subscription sidebar, keeping your subscriptions list fully expanded.
// @author sharmanhall
// @match https://www.youtube.com/*
// @grant none
// @run-at document-idle
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @license MIT
// @copyright 2024, sharmanhall
// ==/UserScript==
/*
MIT License
Copyright (c) 2024 sharmanhall
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
=== Description ===
This userscript automatically clicks the "Show more" button in YouTube's subscription sidebar,
ensuring your subscriptions list stays expanded. It works by:
1. Watching for the YouTube guide section to load
2. Finding the "Show more" button using various selectors
3. Automatically clicking it when found
4. Retrying multiple times if needed
=== Installation ===
1. Install a userscript manager (like Tampermonkey)
2. Install this script
3. Visit YouTube - your subscriptions should automatically expand!
=== Support ===
For issues or feature requests, please visit the GitHub issues page.
*/
(function() {
'use strict';
const DEBUG = true;
function log(...args) {
if (DEBUG) console.log('[YT-Auto-Expand]', ...args);
}
// Print the full HTML of an element for debugging
function logElement(element) {
if (!DEBUG) return;
if (!element) {
log('Element is null');
return;
}
log('Element:', {
tagName: element.tagName,
id: element.id,
className: element.className,
innerHTML: element.innerHTML
});
}
function findShowMoreButton() {
log('Starting button search...');
// Try various selectors
const buttonSelectors = [
'ytd-guide-collapsible-entry-renderer ytd-guide-entry-renderer#expander-item',
'#items ytd-guide-collapsible-entry-renderer #expander-item',
'#items ytd-guide-section-renderer ytd-guide-collapsible-entry-renderer'
];
for (const selector of buttonSelectors) {
log(`Trying selector: ${selector}`);
const element = document.querySelector(selector);
if (element) {
log('Found element with selector:', selector);
logElement(element);
// Check for the endpoint and paper-item
const endpoint = element.querySelector('a#endpoint');
if (endpoint) {
log('Found endpoint:', endpoint.getAttribute('title'));
const paperItem = endpoint.querySelector('tp-yt-paper-item');
if (paperItem) {
log('Found paper-item');
// Check if it's actually the show more button
const text = element.textContent.trim();
log('Button text:', text);
if (text.includes('Show more')) {
log('Found correct button!');
return endpoint;
}
}
}
} else {
log(`No element found for selector: ${selector}`);
}
}
// Additional debug info
const guide = document.querySelector('ytd-guide-section-renderer');
if (guide) {
log('Guide section found, its HTML:');
logElement(guide);
} else {
log('Guide section not found');
}
return null;
}
function expandSubscriptions() {
const button = findShowMoreButton();
if (button) {
log('Clicking button...');
button.click();
return true;
}
return false;
}
// Function to handle retries with delay
function attemptExpansionWithRetry(retriesLeft = 10) {
log(`Attempt ${11 - retriesLeft}/10`);
if (retriesLeft <= 0) {
log('Max retries reached');
return;
}
if (!expandSubscriptions()) {
log(`Retrying in 1000ms... (${retriesLeft} attempts left)`);
setTimeout(() => {
attemptExpansionWithRetry(retriesLeft - 1);
}, 1000);
}
}
// Wait for the guide to be ready
function waitForGuide() {
log('Setting up guide observer');
const observer = new MutationObserver((mutations, obs) => {
log('DOM mutation detected');
const guideSection = document.querySelector('ytd-guide-section-renderer');
if (guideSection) {
log('Guide section found after mutation');
attemptExpansionWithRetry();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
// Start observing as soon as possible
log('Script started');
waitForGuide();
// Also try when the window loads
window.addEventListener('load', () => {
log('Window loaded, making attempt...');
attemptExpansionWithRetry();
});
})();