forked from EricYuan26/BrowserLock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
57 lines (54 loc) · 1.91 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//import { correct } from './login.js';
const closeAllTabs = ()=>{
chrome.tabs.create({url: "login.html"}, function (preset) {
let querying = chrome.tabs.query({}, function (tabs) {
for (let tab of tabs) {
console.log(tab.id + " - " + tab.url);
/* if (tab.url !== url("https://google.com")) {
chrome.tabs.remove(tab.id);
} */
/* if ((tab.id !== preset.id) && (tab.url !== preset.url)) {
chrome.tabs.remove(tab.id);
} */
if (tab.url !== preset.url) {
chrome.tabs.remove(tab.id);
}
}
});
});
}
const loginCloseAllTabs = ()=>{
/* let n = logTabs();
if (n.length == 1) {
chrome.tabs.create({url: "login.html"});
} */
//if you are to not add a detector or smth, you need to maje sure the default tab on startup is set to the ext login page or it will crash.
let querying = chrome.tabs.query({}, function (tabs) {
for (let tab of tabs) {
console.log("[RUNTIME] ID logged for tab " + tab.id + " - " + tab.url);
if (tab.url !== chrome.runtime.getURL('login.html')) {
console.log("[RUNTIME] Closed tab " + tab.id + " - " + tab.url);
chrome.tabs.remove(tab.id);
}
}
});
};
const logTabs = ()=>{
chrome.tabs.query({}, function(tabs) {
var tabIds = tabs.map(function(tab) {
return tab.id;
});
console.log(tabIds); // This will log an array of tab IDs
return tabIds;
});
}
chrome.action.onClicked.addListener(function (thisTab) {
closeAllTabs();
});
chrome.commands.onCommand.addListener((command) => {
closeAllTabs();
});
chrome.tabs.onCreated.addListener(function() {
/* loginCloseAllTabs(); */
null;
});