Skip to content

Instantly share code, notes, and snippets.

@aleclarson
Last active February 8, 2025 19:56
Show Gist options
  • Save aleclarson/d9c5afe4d87fd39a5c0fa60cadaeadd5 to your computer and use it in GitHub Desktop.
Save aleclarson/d9c5afe4d87fd39a5c0fa60cadaeadd5 to your computer and use it in GitHub Desktop.
YouTube feedback shortcut – TamperMonkey
// ==UserScript==
// @name YouTube Enhanced Interaction
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Enhanced click handling for YouTube recommendations
// @author You
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
document.addEventListener('click', async (event) => {
// Skip if ctrl or meta (command) key is pressed
if (event.ctrlKey || event.metaKey) {
return;
}
// Only proceed if alt key is pressed
if (!event.altKey) {
return;
}
// Check if click target is within or is a ytd-rich-item-renderer
let richItem = event.target.closest('ytd-rich-item-renderer, ytd-compact-video-renderer');
if (!richItem) {
const enclosingLink = event.target.closest('a[href^="/watch?"]');
const parsedLink = new URL(enclosingLink.href);
for (const link of document.querySelectorAll(`a[href^="/watch${parsedLink.search}"]`)) {
richItem = link.closest('ytd-rich-item-renderer, ytd-compact-video-renderer');
if (richItem) {
break;
}
}
if (!richItem) {
alert('No rich item found');
return;
}
}
event.preventDefault();
event.stopPropagation();
// Find and click the feedback shape
const menuButton = richItem.querySelector('yt-touch-feedback-shape, button[aria-label="Action menu"]');
if (!menuButton) {
alert('No menu button found');
return;
}
menuButton.click();
// Wait for popup to appear
await new Promise(resolve => setTimeout(resolve, 300));
// Find popup container
const popupContainer = document.querySelector('ytd-popup-container');
if (!popupContainer) {
alert('No popup container found');
return;
}
const menuPopup = popupContainer.querySelector('ytd-menu-popup-renderer, yt-contextual-sheet-layout');
if (!menuPopup) {
alert('No menu popup found');
return;
}
// Get all list items
const menuItems = popupContainer.querySelectorAll('yt-list-item-view-model, ytd-menu-service-item-renderer');
// Determine which text to look for based on key combination
const targetText = event.shiftKey ? "Don't recommend channel" : "Not interested";
// Find and click the matching item
for (const item of menuItems) {
if (item.textContent.includes(targetText)) {
item.click();
break;
}
}
}, /* capture */ true);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment