Skip to content
This repository was archived by the owner on Jul 8, 2022. It is now read-only.

Commit 48ccef1

Browse files
committed
paste password to field if focused on popup activate
1 parent aaaf6d5 commit 48ccef1

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

ext/manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"default_title": "MasterPassword",
2525
"default_popup": "src/browser_action/browser_action.html"
2626
},
27+
"content_scripts": [
28+
{"matches":["<all_urls>"], "js": ["src/browser_action/content.js"]}
29+
],
2730
"permissions": [
2831
"clipboardWrite",
2932
"storage",

ext/src/browser_action/browser_action.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ function copy_to_clipboard(mimetype, data) {
3434
document.execCommand("Copy", false, null);
3535
document.oncopy=null;
3636
}
37+
function update_page_password_input(pass) {
38+
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
39+
chrome.tabs.sendMessage(tabs[0].id, {sender: "no.tyridal.masterpassword", password:pass}, function(response) {
40+
// response should contain pasted:true on success. don't care currently
41+
});
42+
});
43+
}
3744

3845
var mpw_session=null;
3946
var session_store={};
@@ -59,6 +66,7 @@ function recalculate() {
5966
$('#thepassword').html(pass);
6067

6168
copy_to_clipboard("text/plain",pass);
69+
update_page_password_input(pass);
6270
$('#usermessage').html("Password for "+$('#sitename').val()+" copied to clipboard");
6371
}
6472

@@ -114,6 +122,7 @@ function popup(session_store_) {
114122
}
115123
window.addEventListener('load', function () {
116124
popup(chrome.extension.getBackgroundPage().session_store);
125+
117126
},false);
118127

119128
$('#sessionsetup > form').on('submit', function(){

ext/src/browser_action/content.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
2+
if (msg.sender && msg.sender == "no.tyridal.masterpassword" && msg.password &&
3+
document.activeElement &&
4+
document.activeElement.tagName &&
5+
document.activeElement.tagName == "INPUT" &&
6+
document.activeElement.type == "password") {
7+
document.activeElement.value = msg.password;
8+
sendResponse({sender:"no.tyridal.masterpassword", pasted:true});
9+
}
10+
});
11+

0 commit comments

Comments
 (0)