/
background.js
29 lines (25 loc) · 1.07 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
chrome.webNavigation.onHistoryStateUpdated.addListener(function(details) {
console.log('Page uses History API and we heard a pushSate/replaceState.');
chrome.tabs.sendMessage(details.tabId, {"event": "historyChange"});
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
console.log('Tab updated');
chrome.tabs.sendMessage(tabId, {"event": "tab Updated"});
});
chrome.tabs.onActivated.addListener(function(activeInfo) {
console.log('Tab activated');
chrome.tabs.sendMessage(activeInfo.tabId, {"event": "tab Activated"});
});
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
chrome.contextMenus.removeAll();
chrome.contextMenus.create({"title":request.title, "onclick": contextMenuOnClicked});
});
function contextMenuOnClicked(info, tab) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {"event" : "contextMenuAction"}, function(response) {
chrome.tabs.update(null, {
url: response.url
});
});
});
}