Skip to content

Instantly share code, notes, and snippets.

@VelizarHristov
Last active December 29, 2024 01:29
Show Gist options
  • Save VelizarHristov/8520083be3ef07bb34012c56e63ac858 to your computer and use it in GitHub Desktop.
Save VelizarHristov/8520083be3ef07bb34012c56e63ac858 to your computer and use it in GitHub Desktop.
Greasemonkey script to collapse Youtube suggestions behind a button that lets you toggle them
// ==UserScript==
// @name Collapse Youtube suggestions
// @version 1
// @grant none
// @match https://www.youtube.com/*
// ==/UserScript==
let attemptCounter = 0;
// For some reason we need to initially hide the element twice before it stops reappearing
let hideCounter = 0;
function initializePage() {
const related = document.getElementById('related');
if (hideCounter < 2) {
if (related.style.display != 'none') {
related.style.display = 'none';
hideCounter++;
}
attemptCounter++;
const timeoutMs = attemptCounter < 100 ? 100 : 750;
setTimeout(initializePage, timeoutMs);
} else {
const btn = document.createElement('button');
btn.className = 'yt-spec-button-shape-next yt-spec-button-shape-next--filled yt-spec-button-shape-next--mono yt-spec-button-shape-next--size-m';
btn.textContent = "Show related videos";
related.parentNode.insertBefore(btn, related);
btn.onclick = () => {
if (related.style.display === '') { // if displayed
related.style.display = 'none';
btn.textContent = 'Show related videos';
btn.classList.remove('yt-spec-button-shape-next__button-text-content');
btn.classList.add('yt-spec-button-shape-next--filled');
btn.style.backgroundColor = "#000000";
} else {
related.style.display = '';
btn.textContent = 'Hide related videos';
btn.classList.add('yt-spec-button-shape-next__button-text-content');
btn.classList.remove('yt-spec-button-shape-next--filled');
btn.style.backgroundColor = "#99bbff";
}
}
}
}
window.onload = initializePage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment