forked from ericwoodruff/passwordhasherplus
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbackground.js
48 lines (44 loc) · 1.42 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* We fire change and keyup events after we edit the value of the currently
* focused password field to catch the most common ways to do client-side
* password verification.
*/
function updateFocusedField(tabid, hash) {
browser.tabs.executeScript(tabid, {
code: `
document.activeElement.value = '${hash}';
var evt = new Event('change');
setTimeout(document.activeElement.dispatchEvent(evt), 0);
evt = new Event('keyup');
setTimeout(document.activeElement.dispatchEvent(evt), 0);`
});
}
function forwardHash(tag, hash) {
if (debug) console.log("[background.js:forwardHash] got hash " + hash + " for page " + tag);
browser.tabs.query({active:true,currentWindow:true}).then(results => {
var tab = results[0];
updateFocusedField(tab.id, hash);
});
}
/* enable page action for all regular tabs */
browser.tabs.query({}).then(opentabs => {
for (let tab of opentabs) {
browser.pageAction.show(tab.id);
}
});
/* enable page action for new tabs */
browser.tabs.onUpdated.addListener((tabid,changeinfo) => {
browser.pageAction.show(tabid);
});
/* create context menu item for all editable fields */
browser.menus.create({
id: 'open-passhash',
title: 'Password Hasher Plus',
/* TODO: figure out icons */
icons: {
"16": "images/passhash.png",
"32": "images/passhash.png"
},
contexts: ["editable", "password"],
command: "_execute_page_action",
});