-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
68 lines (63 loc) · 2.22 KB
/
Copy pathworker.js
File metadata and controls
68 lines (63 loc) · 2.22 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
self.importScripts('context.js', 'managed.js');
// TO-DO: Do not overwrite viewer.html and use the following instead
// https://www.w3docs.com/tools/code-editor/1085
// https://www.w3docs.com/tools/code-editor/1077
// self.importScripts('overwrite.js');
chrome.runtime.onMessage.addListener((request, sender) => {
if (request.method === 'open-viewer') {
if (sender.frameId === 0) {
chrome.tabs.update(sender.tab.id, {
url: request.viewer
});
}
}
else if (request.method === 'notify') {
chrome.action.setBadgeText({
text: 'E',
tabId: sender.tab.id
});
chrome.action.setTitle({
title: request.message || 'NA',
tabId: sender.tab.id
});
chrome.action.setBadgeBackgroundColor({
color: 'red',
tabId: sender.tab.id
});
}
});
/* action */
chrome.action.onClicked.addListener(() => chrome.tabs.create({
url: '/data/pdf.js/web/viewer.html?file=/data/viewer/welcome.pdf'
}));
/* FAQs & Feedback */
{
chrome.management = chrome.management || {
getSelf(c) {
c({installType: 'normal'});
}
};
if (navigator.webdriver !== true) {
const {homepage_url: page, name, version} = chrome.runtime.getManifest();
chrome.runtime.onInstalled.addListener(({reason, previousVersion}) => {
chrome.management.getSelf(({installType}) => installType === 'normal' && chrome.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) {
chrome.tabs.query({active: true, lastFocusedWindow: true}, tbs => chrome.tabs.create({
url: page + '?version=' + version + (previousVersion ? '&p=' + previousVersion : '') + '&type=' + reason,
active: reason === 'install',
...(tbs && tbs.length && {index: tbs[0].index + 1})
}));
chrome.storage.local.set({'last-update': Date.now()});
}
}
}));
});
chrome.runtime.setUninstallURL(page + '?rd=feedback&name=' + encodeURIComponent(name) + '&version=' + version);
}
}