From 87ce723c4f7568b3342f68568b4730aec4f81fb4 Mon Sep 17 00:00:00 2001 From: Deepjyoti Mondal Date: Tue, 31 Jan 2017 00:09:53 +0530 Subject: [PATCH] popup.js:Added keyboard shortcut for selecting category pupup.html:Added title for displaying tooltip text showing keyboard shorcut for categories Now the category checkboxes can be selected using following keyboard shortcuts : Ctrl+Alt+m : toggle music Ctrl+Alt+v : toggle video Ctrl+Alt+b : toggle books Ctrl+Alt+a : select all the categories Hovering mouse over the category labels displays tooltip text showing the key combination for the respective category. The tooltip text is presently shown only in chrome and not in firefox because of a bug (bugzilla id : 1269421) which has been fixed and the feature will be available from firefox 52 (which is in development version now) fixes #88 --- popup.html | 6 +++--- popup.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/popup.html b/popup.html index 9a02a09..509a31f 100644 --- a/popup.html +++ b/popup.html @@ -42,11 +42,11 @@

Fe - + - + - + diff --git a/popup.js b/popup.js index 9f6ba76..4b49488 100644 --- a/popup.js +++ b/popup.js @@ -10,6 +10,40 @@ function suggestionAsValue() { }); } +// Method to keyboard shortcut +function keyboardShortCutListener(e) { + e.preventDefault(); + if (e.ctrlKey && e.altKey && e.keyCode === 77) { + if (document.getElementById("music").checked === true) { + document.getElementById("music").checked = false; + } else { + document.getElementById("music").checked = true; + } + } else if (e.ctrlKey && e.altKey && e.keyCode === 86) { + if (document.getElementById("video").checked === true) { + document.getElementById("video").checked = false; + } else { + document.getElementById("video").checked = true; + } + } else if (e.ctrlKey && e.altKey && e.keyCode === 66) { + if (document.getElementById("books").checked === true) { + document.getElementById("books").checked = false; + } else { + document.getElementById("books").checked = true; + } + } else if (e.ctrlKey && e.altKey && e.keyCode === 65) { + if ((document.getElementById("music").checked === true) && (document.getElementById("video").checked === true) && (document.getElementById("books").checked === true)) { + document.getElementById("music").checked = false; + document.getElementById("video").checked = false; + document.getElementById("books").checked = false; + } else { + document.getElementById("music").checked = true; + document.getElementById("video").checked = true; + document.getElementById("books").checked = true; + } + } +} + function register(event) { var set1; var set2; @@ -108,6 +142,7 @@ function suggestion() { document.addEventListener("DOMContentLoaded", function () { document.querySelector("button").addEventListener("click", register); + document.addEventListener("keyup", keyboardShortCutListener, false); suggestion(); suggestionAsValue(); });