From 16ee688867cd8bd1eba421e7138c16fb1ed95747 Mon Sep 17 00:00:00 2001 From: Mike Matz Date: Thu, 4 Feb 2010 17:47:58 +0000 Subject: [PATCH] Added support for configurable special key --- addDelicious.js | 11 +++++++++-- options_shortcut.html | 25 +++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/addDelicious.js b/addDelicious.js index f18f0c5..689cade 100644 --- a/addDelicious.js +++ b/addDelicious.js @@ -1,6 +1,7 @@ (function() { var localSettings = { - bookmarkKeyChar: 'D' + bookmarkKeyChar: 'D', + bookmarkSpecialKey: 'alt' }; function getVariableFromLocalStorage(variableName,defaultValue) { @@ -17,12 +18,18 @@ }; getVariableFromLocalStorage('bookmarkKeyChar', localSettings.bookmarkKeyChar); + getVariableFromLocalStorage('bookmarkSpecialKey', localSettings.bookmarkSpecialKey); // Listen for key press window.addEventListener( 'keydown', function(e) { - if (e.which == localSettings.bookmarkKeyChar.charCodeAt(0) && e.altKey) { + if ((e.which == localSettings.bookmarkKeyChar.charCodeAt(0)) + && ( + (localSettings.bookmarkSpecialKey == 'alt' && e.altKey) + || (localSettings.bookmarkSpecialKey == 'ctrl' && e.ctrlKey) + || (localSettings.bookmarkSpecialKey == 'meta' && e.metaKey) + )) { console.log('pressed ^d (or whatever key)'); addDeliciousFromContentScript(); } diff --git a/options_shortcut.html b/options_shortcut.html index 70cadcb..3ae5271 100644 --- a/options_shortcut.html +++ b/options_shortcut.html @@ -11,18 +11,30 @@ $(document).ready(function() { $(window).load(function(){ if(localStorage.getItem("bookmarkKeyChar")) { - var bookmarkKeyChar_stored = localStorage.getItem("bookmarkKeyChar"); + var bookmarkKeyChar_stored = localStorage.getItem("bookmarkKeyChar"), + bookmarkSpecialKey_stored = localStorage.getItem("bookmarkSpecialKey"); $('#bookmarkKeyChar').val(bookmarkKeyChar_stored); + if (bookmarkSpecialKey_stored === null) { + // Default to alt + $('#bookmarkSpeiclaKey').val('alt'); + } else { + $('#bookmarkSpecialKey').val(bookmarkSpecialKey_stored); + } } }); $('#save_options').submit(function(){ - var bookmarkKeyChar = $('#bookmarkKeyChar').val(); + var bookmarkKeyChar = $('#bookmarkKeyChar').val(), + bookmarkSpecialKey = $('#bookmarkSpecialKey').val(); + localStorage.setItem("bookmarkKeyChar", bookmarkKeyChar); + localStorage.setItem("bookmarkSpecialKey", bookmarkSpecialKey); + if(!localStorage.getItem("bookmarkKeyChar")) { alert('Please enter a Keyboard shortcut'); } else { - alert('Keyboard shortcut now set to ' + localStorage.getItem("bookmarkKeyChar")); + alert('Keyboard shortcut now set to ' + localStorage.getItem("bookmarkKeyChar") + ', specialKey set to ' + localStorage.getItem('bookmarkSpecialKey')); } + return false; }); $('#bookmarkKeyChar').keyup(function() { @@ -39,7 +51,12 @@
Keyboard Shortcut: - + +