Add a checkbox to only copy password into clipboard from popup (and a default behaviour from options)

This commit is contained in:
Grégory Soutadé 2021-03-02 16:54:24 +01:00
parent 354ddbbba9
commit 7f95b19264
12 changed files with 166 additions and 74 deletions

View File

@ -380,6 +380,14 @@ function extension_load()
});
return true;
}
else if (request.type == "getPopupClipboard")
{
get_preference("popup_clipboard").then(
function (value) {
sendResponse({"value" : value});
});
return true;
}
else if (request.type == "is_gpass_enabled")
{
browser.tabs.query({active:true, currentWindow:true},

View File

@ -19,7 +19,8 @@
var default_preferences = {"pbkdf2_level": 1000,
"account_url": "https://gpass-demo.soutade.fr/demo",
"always_disabled":false
"always_disabled":false,
"popup_clipboard":false
};
function get_preference(key)

View File

@ -10,8 +10,9 @@
<br/>
<b>PBKDF2 level</b> Number of iterations used to derivate master key <input id="pbkdf2_level" type="number"/><br />
<br/>
<b>Always disabled</b> Disable gPass for all websites. You can still use popup, but no hook is attached to login forms <input id="always_disabled" type="checkbox"/><br />
<br/>
<b>Always disabled</b> Disable gPass for all websites. You can still use popup, but no hook is attached to login forms<input id="always_disabled" type="checkbox"/><br />
<b>Popup clipboard copy</b> Copy password into clipboard (by default) when using popup <input id="popup_clipboard" type="checkbox"/><br />
<br/>
<br/>
<input type="button" id="save" value="Save"/>

View File

@ -1,17 +1,20 @@
var default_preferences = {"pbkdf2_level": 1000,
"account_url": "https://gpass-demo.soutade.fr/demo",
"always_disabled":false
"always_disabled":false,
"popup_clipboard":false
};
function save() {
var account_url = document.getElementById('account_url').value;
var pbkdf2_level = document.getElementById('pbkdf2_level').value;
var always_disabled = document.getElementById('always_disabled').checked;
var popup_clipboard = document.getElementById('popup_clipboard').checked;
chrome.storage.local.set({
'account_url': account_url,
'pbkdf2_level': pbkdf2_level,
'always_disabled': always_disabled,
'popup_clipboard': popup_clipboard,
}, function() {
alert('Saved');
});
@ -37,6 +40,7 @@ chrome.storage.local.get(null, function(prefs) {
restoreOption(prefs, 'account_url');
restoreOption(prefs, 'pbkdf2_level');
restoreOption(prefs, 'always_disabled');
restoreOption(prefs, 'popup_clipboard');
});
document.getElementById('save').addEventListener("click", save);

View File

@ -6,6 +6,7 @@
<body>
<form id="passwordForm" autocomplete="off">
Username <input type="text" id="gPassUsername" autofocus></input><br/> Master key <input type="password" id="gPassMasterKey"/><br/>
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>

View File

@ -17,7 +17,52 @@
along with gPass. If not, see <http://www.gnu.org/licenses/>.
*/
var username_filled = false
var username_filled = false;
function _server_response(response, tabs, do_submit, force_copy)
{
debug("Get Response");
if (response.value == SERVER.OK)
{
/* Only copy */
if (document.getElementById("clipboard").checked)
{
navigator.clipboard.writeText(response.password).then(function() {
notify("Password pasted into clipboard", "");
window.close();
});
return true;
}
/* Fill + optional copy */
parameters = {
"type":"setPassword",
"password":response.password,
"submit":do_submit
};
send_tab_message(tabs[0].id, parameters,
function(arg)
{
debug("Response to setPassword " + arg);
if (arg === "" || force_copy)
{
navigator.clipboard.writeText(response.password).then(function() {
notify("Password pasted into clipboard", "");
window.close();
});
}
else
{
notify("Password filled", "");
window.close();
}
}
);
}
return true;
}
function _query_tabs_get_password(tabs)
{
@ -55,38 +100,11 @@ function _query_tabs_get_password(tabs)
};
browser.runtime.sendMessage(parameters, {},
function (response)
{
debug("Get Response");
if (response.value == SERVER.OK)
{
parameters = {
"type":"setPassword",
"password":response.password,
"submit":do_submit
};
send_tab_message(tabs[0].id, parameters,
function(arg)
{
debug("Response to setPassword " + arg);
if (arg === "" || force_copy)
{
navigator.clipboard.writeText(response.password).then(function() {
notify("Password pasted into clipboard", "");
window.close();
});
}
else
{
notify("Password filled", "");
window.close();
}
}
);
}
return true;
});
function (response)
{
return _server_response(response, tabs, do_submit, force_copy);
}
);
return true;
}
@ -129,9 +147,22 @@ function _query_tabs_init(tabs)
}
});
/* Clipboard copy */
parameters = {
"type":"getPopupClipboard"
};
browser.runtime.sendMessage(parameters, {},
function (response)
{
document.getElementById("clipboard").checked = response.value;
return true;
});
/* Setup server link address */
parameters = {
type:"getServerAddress"
"type":"getServerAddress"
};
browser.runtime.sendMessage(parameters, {},

View File

@ -380,6 +380,14 @@ function extension_load()
});
return true;
}
else if (request.type == "getPopupClipboard")
{
get_preference("popup_clipboard").then(
function (value) {
sendResponse({"value" : value});
});
return true;
}
else if (request.type == "is_gpass_enabled")
{
browser.tabs.query({active:true, currentWindow:true},

View File

@ -19,7 +19,8 @@
var default_preferences = {"pbkdf2_level": 1000,
"account_url": "https://gpass-demo.soutade.fr/demo",
"always_disabled":false
"always_disabled":false,
"popup_clipboard":false
};
function get_preference(key)

View File

@ -10,8 +10,9 @@
<br/>
<b>PBKDF2 level</b> Number of iterations used to derivate master key <input id="pbkdf2_level" type="number"/><br />
<br/>
<b>Always disabled</b> Disable gPass for all websites. You can still use popup, but no hook is attached to login forms <input id="always_disabled" type="checkbox"/><br />
<br/>
<b>Always disabled</b> Disable gPass for all websites. You can still use popup, but no hook is attached to login forms<input id="always_disabled" type="checkbox"/><br />
<b>Popup clipboard copy</b> Copy password into clipboard (by default) when using popup <input id="popup_clipboard" type="checkbox"/><br />
<br/>
<br/>
<input type="button" id="save" value="Save"/>

View File

@ -1,17 +1,20 @@
var default_preferences = {"pbkdf2_level": 1000,
"account_url": "https://gpass-demo.soutade.fr/demo",
"always_disabled":false
"always_disabled":false,
"popup_clipboard":false
};
function save() {
var account_url = document.getElementById('account_url').value;
var pbkdf2_level = document.getElementById('pbkdf2_level').value;
var always_disabled = document.getElementById('always_disabled').checked;
var popup_clipboard = document.getElementById('popup_clipboard').checked;
browser.storage.local.set({
"account_url":account_url,
"pbkdf2_level":pbkdf2_level,
"always_disabled": always_disabled,
"popup_clipboard": popup_clipboard,
})
.then(function ok() { alert("Saved"); },
function err() { alert("Cannot save your preferences");}
@ -42,6 +45,7 @@ function restoreOptions()
restoreOption(prefs, 'account_url');
restoreOption(prefs, 'pbkdf2_level');
restoreOption(prefs, 'always_disabled');
restoreOption(prefs, 'popup_clipboard');
}
);
}

View File

@ -6,6 +6,7 @@
<body>
<form id="passwordForm" autocomplete="off">
Username <input type="text" id="gPassUsername" autofocus></input><br/> Master key <input type="password" id="gPassMasterKey"/><br/>
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>

View File

@ -17,7 +17,52 @@
along with gPass. If not, see <http://www.gnu.org/licenses/>.
*/
var username_filled = false
var username_filled = false;
function _server_response(response, tabs, do_submit, force_copy)
{
debug("Get Response");
if (response.value == SERVER.OK)
{
/* Only copy */
if (document.getElementById("clipboard").checked)
{
navigator.clipboard.writeText(response.password).then(function() {
notify("Password pasted into clipboard", "");
window.close();
});
return true;
}
/* Fill + optional copy */
parameters = {
"type":"setPassword",
"password":response.password,
"submit":do_submit
};
send_tab_message(tabs[0].id, parameters,
function(arg)
{
debug("Response to setPassword " + arg);
if (arg === "" || force_copy)
{
navigator.clipboard.writeText(response.password).then(function() {
notify("Password pasted into clipboard", "");
window.close();
});
}
else
{
notify("Password filled", "");
window.close();
}
}
);
}
return true;
}
function _query_tabs_get_password(tabs)
{
@ -55,38 +100,11 @@ function _query_tabs_get_password(tabs)
};
browser.runtime.sendMessage(parameters, {},
function (response)
{
debug("Get Response");
if (response.value == SERVER.OK)
{
parameters = {
"type":"setPassword",
"password":response.password,
"submit":do_submit
};
send_tab_message(tabs[0].id, parameters,
function(arg)
{
debug("Response to setPassword " + arg);
if (arg === "" || force_copy)
{
navigator.clipboard.writeText(response.password).then(function() {
notify("Password pasted into clipboard", "");
window.close();
});
}
else
{
notify("Password filled", "");
window.close();
}
}
);
}
return true;
});
function (response)
{
return _server_response(response, tabs, do_submit, force_copy);
}
);
return true;
}
@ -129,9 +147,22 @@ function _query_tabs_init(tabs)
}
});
/* Clipboard copy */
parameters = {
"type":"getPopupClipboard"
};
browser.runtime.sendMessage(parameters, {},
function (response)
{
document.getElementById("clipboard").checked = response.value;
return true;
});
/* Setup server link address */
parameters = {
type:"getServerAddress"
"type":"getServerAddress"
};
browser.runtime.sendMessage(parameters, {},