YouTube add to Watch Later shortcut

Simply Alt-Click a video in the YouTube recommendations to immediately add it to Watch Later.

  1. // ==UserScript==
  2. // @name YouTube add to Watch Later shortcut
  3. // @namespace https://greasyfork.org/en/users/1436613-gosha305
  4. // @match https://www.youtube.com/*
  5. // @license MIT
  6. // @version 1.0
  7. // @author gosha305
  8. // @description Simply Alt-Click a video in the YouTube recommendations to immediately add it to Watch Later.
  9. // ==/UserScript==
  10.  
  11.  
  12. document.addEventListener("click", function(event){
  13. if (event.altKey) {
  14. event.preventDefault()
  15. event.stopImmediatePropagation();
  16. clickOnWatchLater(findVideoContainer(event.target))
  17. }
  18. }, true)
  19.  
  20. function findVideoContainer(target){
  21. return (target.closest("#dismissible") || document.querySelector(`[href=\'${target.closest("#media-container-link").getAttribute("href")}\']`).closest("#dismissible"))
  22. }
  23.  
  24. function clickOnWatchLater(element){
  25. (new MutationObserver(function(_,observer){
  26. const watchLaterButton = document.querySelector("ytd-popup-container ytd-menu-service-item-renderer:nth-of-type(2)");
  27. if (watchLaterButton){
  28. watchLaterButton.click()
  29. observer.disconnect()
  30. }
  31. })).observe(document.querySelector("ytd-popup-container"), {subtree: true, attributes:true})
  32. element.querySelector("#button.ytd-menu-renderer > button").click()
  33. }