Youtube: Space to Pause

Bind the spacebar to play/pause the video.

  1. // ==UserScript==
  2. // @name Youtube: Space to Pause
  3. // @description Bind the spacebar to play/pause the video.
  4. // @author Chris H (Zren)
  5. // @icon https://youtube.com/favicon.ico
  6. // @namespace http://xshade.ca
  7. // @version 1
  8. // @include http*://*.youtube.com/*
  9. // @include http*://youtube.com/*
  10. // @include http*://*.youtu.be/*
  11. // @include http*://youtu.be/*
  12. // ==/UserScript==
  13.  
  14. window.addEventListener('keydown', function(e) {
  15. var playButton = document.querySelector('button.ytp-play-button');
  16. var isKey = e.keyCode === 32; // Space
  17. var validTarget = e.target === document.body || e.target === document.querySelector('#player-api');
  18. if (validTarget && isKey && playButton) {
  19. e.preventDefault();
  20. playButton.click();
  21. }
  22. });