-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (43 loc) · 1.17 KB
/
index.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
let initialState = {
_blacklist: [
"chrome://",
"about:blank",
"chrome-extension://",
"localhost",
"chrome-devtools",
"mailto:",
"file://"
],
_settings: {
timeseriesFilter: "alltime"
}
};
// Set up the new tab page on first load
(async function() {
let items = await getItems();
let settings = await getSettings();
let blacklist = await getBlacklist();
createTimeseriesFilterDropdown(settings);
createBlacklistDropdownElements(blacklist);
drawView(items);
})();
// redraw when tab is activated
chrome.tabs.onActivated.addListener(function(x) {
chrome.tabs.get(x.tabId, async function(active) {
let localStorageItems = await getItems();
if (active.url.includes("chrome://") && localStorageItems.length) {
drawView(localStorageItems);
}
});
});
// redraw when window is focused
chrome.windows.onFocusChanged.addListener(function(newWindowId) {
if (newWindowId > 0) {
chrome.tabs.getSelected(newWindowId, async function(active) {
let localStorageItems = await getItems();
if (active.url.includes("chrome://newtab") && localStorageItems.length) {
drawView(localStorageItems);
}
});
}
});