Set activated icon only when a username is filled

This commit is contained in:
Grégory Soutadé 2021-03-02 14:53:06 +01:00
parent 267a809019
commit a485267da8
4 changed files with 82 additions and 51 deletions

View File

@ -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

View File

@ -17,6 +17,11 @@
along with gPass. If not, see <http://www.gnu.org/licenses/>.
*/
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/

View File

@ -56,23 +56,35 @@ function try_get_name(fields, type_filters, match)
for (var i=0; i<fields.length; i++)
{
var field = fields[i];
var to_test = !match;
for (var a=0; a<type_filters.length; a++)
{
if ((match && field.getAttribute("type") == type_filters[a]) ||
(!match && field.getAttribute("type") != type_filters[a]))
{
if (field.hasAttribute("name") && field.value != "")
{
name = field.getAttribute("name");
// Subset of common user field
if (name == "user") user = field.value;
else if (name == "usr") user = field.value;
else if (name == "username") user = field.value;
else if (name == "login") user = field.value;
if (match && field.getAttribute("type") == type_filters[a])
{
to_test = true;
break;
}
_add_name(all_logins, field.value);
}
if(!match && field.getAttribute("type") == type_filters[a])
{
to_test = false;
break;
}
}
if (to_test)
{
if (field.hasAttribute("name") && field.value != "")
{
name = field.getAttribute("name");
// Subset of common user field
if (name == "user") user = field.value;
else if (name == "usr") user = field.value;
else if (name == "username") user = field.value;
else if (name == "login") user = field.value;
_add_name(all_logins, field.value);
}
}
}
@ -83,28 +95,59 @@ function try_get_name(fields, type_filters, match)
return all_logins;
}
function get_logins(form, all_logins)
{
var fields = form.getElementsByTagName("input");
var logins = null;
debug("get_logins");
var type_filters = new Array();
// Get all <input type="text"> && <input type="email">
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 <input type="text"> && <input type="email">
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;

View File

@ -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;