Set activated icon only when a username is filled
This commit is contained in:
parent
267a809019
commit
a485267da8
|
@ -234,6 +234,8 @@ function update_gpass_icon(iconId, tabId)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug(icon_name);
|
||||||
|
|
||||||
icon_infos["path"] = {
|
icon_infos["path"] = {
|
||||||
16:"icons/gpass" + icon_name + "_icon_16.png",
|
16:"icons/gpass" + icon_name + "_icon_16.png",
|
||||||
|
@ -302,6 +304,7 @@ function _query_tabs_update_icon(tabs, iconId)
|
||||||
|
|
||||||
function gpass_switch_enable(tab)
|
function gpass_switch_enable(tab)
|
||||||
{
|
{
|
||||||
|
debug("Switch enable");
|
||||||
is_gpass_enabled(tab.url).then(
|
is_gpass_enabled(tab.url).then(
|
||||||
function (key_present)
|
function (key_present)
|
||||||
{
|
{
|
||||||
|
@ -361,15 +364,6 @@ function extension_load()
|
||||||
});
|
});
|
||||||
return true;
|
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")
|
else if (request.type == "update_icon")
|
||||||
{
|
{
|
||||||
debug("update_icon");
|
debug("update_icon");
|
||||||
|
@ -396,9 +390,9 @@ function extension_load()
|
||||||
|
|
||||||
/* Not supported by Chrome */
|
/* Not supported by Chrome */
|
||||||
if (browser.menus.onShown)
|
if (browser.menus.onShown)
|
||||||
title = 'disable gPass for this website';
|
title = 'Disable gPass for this website';
|
||||||
else
|
else
|
||||||
title = 'disable or enable gPass for this website';
|
title = 'Disable or enable gPass for this website';
|
||||||
|
|
||||||
browser.menus.create({
|
browser.menus.create({
|
||||||
id: 'switch_enable',
|
id: 'switch_enable',
|
||||||
|
@ -428,9 +422,9 @@ function extension_load()
|
||||||
function (key_present) {
|
function (key_present) {
|
||||||
enabled = (key_present == null);
|
enabled = (key_present == null);
|
||||||
if (enabled)
|
if (enabled)
|
||||||
title = 'disable gPass for this website';
|
title = 'Disable gPass for this website';
|
||||||
else
|
else
|
||||||
title = 'enable gPass for this website';
|
title = 'Enable gPass for this website';
|
||||||
browser.menus.update("switch_enable",
|
browser.menus.update("switch_enable",
|
||||||
{
|
{
|
||||||
"title":title
|
"title":title
|
||||||
|
|
|
@ -17,6 +17,11 @@
|
||||||
along with gPass. If not, see <http://www.gnu.org/licenses/>.
|
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)
|
function get_preference(key)
|
||||||
{
|
{
|
||||||
// Inspired from https://github.com/akiomik/chrome-storage-promise/
|
// Inspired from https://github.com/akiomik/chrome-storage-promise/
|
||||||
|
|
|
@ -56,23 +56,35 @@ function try_get_name(fields, type_filters, match)
|
||||||
for (var i=0; i<fields.length; i++)
|
for (var i=0; i<fields.length; i++)
|
||||||
{
|
{
|
||||||
var field = fields[i];
|
var field = fields[i];
|
||||||
|
var to_test = !match;
|
||||||
|
|
||||||
for (var a=0; a<type_filters.length; a++)
|
for (var a=0; a<type_filters.length; a++)
|
||||||
{
|
{
|
||||||
if ((match && field.getAttribute("type") == type_filters[a]) ||
|
if (match && field.getAttribute("type") == type_filters[a])
|
||||||
(!match && field.getAttribute("type") != type_filters[a]))
|
{
|
||||||
{
|
to_test = true;
|
||||||
if (field.hasAttribute("name") && field.value != "")
|
break;
|
||||||
{
|
}
|
||||||
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);
|
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;
|
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)
|
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",
|
type:"update_icon",
|
||||||
icon_id:GPASS_ICON.ACTIVATED,
|
icon_id:GPASS_ICON.ACTIVATED,
|
||||||
};
|
};
|
||||||
browser.runtime.sendMessage(parameters, {});
|
browser.runtime.sendMessage(parameters, {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_blur(e)
|
function on_blur(e)
|
||||||
{
|
{
|
||||||
if (gpass_enabled)
|
if (!gpass_enabled)
|
||||||
{
|
return;
|
||||||
parameters = {
|
|
||||||
type:"update_icon",
|
parameters = {
|
||||||
icon_id:GPASS_ICON.NORMAL,
|
type:"update_icon",
|
||||||
};
|
icon_id:GPASS_ICON.NORMAL,
|
||||||
browser.runtime.sendMessage(parameters, {});
|
};
|
||||||
}
|
browser.runtime.sendMessage(parameters, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_sumbit(e)
|
function on_sumbit(e)
|
||||||
|
@ -116,15 +159,8 @@ function on_sumbit(e)
|
||||||
|
|
||||||
debug("on_submit");
|
debug("on_submit");
|
||||||
|
|
||||||
type_filters = new Array();
|
logins = get_logins(form, true);
|
||||||
// Get all <input type="text"> && <input type="email">
|
all_logins = get_logins(form, false);
|
||||||
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);
|
|
||||||
|
|
||||||
if (!logins.length)
|
if (!logins.length)
|
||||||
logins = all_logins;
|
logins = all_logins;
|
||||||
|
|
|
@ -22,10 +22,6 @@ var DEBUG = false;
|
||||||
SERVER = {OK : 0, FAILED : 1, RESTART_REQUEST : 2};
|
SERVER = {OK : 0, FAILED : 1, RESTART_REQUEST : 2};
|
||||||
GPASS_ICON = {NORMAL:0, DISABLED:1, ACTIVATED: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 browser = browser || chrome;
|
||||||
var crypto = crypto || window.crypto;
|
var crypto = crypto || window.crypto;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user