YouTube Shorts key controls

Adds key controls to YouTube Shorts

  1. // ==UserScript==
  2. // @name YouTube Shorts key controls
  3. // @version 0.1
  4. // @namespace Violentmonkey Scripts
  5. // @description Adds key controls to YouTube Shorts
  6. // @author CarlosMarques
  7. // @match https://www.youtube.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function(){
  13. let listening2clicks = false;
  14. let mObserver = new MutationObserver(function(mutations){
  15. if(!listening2clicks && document.getElementById("shorts-player").getElementsByTagName("video")[0]){
  16. document.addEventListener("keydown", function(e){
  17. let shortVideo = document.getElementById("shorts-player").getElementsByTagName("video")[0];
  18. switch (e.key){
  19. case 'j':
  20. shortVideo.currentTime = shortVideo.currentTime - 10;
  21. break;
  22. case 'l':
  23. shortVideo.currentTime = shortVideo.currentTime + 10;
  24. break;
  25. case 'ArrowLeft':
  26. shortVideo.currentTime = shortVideo.currentTime - 5;
  27. break;
  28. case 'ArrowRight':
  29. shortVideo.currentTime = shortVideo.currentTime + 5;
  30. break;
  31. }
  32. })
  33. listening2clicks = true;
  34. }
  35. })
  36. mObserver.observe(document.body, {subtree: true, childList: true, characterData: true});
  37. })()