-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
51 lines (49 loc) · 1.25 KB
/
content.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
49
50
51
function findElement(selectors) {
let field;
for (i = 0; i < selectors.length; i++) {
field = $(selectors[i]);
if (field.length) {
return field;
}
}
return {
val: function(x) {
return "";
}
};
}
function findUser() {
let userSelectors = [
"#Email",
"#username",
"#user",
"#login_field",
"[name*='email']",
"[name='login']",
"[name='login_form[username]']",
"[name*='login_field']",
"[name*='username']",
"[name*='user']"
];
return findElement(userSelectors);
}
function findPassword() {
let passwordSelectors = [
"[name*='password']",
"[type='password']"
];
return findElement(passwordSelectors);
}
// Callback to return user data and url from active tab
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if(request.action === "get_url"){
sendResponse({
url: window.location.host,
user: findUser().val(),
});
}
if(request.action === "set_user_data"){
findUser().val(request.user);
findPassword().val(request.password);
}
})