forked from chandler-stimson/gridify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
54 lines (44 loc) · 1.71 KB
/
worker.js
File metadata and controls
54 lines (44 loc) · 1.71 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const notify = e => chrome.notifications.create({
type: 'basic',
iconUrl: '/data/icons/48.png',
title: chrome.runtime.getManifest().name,
message: e.message || e
});
chrome.action.onClicked.addListener(tab => chrome.scripting.executeScript({
target: {
tabId: tab.id
},
files: ['data/inject/grid.js']
}).catch(notify));
chrome.runtime.onMessage.addListener(request => {
if (request.method === 'notify') {
notify(request.message);
}
});
/* FAQs & Feedback */
{
const {management, runtime: {onInstalled, setUninstallURL, getManifest}, storage, tabs} = chrome;
if (navigator.webdriver !== true) {
const page = getManifest().homepage_url;
const {name, version} = getManifest();
onInstalled.addListener(({reason, previousVersion}) => {
management.getSelf(({installType}) => installType === 'normal' && storage.local.get({
'faqs': true,
'last-update': 0
}, prefs => {
if (reason === 'install' || (prefs.faqs && reason === 'update')) {
const doUpdate = (Date.now() - prefs['last-update']) / 1000 / 60 / 60 / 24 > 45;
if (doUpdate && previousVersion !== version) {
tabs.query({active: true, currentWindow: true}, tbs => tabs.create({
url: page + '?version=' + version + (previousVersion ? '&p=' + previousVersion : '') + '&type=' + reason,
active: reason === 'install',
...(tbs && tbs.length && {index: tbs[0].index + 1})
}));
storage.local.set({'last-update': Date.now()});
}
}
}));
});
setUninstallURL(page + '?rd=feedback&name=' + encodeURIComponent(name) + '&version=' + version);
}
}