From 32e18a6f289700e5747c9fab705407f4152d2736 Mon Sep 17 00:00:00 2001 From: Pasu Chan Chak Shing Date: Sun, 13 May 2018 21:59:21 +0800 Subject: [PATCH 1/8] Add "Reset to Defaults" Option in Popup UI, Fix #10004 --- chromium/background-scripts/background.js | 8 ++++++++ chromium/pages/popup/index.html | 4 ++++ chromium/pages/popup/ux.js | 5 ++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/chromium/background-scripts/background.js b/chromium/background-scripts/background.js index 9e8392a773ec..988b4f8c836e 100644 --- a/chromium/background-scripts/background.js +++ b/chromium/background-scripts/background.js @@ -713,6 +713,14 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){ sendResponse(true); }); return true; + } else if (message.type == "reset_to_defaults") { + // restore the 'default states' of the rulesets + store.set_promise('ruleActiveStates', {}).then(() => { + // clear the caches such that it becomes stateless + destroy_caches(); + // re-activate all rules according to the new states + initializeAllRules(); + }); } else if (message.type == "add_new_rule") { all_rules.addNewRuleAndStore(message.object).then(() => { sendResponse(true); diff --git a/chromium/pages/popup/index.html b/chromium/pages/popup/index.html index 5dbd92ad9faa..063bab85ca9c 100644 --- a/chromium/pages/popup/index.html +++ b/chromium/pages/popup/index.html @@ -24,6 +24,10 @@

+
+ +
+
diff --git a/chromium/pages/popup/ux.js b/chromium/pages/popup/ux.js index 1090d7687f76..22330f838c42 100644 --- a/chromium/pages/popup/ux.js +++ b/chromium/pages/popup/ux.js @@ -158,8 +158,11 @@ document.addEventListener("DOMContentLoaded", function () { // Set up the enabled/disabled switch & hide/show rules updateEnabledDisabledUI(); - document.getElementById('onoffswitch').addEventListener('click', toggleEnabledDisabled); + e('onoffswitch').addEventListener('click', toggleEnabledDisabled); e('http-nowhere-checkbox').addEventListener('click', toggleHttpNowhere, false); + e('reset-to-defaults').addEventListener('click', function() { + sendMessage("reset_to_defaults"); + }); // Print the extension's current version. var the_manifest = chrome.runtime.getManifest(); From 98185913d13e30d7cfd1c0f08df141f8775f5666 Mon Sep 17 00:00:00 2001 From: Pasu Chan Chak Shing Date: Sun, 13 May 2018 22:09:21 +0800 Subject: [PATCH 2/8] Fix Travis errors with eslint (indentation) --- chromium/background-scripts/background.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chromium/background-scripts/background.js b/chromium/background-scripts/background.js index 988b4f8c836e..afa5a205c6fb 100644 --- a/chromium/background-scripts/background.js +++ b/chromium/background-scripts/background.js @@ -716,11 +716,11 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){ } else if (message.type == "reset_to_defaults") { // restore the 'default states' of the rulesets store.set_promise('ruleActiveStates', {}).then(() => { - // clear the caches such that it becomes stateless - destroy_caches(); - // re-activate all rules according to the new states - initializeAllRules(); - }); + // clear the caches such that it becomes stateless + destroy_caches(); + // re-activate all rules according to the new states + initializeAllRules(); + }); } else if (message.type == "add_new_rule") { all_rules.addNewRuleAndStore(message.object).then(() => { sendResponse(true); From 7dd13043fb38750ca78019b2347080ca29beb8eb Mon Sep 17 00:00:00 2001 From: Pasu Chan Chak Shing Date: Sun, 13 May 2018 22:19:41 +0800 Subject: [PATCH 3/8] Small, cosmestic changes on coding styles --- chromium/pages/popup/ux.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/chromium/pages/popup/ux.js b/chromium/pages/popup/ux.js index 22330f838c42..873729a659d0 100644 --- a/chromium/pages/popup/ux.js +++ b/chromium/pages/popup/ux.js @@ -96,7 +96,7 @@ function showHttpNowhereUI() { // Change the UI to reflect extension enabled/disabled function updateEnabledDisabledUI() { getOption_('globalEnabled', true, function(item) { - document.getElementById('onoffswitch').checked = item.globalEnabled; + e('onoffswitch').checked = item.globalEnabled; e('disableButton').style.visibility = "visible"; // Hide or show the rules sections if (item.globalEnabled) { @@ -110,7 +110,7 @@ function updateEnabledDisabledUI() { // Toggle extension enabled/disabled status function toggleEnabledDisabled() { - var extension_toggle_effect = function(){ + var extension_toggle_effect = function() { updateEnabledDisabledUI(); // The extension state changed, so reload this tab. chrome.tabs.reload(); @@ -152,24 +152,24 @@ function gotTab(activeTab) { * Fill in content into the popup on load */ document.addEventListener("DOMContentLoaded", function () { - stableRules = document.getElementById("StableRules"); - unstableRules = document.getElementById("UnstableRules"); + stableRules = e("StableRules"); + unstableRules = e("UnstableRules"); getTab(gotTab); // Set up the enabled/disabled switch & hide/show rules updateEnabledDisabledUI(); e('onoffswitch').addEventListener('click', toggleEnabledDisabled); e('http-nowhere-checkbox').addEventListener('click', toggleHttpNowhere, false); - e('reset-to-defaults').addEventListener('click', function() { + e('reset-to-defaults').addEventListener('click', () => { sendMessage("reset_to_defaults"); }); // Print the extension's current version. var the_manifest = chrome.runtime.getManifest(); - var version_info = document.getElementById('current-version'); + var version_info = e('current-version'); version_info.innerText = the_manifest.version; - let rulesets_versions = document.getElementById('rulesets-versions'); + let rulesets_versions = e('rulesets-versions'); sendMessage("get_ruleset_timestamps", null, timestamps => { for(let [update_channel, timestamp] of timestamps){ if(timestamp > 0){ From 2a36707e6a677d86b6366073c41a346738094efc Mon Sep 17 00:00:00 2001 From: Pasu Chan Chak Shing Date: Sun, 13 May 2018 22:36:01 +0800 Subject: [PATCH 4/8] Reload tabs when operations completed --- chromium/background-scripts/background.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chromium/background-scripts/background.js b/chromium/background-scripts/background.js index afa5a205c6fb..40ccdd146784 100644 --- a/chromium/background-scripts/background.js +++ b/chromium/background-scripts/background.js @@ -720,6 +720,8 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){ destroy_caches(); // re-activate all rules according to the new states initializeAllRules(); + // reload tabs when operations completed + chrome.tabs.reload(); }); } else if (message.type == "add_new_rule") { all_rules.addNewRuleAndStore(message.object).then(() => { From b95bfd035e718a626544218016e78150c9a5e965 Mon Sep 17 00:00:00 2001 From: Pasu Chan Chak Shing Date: Tue, 22 May 2018 10:01:26 +0800 Subject: [PATCH 5/8] Add confirmation dialog to avoid accidental clicks --- chromium/pages/popup/ux.js | 4 +++- src/chrome/locale/en/https-everywhere.dtd | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/chromium/pages/popup/ux.js b/chromium/pages/popup/ux.js index 873729a659d0..937450747e37 100644 --- a/chromium/pages/popup/ux.js +++ b/chromium/pages/popup/ux.js @@ -161,7 +161,9 @@ document.addEventListener("DOMContentLoaded", function () { e('onoffswitch').addEventListener('click', toggleEnabledDisabled); e('http-nowhere-checkbox').addEventListener('click', toggleHttpNowhere, false); e('reset-to-defaults').addEventListener('click', () => { - sendMessage("reset_to_defaults"); + if (confirm(chrome.i18n.getMessage("prefs_reset_defaults_message"))) { + sendMessage("reset_to_defaults"); + } }); // Print the extension's current version. diff --git a/src/chrome/locale/en/https-everywhere.dtd b/src/chrome/locale/en/https-everywhere.dtd index d5094d06529b..1e71f2b42efe 100644 --- a/src/chrome/locale/en/https-everywhere.dtd +++ b/src/chrome/locale/en/https-everywhere.dtd @@ -23,6 +23,7 @@ + From 3cbf265b41c779d285459fe48b16eb3309f11b56 Mon Sep 17 00:00:00 2001 From: Pasu Chan Chak Shing Date: Tue, 22 May 2018 10:06:18 +0800 Subject: [PATCH 6/8] Move "Reset to Defaults" link below the rules sections --- chromium/pages/popup/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chromium/pages/popup/index.html b/chromium/pages/popup/index.html index 063bab85ca9c..21dac9971bb7 100644 --- a/chromium/pages/popup/index.html +++ b/chromium/pages/popup/index.html @@ -24,10 +24,6 @@

-
- -
-
@@ -63,6 +59,10 @@

+ +
+ +