Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name YT Full Like Dislike Rewind
- // @namespace http://tampermonkey.net/
- // @version 2025-02-23
- // @description try to take over the world!
- // @author You
- // @match https://www.youtube.com/*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- document.addEventListener('keydown', function(event) {
- console.dir(event);
- var yts;
- if (event.altKey && event.key === ']') {
- //Like the ***currently visible*** YouTube Short
- //
- //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.
- yts = [...document.querySelectorAll("ytd-toggle-button-renderer#like-button button")].filter(cv => cv.getBoundingClientRect().top > 0 & cv.getBoundingClientRect().top < window.innerHeight);
- if (yts.length > 0) {
- yts[0].click();
- }
- //Like regular YouTube video
- var ytr = [...document.querySelectorAll("like-button-view-model .yt-spec-touch-feedback-shape__fill")];
- if (ytr.length > 0) {
- ytr[0].click();
- }
- }
- if (event.altKey && event.key === '[') {
- //Dislike currently visible YouTube Short
- //
- //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.
- yts = [...document.querySelectorAll("ytd-toggle-button-renderer#dislike-button button")].filter(cv => cv.getBoundingClientRect().top > 0 & cv.getBoundingClientRect().top < window.innerHeight);
- if (yts.length > 0) {
- //document.querySelector("dislike-button-view-model button").click();
- yts[0].click();
- }
- //Dislike regular YouTube video
- else {
- [...document.querySelectorAll("dislike-button-view-model .yt-spec-touch-feedback-shape__fill")][0].click();
- }
- }
- //Rewind 5 secs
- if (event.altKey && event.key === 'j') {
- Array.from(document.querySelectorAll("video")).filter(cv => cv.clientHeight > 0)[0].currentTime -= 5;
- }
- if (event.key == 'ArrowLeft' && document.location.pathname.split('/')[1] == "shorts") {
- Array.from(document.querySelectorAll("video")).filter(cv => cv.clientHeight > 0)[0].currentTime -= 5;
- }
- //FF 5 secs
- if (event.key == 'ArrowRight' && document.location.pathname.split('/')[1] == "shorts") {
- Array.from(document.querySelectorAll("video")).filter(cv => cv.clientHeight > 0)[0].currentTime += 5;
- }
- if (event.altKey && event.key === 'l') {
- Array.from(document.querySelectorAll("video")).filter(cv => cv.clientHeight > 0)[0].currentTime += 5;
- }
- //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))
- if (event.key === ',' && [...document.querySelectorAll("ytd-engagement-panel-section-list-renderer")].filter(cv => cv.getBoundingClientRect().top > 0 & cv.getBoundingClientRect().top < window.innerHeight).length == 0) {
- Array.from(document.querySelectorAll("video")).filter(cv => cv.clientHeight > 0)[0].currentTime -= 1;
- }
- if (event.key === '.' && [...document.querySelectorAll("ytd-engagement-panel-section-list-renderer")].filter(cv => cv.getBoundingClientRect().top > 0 & cv.getBoundingClientRect().top < window.innerHeight).length == 0) {
- Array.from(document.querySelectorAll("video")).filter(cv => cv.clientHeight > 0)[0].currentTime += 1;
- }
- //Click menu button for currently visible Short
- //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.
- if (event.altKey && event.key === ';') {
- ([...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();
- }
- //Subscribe to current Short or Video
- //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.
- if (event.altKey && event.key === 's') {
- (([...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) ||
- (document.evaluate("//button/div/span[text()='Subscribed']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null )).snapshotItem(0)
- ).click();
- }
- //***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.
- if (event.altKey && event.key === 'w') {
- (document.querySelectorAll("yt-reel-multi-format-link-view-model a")[0]).click();
- }
- //Clicking on the text in the Short brings up the video description. This keyboard shortcut does that.
- if (event.altKey && event.key === 'i') {
- (document.querySelectorAll("yt-shorts-video-title-view-model h2")[0]).click();
- }
- //Save non-Short video to playlist
- if (event.altKey && event.key === 'a') {
- document.querySelector("button[title='Save']").click();
- }
- //Click the X to close the playlist popup
- if (event.shiftKey && event.code == "KeyX") {
- document.querySelectorAll("yt-icon[icon='close']")[0].click();
- }
- });
- //Show blue background on tab-focused items. Used for testing/debugging and checking that the script is running.
- //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";
- // Your code here...
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement