Youtube Play/Pause Instead of Changing Playback Speed

Pressing space pauses or plays the video without affecting playback speed.

  1. // ==UserScript==
  2. // @name Youtube Play/Pause Instead of Changing Playback Speed
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Pressing space pauses or plays the video without affecting playback speed.
  6. // @author RDJ
  7. // @match *://www.youtube.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. document.addEventListener('keydown', function(event) {
  16. if (event.code === 'Space' && !event.ctrlKey && !event.altKey && !event.shiftKey) {
  17.  
  18. if (event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA' || event.target.isContentEditable) {
  19. return;
  20. }
  21.  
  22. event.preventDefault();
  23. event.stopPropagation();
  24.  
  25. let video = document.querySelector('video');
  26.  
  27. if (video) {
  28. if (video.paused) {
  29. video.play();
  30. } else {
  31. video.pause();
  32. }
  33. }
  34. }
  35. }, true);
  36. })();