-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
46 lines (42 loc) · 1.58 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
// background.js
// Called when the user clicks on the browser action.
var username;
var password;
var activeTab;
// chrome.browserAction.onClicked.addListener(function(tab) {
// });
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.message === "login") {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, { message: "clicked_browser_action" });
});
}
else if (request.message === "open_new_tab") {
chrome.tabs.create({ "url": request.url });
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.storage.local.get(['name'], function (result) {
username = result.name;
chrome.storage.local.get(['pass'], function (result) {
password = result.pass;
});
});
activeTab = tabs[0];
});
setTimeout(function () {
chrome.tabs.sendMessage(activeTab.id, { "message": "done-loading", username: username, password: password });
}, 1000);
} else if (request.message == 'restart') {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
var activeTab = tabs[0];
chrome.tabs.remove(tabs[0].id, function(){
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, { message: "clicked_browser_action" });
});
});
});
}
}
);