Advertisement
Guest User

TamperMonkey YouTube keyboard shortcuts

a guest
Apr 22nd, 2025
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         YT Full Like Dislike Rewind
  3. // @namespace    http://tampermonkey.net/
  4. // @version      2025-02-23
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match        https://www.youtube.com/*
  8. // @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.     'use strict';
  14.     document.addEventListener('keydown', function(event) {
  15.         console.dir(event);
  16.         var yts;
  17.         if (event.altKey && event.key === ']') {
  18.             //Like the ***currently visible*** YouTube Short
  19.             //
  20.             //Although I think YouTube no longer shows the previous and next video's Like/Dislike buttons off screen, they did previously exist.  The clientRect function makes sure we target the buttons for the video visible in the viewport.
  21.             yts = [...document.querySelectorAll("ytd-toggle-button-renderer#like-button button")].filter(cv => cv.getBoundingClientRect().top > 0 & cv.getBoundingClientRect().top < window.innerHeight);
  22.             if (yts.length > 0) {
  23.                 yts[0].click();
  24.             }
  25.             //Like regular YouTube video
  26.             var ytr = [...document.querySelectorAll("like-button-view-model .yt-spec-touch-feedback-shape__fill")];
  27.             if (ytr.length > 0) {
  28.                 ytr[0].click();
  29.             }
  30.         }
  31.         if (event.altKey && event.key === '[') {
  32.             //Dislike currently visible YouTube Short
  33.             //
  34.             //Although I think YouTube no longer shows the previous and next video's Like/Dislike buttons off screen, they did previously exist.  The clientRect function makes sure we target the buttons for the video visible in the viewport.
  35.             yts = [...document.querySelectorAll("ytd-toggle-button-renderer#dislike-button button")].filter(cv => cv.getBoundingClientRect().top > 0 & cv.getBoundingClientRect().top < window.innerHeight);
  36.             if (yts.length > 0) {
  37.                 //document.querySelector("dislike-button-view-model button").click();
  38.                 yts[0].click();
  39.             }
  40.             //Dislike regular YouTube video
  41.             else {
  42.                 [...document.querySelectorAll("dislike-button-view-model .yt-spec-touch-feedback-shape__fill")][0].click();
  43.             }
  44.         }
  45.         //Rewind 5 secs
  46.         if (event.altKey && event.key === 'j') {
  47.             Array.from(document.querySelectorAll("video")).filter(cv => cv.clientHeight > 0)[0].currentTime -= 5;
  48.         }
  49.         if (event.key == 'ArrowLeft' && document.location.pathname.split('/')[1] == "shorts") {
  50.             Array.from(document.querySelectorAll("video")).filter(cv => cv.clientHeight > 0)[0].currentTime -= 5;
  51.         }
  52.         //FF 5 secs
  53.         if (event.key == 'ArrowRight' && document.location.pathname.split('/')[1] == "shorts") {
  54.             Array.from(document.querySelectorAll("video")).filter(cv => cv.clientHeight > 0)[0].currentTime += 5;
  55.         }
  56.         if (event.altKey && event.key === 'l') {
  57.             Array.from(document.querySelectorAll("video")).filter(cv => cv.clientHeight > 0)[0].currentTime += 5;
  58.         }
  59.         //Rewind or Skip 1 second in Shorts  using the '<' and '>' keys (as long as you don't have the comments box open (so you can use puncuation in your comments without screwing up the video))
  60.         if (event.key === ',' && [...document.querySelectorAll("ytd-engagement-panel-section-list-renderer")].filter(cv => cv.getBoundingClientRect().top > 0 & cv.getBoundingClientRect().top < window.innerHeight).length == 0) {
  61.             Array.from(document.querySelectorAll("video")).filter(cv => cv.clientHeight > 0)[0].currentTime -= 1;
  62.         }
  63.         if (event.key === '.' && [...document.querySelectorAll("ytd-engagement-panel-section-list-renderer")].filter(cv => cv.getBoundingClientRect().top > 0 & cv.getBoundingClientRect().top < window.innerHeight).length == 0) {
  64.             Array.from(document.querySelectorAll("video")).filter(cv => cv.clientHeight > 0)[0].currentTime += 1;
  65.         }
  66.         //Click menu button for currently visible Short
  67.         //This gives you the ability to select menu items such as "Description", "Save to Playlist", toggle "Ambient Mode", toggle "Captions", etc.  You can use Arrow Up/Down or Tab to highlight the menu item and Space/Enter to click it.
  68.         if (event.altKey && event.key === ';') {
  69.              ([...document.querySelectorAll("#menu-button button")].filter(cv => cv.getBoundingClientRect().top > 0 & cv.getBoundingClientRect().top < window.innerHeight)[0] || document.querySelector("button[aria-label='More actions']")).click();
  70.         }
  71.         //Subscribe to current Short or Video
  72.         //If it's a Video, it shows the menu that gives you the choice of All, Personalized, None, or Unsubscribe, rather than just performing the default "Subscribed" option that clicking the button does.
  73.         if (event.altKey && event.key === 's') {
  74.             (([...document.querySelectorAll("yt-subscribe-button-view-model button")].filter(cv => cv.getBoundingClientRect().top > 0 & cv.getBoundingClientRect().top < window.innerHeight))[0] || (document.evaluate("//span[text()='Subscribed']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null )).snapshotItem(0) ||
  75.              (document.evaluate("//button/div/span[text()='Subscribed']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null )).snapshotItem(0)
  76.             ).click();
  77.         }
  78.         //***Some*** YouTube Shorts have text on a seperate line, which is preceeded by a "▶".  Clicking that text takes you either to the FULL video that this Short is taken from ***OR*** to another Short from this author.  This clicks that link.
  79.         if (event.altKey && event.key === 'w') {
  80.             (document.querySelectorAll("yt-reel-multi-format-link-view-model a")[0]).click();
  81.         }
  82.         //Clicking on the text in the Short brings up the video description.  This keyboard shortcut does that.
  83.         if (event.altKey && event.key === 'i') {
  84.             (document.querySelectorAll("yt-shorts-video-title-view-model h2")[0]).click();
  85.         }
  86.         //Save non-Short video to playlist
  87.         if (event.altKey && event.key === 'a') {
  88.             document.querySelector("button[title='Save']").click();
  89.         }
  90.         //Click the X to close the playlist popup
  91.         if (event.shiftKey && event.code == "KeyX") {
  92.             document.querySelectorAll("yt-icon[icon='close']")[0].click();
  93.         }
  94.     });
  95.  
  96.     //Show blue background on tab-focused items.  Used for testing/debugging and checking that the script is running.
  97.     //Array.from([...document.styleSheets].filter(cv => cv.href == document.querySelectorAll("style.global_styles")[0].previousSibling.href)[0].cssRules).filter(cv => cv.selectorText == ".yt-spec-button-shape-next--mono.yt-spec-button-shape-next--focused")[0].style.background = "blue";
  98.  
  99.  
  100.     // Your code here...
  101. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement