Open spotify keyboard controls

control open spotify with the keyboard

  1. // ==UserScript==
  2. // @name Open spotify keyboard controls
  3. // @namespace http://digfish.org/
  4. // @version 0.1
  5. // @description control open spotify with the keyboard
  6. // @author digfish
  7. // @match *.spotify.*
  8. // @grant none
  9. // @include https://*.spotify.*/*
  10. // @match http://*.spotify.*/*
  11. // @match https:/*.spotify.*/*
  12. // @copyright digfish, based on ${4:Gustavo Keener}
  13. // @debugger
  14. // @require http://code.jquery.com/jquery-1.8.0.min.js
  15. // ==/UserScript==
  16.  
  17. // Add jQuery, unless it already exists
  18.  
  19. if(typeof jQuery === 'undefined'|| !jQuery){
  20. (function(){
  21. var s=document.createElement('script');
  22. s.setAttribute('src','https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js');
  23. if(typeof jQuery=='undefined'){
  24. document.getElementsByTagName('head')[0].appendChild(s);
  25. console.log('jQuery inject userscript: LOADED jQuery via userscript');
  26. } else {
  27. console.log('jQuery inject userscript: jQuery WAS NOT LOADED via userscript');
  28.  
  29. }
  30. })();
  31. }
  32.  
  33. (function() {
  34. // 'use strict';
  35.  
  36. console.log('Loading Script Open Spotify keyboard controls!');
  37. $('body').keyup(function(evt) {
  38.  
  39. console.log('Pressed on key:', evt.which);
  40. // fast forward is not reacting... and to catch volume keys impossible, unless you use
  41. // the usual Fx key functions...
  42. if (evt.which == 179 ) { // F7 Play-Pause
  43. $('button.control-button.spoticon-pause-16').click();
  44. $('button.control-button.spoticon-play-16').click();
  45. } else if (evt.which == 177) { // F6 rewind
  46. $('.spoticon-skip-forward-16').click();
  47. }
  48. });
  49.  
  50.  
  51.  
  52.  
  53.  
  54. })();