/* Copyright (C) 2013-2022 Grégory Soutadé This file is part of gPass. gPass is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. gPass is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with gPass. If not, see . */ /* from misc.js */ /* Can't directly add it, because it's now a module */ var DEBUG = false; var browser = browser || chrome; const SERVER = {OK : 0, FAILED : 1, RESTART_REQUEST : 2}; const GPASS_ICON = {NORMAL:0, DISABLED:1, ACTIVATED:2}; function debug(s) { if (DEBUG) console.log(s); } function notify(text, data) { browser.runtime.sendMessage({type: "notification", options:{"message":text, "data":data}}); } var gpass_enabled = true; function _add_name(logins, name) { 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) return; var logins = get_logins(this.form, true); var all_logins = get_logins(this.form, false); if (logins.length || all_logins.length) { var parameters = { type:"update_icon", icon_id:GPASS_ICON.ACTIVATED, }; browser.runtime.sendMessage(parameters, {}); } } function on_blur(e) { if (!gpass_enabled) return; var parameters = { type:"update_icon", icon_id:GPASS_ICON.NORMAL, }; browser.runtime.sendMessage(parameters, {}); } function on_sumbit(e) { var form = this; var fields = form.getElementsByTagName("input"); var domain = form.ownerDocument.baseURI; var password_computed = false; debug("on_submit"); var logins = get_logins(form, true); var all_logins = get_logins(form, false); if (!logins.length) logins = all_logins; e.preventDefault(); // Look for for (var i=0; i && type_filters.push("text"); type_filters.push("email"); var logins = try_get_name(fields, type_filters, true); if (logins.length == 1) sendResponse(logins[0]); else sendResponse(""); } else sendResponse(""); } else if (request.type == "setPassword") { debug("setPassword"); var response = ""; if (managed_forms.length == 1) { var fields = managed_forms[0].getElementsByTagName("input"); var password_field = null; for (var a=0; a