-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevent.js
30 lines (26 loc) · 993 Bytes
/
event.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
(function() {
var regex = /^(http[s]?\:\/\/)([^\/]*)(\/.*)$/i;
function renavigate(event) {
var match = event.url.match(regex);
if (match === undefined || match === null || match.length != 4) {
return;
}
chrome.storage.sync.get(match[2], function(item) {
if (item.hasOwnProperty(match[2])) {
chrome.tabs.get(event.tabId, function(tab) {
if (tab.url == event.url) {
chrome.tabs.update(event.tabId, {url: match[1] + item[match[2]] + match[3]});
}
});
}
});
}
chrome.webNavigation.onBeforeNavigate.addListener(renavigate);
chrome.webNavigation.onCommitted.addListener(renavigate);
chrome.browserAction.onClicked.addListener(function(tab) {
if (!tab.url.match(/^http[s]?\:\/\//)) {
return;
}
chrome.browserAction.setPopup({popup: "action.html"});
});
})();