-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackground.js
More file actions
30 lines (28 loc) · 1.11 KB
/
background.js
File metadata and controls
30 lines (28 loc) · 1.11 KB
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
url = "http://localhost"
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo["url"] && !changeInfo["url"].startsWith(url)) {
if (tab["pendingUrl"] == "chrome://newtab/") {
chrome.tabs.getAllInWindow((tabs) => {
if (tabs.length > 1) {
if (tab["pendingUrl"].startsWith("chrome://") && tab["pendingUrl"] != "chrome://newtab/") { return; }
chrome.tabs.remove(tab["id"])
} else {
chrome.tabs.update(tabId, {"url": url});
}
});
}
if (changeInfo["url"].startsWith("chrome://")) { return };
console.log(tabId);
chrome.tabs.update(tabId, {"url": url});
}
});
chrome.tabs.onCreated.addListener(function(tab) {
console.log(tab);
chrome.tabs.getAllInWindow((tabs) => {
if (tabs.length > 1) {
if (tab["pendingUrl"] == "chrome://newtab/") { chrome.tabs.remove(tab["id"]); }
if (tab["pendingUrl"].startsWith("chrome://")) { return; }
chrome.tabs.remove(tab["id"]);
}
});
});