-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
29 lines (24 loc) · 1.06 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.runtime.onConnect.addListener(function(port) {
console.assert(port.name == 'mes918x83x2!');
port.onMessage.addListener(function(msg) {
// make sure message is from content script
if (msg.url != null && msg.content == 'urlToOpen') {
const urlAsStr = msg.url.toString();
// if the link is a self reference, don't open it
if (urlAsStr[urlAsStr.length-1] == '#') {
return;
}
chrome.storage.sync.get(['disabledSites'], function(items) {
const currentBaseUrl = window.location.host;
const disabledSitesArr = items['disabledSites'] != undefined ? items['disabledSites'] : [];
if(disabledSitesArr.includes(currentBaseUrl)) {
return;
}
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
window.open(msg.url);
chrome.tabs.update(tabs[0].id, {selected: true});
});
});
}
});
});