Next, Previous, and play/pause key shortcuts for bandcamp

Allows the left and right keyboard arrows to be used to go to the previous and next songs on bandcamp.

  1. // ==UserScript==
  2. // @name Next, Previous, and play/pause key shortcuts for bandcamp
  3. // @description Allows the left and right keyboard arrows to be used to go to the previous and next songs on bandcamp.
  4. // @author Zach Saucier
  5. // @namespace https://zachsaucier.com/
  6. // @version 1.2
  7. // @match https://bandcamp.com/*
  8. // @match https://*.bandcamp.com/*
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. window.addEventListener('keydown', (event) => {
  14. console.log(event.code);
  15. switch(event.code) {
  16. case 'ArrowLeft':
  17. if(document.querySelector('.prev-icon'))
  18. document.querySelector('.prev-icon').click();
  19. if(document.querySelector('.prevbutton'))
  20. document.querySelector('.prevbutton').click();
  21. break;
  22. case 'ArrowRight':
  23. if(document.querySelector('.next-icon'))
  24. document.querySelector('.next-icon').click();
  25. if(document.querySelector('.nextbutton'))
  26. document.querySelector('.nextbutton').click();
  27. break;
  28. case 'Space':
  29. if(document.querySelector('.playpause'))
  30. document.querySelector('.playpause').click();
  31. if(document.querySelector('.playbutton'))
  32. document.querySelector('.playbutton').click();
  33. event.preventDefault();
  34. break;
  35. }
  36. }, false);
  37. })();