Update manifest to v3 (Chrome only)

This commit is contained in:
2022-09-26 20:30:40 +02:00
parent 2cb26d6d40
commit 129335dc2d
9 changed files with 403 additions and 363 deletions

View File

@@ -9,8 +9,6 @@
Copy password into clipboard <input id="clipboard" type="checkbox"/><br />
<input id="getButton" type="submit" value="Get"/> <a id="serverLink" href="">Your server</a>
</form>
<script src="misc.js"></script>
<script src="compat.js"></script>
<script src="popup.js"></script>
<script type="module" src="popup.js"></script>
</body>
</html>

View File

@@ -1,5 +1,5 @@
/*
Copyright (C) 2020 Grégory Soutadé
Copyright (C) 2020-2022 Grégory Soutadé
This file is part of gPass.
@@ -17,10 +17,13 @@
along with gPass. If not, see <http://www.gnu.org/licenses/>.
*/
import {SERVER, browser, notify, debug} from "./misc.js";
import {get_preference, send_tab_message} from "./compat.js";
var username_filled = false;
function _server_response(response, tabs, do_submit, force_copy)
{
{
debug("Get Response");
if (response.value == SERVER.OK)
{
@@ -29,17 +32,17 @@ function _server_response(response, tabs, do_submit, force_copy)
{
navigator.clipboard.writeText(response.password).then(function() {
notify("Password pasted into clipboard", "");
window.close();
window.setTimeout(function() {window.close();}, 2000);
});
return true;
}
/* Fill + optional copy */
parameters = {
var parameters = {
"type":"setPassword",
"password":response.password,
"submit":do_submit
"submit":do_submit,
};
send_tab_message(tabs[0].id, parameters,
function(arg)
@@ -49,13 +52,13 @@ function _server_response(response, tabs, do_submit, force_copy)
{
navigator.clipboard.writeText(response.password).then(function() {
notify("Password pasted into clipboard", "");
window.close();
window.setTimeout(function() {window.close();}, 2000);
});
}
else
{
notify("Password filled", "");
window.close();
window.setTimeout(function() {window.close();}, 2000);
}
}
);
@@ -91,7 +94,7 @@ function _query_tabs_get_password(tabs)
var logins = new Array();
logins.push(username);
parameters = {
var parameters = {
type:"password",
logins:logins,
domain:domain,
@@ -115,12 +118,12 @@ function get_password(evt)
evt.preventDefault();
browser.tabs.query({active:true, currentWindow:true}, _query_tabs_get_password);
browser.tabs.query({active:true, currentWindow:true}).then(_query_tabs_get_password);
return false;
}
pform = document.getElementById("passwordForm");
var pform = document.getElementById("passwordForm");
if (pform != null)
pform.onsubmit = get_password;
@@ -132,7 +135,7 @@ function _query_tabs_init(tabs)
if (tabs.length != 1) return;
/* Fill username */
parameters = {
var parameters = {
"type":"getUsername"
};
@@ -166,20 +169,22 @@ function _query_tabs_init(tabs)
};
browser.runtime.sendMessage(parameters, {},
function (response)
{
url = response.value;
url = url.substring(0, url.lastIndexOf('/'));
url += '?';
url += 'url=' + encodeURI(tabs[0].url.split("?")[0]);
url += '&user=' + document.getElementById("gPassUsername").value;
link = document.getElementById("serverLink");
link.href = url;
return true;
});
function (response)
{
if (tabs[0].url === undefined) return true;
if (tabs[0].url.startsWith("chrome://newtab/")) tabs[0].url = "";
var url = response.value;
url = url.substring(0, url.lastIndexOf('/'));
url += '?';
url += 'url=' + encodeURI(tabs[0].url.split("?")[0]);
url += '&user=' + document.getElementById("gPassUsername").value;
var link = document.getElementById("serverLink");
link.href = url;
return true;
});
return true;
}
browser.tabs.query({active:true, currentWindow:true}, _query_tabs_init);
browser.tabs.query({active:true, currentWindow:true}).then(_query_tabs_init);