-
Notifications
You must be signed in to change notification settings - Fork 0
/
default-containers.js
78 lines (61 loc) · 2.13 KB
/
default-containers.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//var containers = browser.contextualIdentities;
console.log("its working");
//console.log(containers);
var preferredTheme;
var currentContainer = '';
function saveOptions() {
console.log("hit save options");
let preferredTheme;
browser.theme.getCurrent().then((currentTheme) => {
preferredTheme = currentTheme;
console.log(currentTheme);
let storageItem = browser.storage.sync.get('installedTheme');
storageItem.then((storedItem) => {
browser.storage.sync.set({
installedTheme: preferredTheme
});
});
});
}
initialize();
function initialize() {
saveOptions();
setInitialStateIcon();
}
function hijackNewTab(tab) {
var id = tab.id;
var title = tab.title;
var url = tab.url;
//
browser.tabs.onCreated.removeListener(hijackNewTab);
console.log("we hit here hijack new tab");
browser.storage.sync.get('containerid').then((storedItem) => {
console.log("we hit here get storage");
console.log(storedItem);
currentContainer = storedItem.containerid;
if(currentContainer != '' && url == 'about:newtab') {
console.log(tab);
console.log(currentContainer);
console.log("tab should be updating");
browser.tabs.remove(id);
browser.tabs.create({ cookieStoreId: currentContainer });
//browser.tabs.remove(id);
}
browser.tabs.onCreated.addListener(hijackNewTab);
});
}
browser.tabs.onCreated.addListener(hijackNewTab);
function setInitialStateIcon() {
browser.storage.sync.get('containerid').then((storedItem) => {
currentContainer = storedItem.containerid;
//get container from currentcontainer
browser.contextualIdentities.get(currentContainer).then((context) => {
var icon = context.iconUrl;
//get the filename from the icon url
var filename = icon.substring(icon.lastIndexOf('/')+1);
//set the icon to the filename
var finalicon = "/icons/" + filename;
browser.browserAction.setIcon({path: finalicon});
});
});
}