Last active
February 8, 2025 19:56
-
-
Save aleclarson/d9c5afe4d87fd39a5c0fa60cadaeadd5 to your computer and use it in GitHub Desktop.
Revisions
-
aleclarson revised this gist
Feb 8, 2025 . 1 changed file with 33 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,36 +23,58 @@ } // 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; -
aleclarson created this gist
Feb 8, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ // ==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 const richItem = event.target.closest('ytd-rich-item-renderer'); if (!richItem) { return; } // Find and click the feedback shape const feedbackShape = richItem.querySelector('yt-touch-feedback-shape'); if (feedbackShape) { event.preventDefault(); event.stopPropagation(); feedbackShape.click(); } // Wait for popup to appear await new Promise(resolve => setTimeout(resolve, 100)); // Find popup container const popupContainer = document.querySelector('ytd-popup-container yt-contextual-sheet-layout'); if (!popupContainer) { return; } // Get all list items const listItems = popupContainer.querySelectorAll('yt-list-item-view-model'); // 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 listItems) { if (item.textContent.includes(targetText)) { item.click(); break; } } }, /* capture */ true); })();