From b5fe0a63dc3c9f47a7052950f8b0169b524fbde5 Mon Sep 17 00:00:00 2001 From: maximelebreton Date: Wed, 23 Oct 2013 17:59:22 +0200 Subject: [PATCH] Shortcut Added ! --- core.js | 35 ++++++++++++++++++++++++++--------- manifest.json | 10 +++++++++- updates.xml | 2 +- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/core.js b/core.js index 6ae3153..d5ed55c 100644 --- a/core.js +++ b/core.js @@ -10,7 +10,7 @@ var prefs; var contextMenuId = null; var chromeContentSettings = chrome.contentSettings; -/* currently (chrome 16), infobars is not implemented (only experimental...) */ +/* currently, infobars is not implemented (only experimental...) */ var chromeInfobars = chrome.infobars; @@ -53,6 +53,14 @@ if(chromeContentSettings) { chrome.browserAction.onClicked.addListener(changeSettings); + + chrome.commands.onCommand.addListener(function(command) { + if (command == "toggle-qjs") { + changeSettings(); + } + }); + + } else { chrome.browserAction.onClicked.addListener(openJsPanel.call()); } @@ -75,12 +83,13 @@ function getSettings() { function(details) { //console.info("Current tab settings : "+url); url ? matchForbiddenOrigin = url.match(forbiddenOrigin,'') : matchForbiddenOrigin = true; - matchForbiddenOrigin ? updateIcon("inactive") : updateIcon(details.setting); + matchForbiddenOrigin ? updateIcon("inactive") : updateIcon(details.setting); }); }); } function changeSettings() { + if (!matchForbiddenOrigin) { chromeContentSettings.javascript.get({ 'primaryUrl': url, @@ -98,15 +107,17 @@ function changeSettings() { 'primaryPattern': pattern, 'setting': newSetting, 'scope': (incognito ? 'incognito_session_only' : 'regular') - }); - - updateIcon(newSetting); + }, function() { - if (prefs.autoRefresh) { - chrome.tabs.reload(tabId); - } + updateIcon(newSetting); - setLocalStorageRule(pattern, newSetting); + if (prefs.autoRefresh) { + chrome.tabs.reload(tabId); + } + + setLocalStorageRule(pattern, newSetting); + + }); //console.info("javascript is now "+newSetting+"ed on "+pattern); } @@ -125,6 +136,7 @@ function changeSettings() { } } + } @@ -149,6 +161,9 @@ function setLocalStorageRule(pattern, newSetting) { } if (!keyExist) { + + // to do : keep only block, only allow or both + rules.push({ 'primaryPattern': pattern, 'setting': newSetting, @@ -166,6 +181,8 @@ function importRules(localStorageRules) { var rules = localStorageRules; + // todo : delete spaces + if (rules.length) { for(i = 0; i < rules.length; i++) { diff --git a/manifest.json b/manifest.json index 51d6488..1100207 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { "name" : "Quick Javascript Switcher" -, "version" : "1.3.0" +, "version" : "1.3.1" , "minimum_chrome_version": "16.0" , "manifest_version" : 2 , "homepage_url" : "https://github.com/maximelebreton/quick-javascript-switcher" @@ -28,5 +28,13 @@ { "page": "background.html" } , "options_page" : "options.html" + +, "commands": { + "toggle-qjs": { + "suggested_key": { "default": "Alt+Shift+Q" }, + "description": "Toggle JavaScript" + } + } + } diff --git a/updates.xml b/updates.xml index 0223a04..e2086a9 100644 --- a/updates.xml +++ b/updates.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file