From a485267da8cb20edeedecad4e19a765da948fe73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Tue, 2 Mar 2021 14:53:06 +0100 Subject: [PATCH] Set activated icon only when a username is filled --- chrome_addon/background.js | 20 +++---- chrome_addon/compat.js | 5 ++ chrome_addon/lib/main.js | 104 +++++++++++++++++++++++++------------ chrome_addon/lib/misc.js | 4 -- 4 files changed, 82 insertions(+), 51 deletions(-) diff --git a/chrome_addon/background.js b/chrome_addon/background.js index 5b185ec..fd6453e 100644 --- a/chrome_addon/background.js +++ b/chrome_addon/background.js @@ -234,6 +234,8 @@ function update_gpass_icon(iconId, tabId) break; default: } + + debug(icon_name); icon_infos["path"] = { 16:"icons/gpass" + icon_name + "_icon_16.png", @@ -302,6 +304,7 @@ function _query_tabs_update_icon(tabs, iconId) function gpass_switch_enable(tab) { + debug("Switch enable"); is_gpass_enabled(tab.url).then( function (key_present) { @@ -361,15 +364,6 @@ function extension_load() }); return true; } - else if (request.type == "switch_enable") - { - debug("Switch enable"); - browser.tabs.query({active:true, currentWindow:true}, - function cb(tabs) { - _query_tabs_switch_enable(tabs, sendResponse) - }); - return true; - } else if (request.type == "update_icon") { debug("update_icon"); @@ -396,9 +390,9 @@ function extension_load() /* Not supported by Chrome */ if (browser.menus.onShown) - title = 'disable gPass for this website'; + title = 'Disable gPass for this website'; else - title = 'disable or enable gPass for this website'; + title = 'Disable or enable gPass for this website'; browser.menus.create({ id: 'switch_enable', @@ -428,9 +422,9 @@ function extension_load() function (key_present) { enabled = (key_present == null); if (enabled) - title = 'disable gPass for this website'; + title = 'Disable gPass for this website'; else - title = 'enable gPass for this website'; + title = 'Enable gPass for this website'; browser.menus.update("switch_enable", { "title":title diff --git a/chrome_addon/compat.js b/chrome_addon/compat.js index 729d202..575f931 100644 --- a/chrome_addon/compat.js +++ b/chrome_addon/compat.js @@ -17,6 +17,11 @@ along with gPass. If not, see . */ +var default_preferences = {"pbkdf2_level": 1000, + "account_url": "https://gpass-demo.soutade.fr/demo", + "always_disabled":false + }; + function get_preference(key) { // Inspired from https://github.com/akiomik/chrome-storage-promise/ diff --git a/chrome_addon/lib/main.js b/chrome_addon/lib/main.js index ea39299..3f4cf33 100644 --- a/chrome_addon/lib/main.js +++ b/chrome_addon/lib/main.js @@ -56,23 +56,35 @@ function try_get_name(fields, type_filters, match) for (var i=0; i && + type_filters.push("text"); + type_filters.push("email"); + if (all_logins) + logins = try_get_name(fields, type_filters, true); + else + { + // Get all other fields except text, email and password + type_filters.push("password"); + type_filters.push("hidden"); + logins = try_get_name(fields, type_filters, false); + } + + return logins; +} + function on_focus(e) { - if (gpass_enabled) + if (!gpass_enabled) + return; + + var logins = get_logins(this.form, true); + var all_logins = get_logins(this.form, false); + + if (logins.length || all_logins.length) { - parameters = { + parameters = { type:"update_icon", icon_id:GPASS_ICON.ACTIVATED, - }; - browser.runtime.sendMessage(parameters, {}); + }; + browser.runtime.sendMessage(parameters, {}); } } function on_blur(e) { - if (gpass_enabled) - { - parameters = { - type:"update_icon", - icon_id:GPASS_ICON.NORMAL, - }; - browser.runtime.sendMessage(parameters, {}); - } + if (!gpass_enabled) + return; + + parameters = { + type:"update_icon", + icon_id:GPASS_ICON.NORMAL, + }; + browser.runtime.sendMessage(parameters, {}); } function on_sumbit(e) @@ -116,15 +159,8 @@ function on_sumbit(e) debug("on_submit"); - type_filters = new Array(); - // Get all && - type_filters.push("text"); - type_filters.push("email"); - logins = try_get_name(fields, type_filters, true); - - // Get all other fields except text, email and password - type_filters.push("password"); - all_logins = try_get_name(fields, type_filters, false); + logins = get_logins(form, true); + all_logins = get_logins(form, false); if (!logins.length) logins = all_logins; diff --git a/chrome_addon/lib/misc.js b/chrome_addon/lib/misc.js index aa891d7..a441a1e 100644 --- a/chrome_addon/lib/misc.js +++ b/chrome_addon/lib/misc.js @@ -22,10 +22,6 @@ var DEBUG = false; SERVER = {OK : 0, FAILED : 1, RESTART_REQUEST : 2}; GPASS_ICON = {NORMAL:0, DISABLED:1, ACTIVATED:2}; -var default_preferences = {"pbkdf2_level": 1000, - "account_url": "https://gpass-demo.soutade.fr/demo", - "crypto_v1_compatible": true}; - var browser = browser || chrome; var crypto = crypto || window.crypto;