X-Git-Url: https://git.wh0rd.org/?p=chrome-ext%2Fmusic-player-client.git;a=blobdiff_plain;f=main.js;h=16875983968fd05b34c142910747a369b2bb5517;hp=1466bded59d7192b0a094b2c4bea70254d47cb39;hb=ccfc12deb15558bccd7d1c5a586fef5b86d386ea;hpb=650b9e7b55fa66426318c67b20f6c0cf82faac27 diff --git a/main.js b/main.js index 1466bde..1687598 100644 --- a/main.js +++ b/main.js @@ -61,17 +61,23 @@ window.onload = function() { }; window.onkeypress = function(e) { + if (e.target != document.body) { + /* Only allow the shortcuts when the focus is on the body. + Otherwise you can't type these numbers into text fields. */ + return; + } + switch (e.keyCode) { case 49: // 1 show_page('controls'); break; - case 50: // 1 + case 50: // 2 show_page('metadata'); break; - case 51: // 1 + case 51: // 3 show_page('playlist'); break; - case 52: // 1 + case 52: // 4 show_page('options'); break; } @@ -157,12 +163,15 @@ function show_page(page) { if (typeof(page) != 'string') page = this.id.split('.')[1]; + // We might not be connected in which case 'mpc' will be undefined. switch (page) { case 'playlist': - mpc.playlistinfo(); + if (mpc) + mpc.playlistinfo(); // Fallthrough. case 'metadata': - mpc.currentsong(); + if (mpc) + mpc.currentsong(); break; }