-
Notifications
You must be signed in to change notification settings - Fork 2
/
background.js
29 lines (26 loc) · 940 Bytes
/
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
//To detect browserAction
chrome.browserAction.onClicked.addListener(function (tab) {
chrome.tabs.sendMessage(tab.id, { "message": "clicked_browser_action" });
});
//To issue message to begin scrolling
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.message === "open_new_tab") {
chrome.tabs.create({ "url": request.url }, function (tab) {
chrome.tabs.executeScript(tab.id, { file: "content.js" }, function () {
chrome.tabs.sendMessage(tab.id, { "message": "opened_new_tab" });
});
});
}
}
);
//To kill new Tab
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.message === "close_current_tab") {
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.remove(tab.id);
});
}
}
);