Greasemonkey script for Logitech Media Server

by Michael Birch

I use the web interface to control LMS on my music server. If the phone rings when I’m working, I can switch to the browser window and hit the spacebar to stop the music.

This script lets you use the keyboard to start and stop the playback (after clicking the play button). The play button is an HTML button element, which means that all that is needed is to give it focus when clicked. Once it has focus, the spacebar or return key will activate a click event.

// ==UserScript==
// @name        Start and Stop
// @grant        none
// @namespace   musicserver
// @include     http://192.168.1.5:9000/
// @version     1
// ==/UserScript==
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
addEvent(window, 'load', startStopFocus);
function startStopFocus (){
  var startStopButton = document.getElementById('ext-gen42');
  startStopButton.addEventListener('click', function() {
    startStopButton.focus();
  });
}
blog comments powered by Disqus