forked from arantius/resurrect-pages
-
Notifications
You must be signed in to change notification settings - Fork 3
/
background.js
87 lines (82 loc) · 3.03 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
chrome.storage.local.get('openIn', item => {
if (item.openIn) {
openIn = item.openIn;
}
['page', 'link'].forEach(context => {
chrome.contextMenus.create({
contexts: [context],
id: 'resurrect-' + context,
title: chrome.i18n.getMessage('resurrect_' + context),
}, logLastError);
for (let [name, id, icon] of [
['Cachew', 'cachew', 'cachew'],
['Archive', 'archive', 'waybackmachine'],
['ArchiveList', 'archivelist', 'waybackmachine'],
['ArchiveIs', 'archiveis', 'archiveis'],
['WebCitation', 'webcitation', 'webcitation'],
['MementoWeb', 'mementoweb', 'mementoweb'],
['IsUp', 'isup', 'isup'],
]) {
chrome.contextMenus.create({
contexts: [context],
icons: {16: 'icons/cacheicons/' + icon + '.png'},
id: 'resurrect-' + id + '-' + context,
parentId: 'resurrect-' + context,
title: chrome.i18n.getMessage('resurrect' + name),
}, logLastError);
}
chrome.contextMenus.create({
id: 'resurrect-separator-config-' + context,
type: 'separator',
contexts: [context],
parentId: 'resurrect-' + context
}, logLastError);
for (let [name, where, checked] of [
['CurrentTab', 'current-tab', openIn == openInEnum.CURRENT_TAB],
['NewTab', 'new-tab', openIn == openInEnum.NEW_TAB],
['BgTab', 'bg-tab', openIn == openInEnum.NEW_BGTAB],
['NewWindow', 'new-window', openIn == openInEnum.NEW_WINDOW],
]) {
chrome.contextMenus.create({
id: 'resurrect-' + where + '-' + context,
type: 'radio',
title: chrome.i18n.getMessage('resurrectConfig' + name),
contexts: [context],
checked: checked,
parentId: 'resurrect-' + context
}, logLastError);
}
});
});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
let id = info.menuItemId;
let url = null;
if (id.endsWith('-page')) {
url = info.pageUrl;
} else if (id.endsWith('-link')) {
url = info.linkUrl;
}
if (id.startsWith('resurrect-cachew-')) {
goToUrl(genCachewUrl(url), openIn, tab.id);
} else if (id.startsWith('resurrect-archive-')) {
goToUrl(genIaUrl(url), openIn, tab.id);
} else if (id.startsWith('resurrect-archivelist-')) {
goToUrl(genIaListUrl(url), openIn, tab.id);
} else if (id.startsWith('resurrect-archiveis-')) {
goToUrl(genArchiveIsUrl(url), openIn, tab.id);
} else if (id.startsWith('resurrect-isup-')) {
goToUrl(genIsUpUrl(url), openIn, tab.id);
} else if (id.startsWith('resurrect-webcitation-')) {
goToUrl(genWebCiteUrl(url), openIn, tab.id);
} else if (id.startsWith('resurrect-mementoweb-')) {
goToUrl(genMementoUrl(url), openIn, tab.id);
} else if (id.startsWith('resurrect-current-tab-')) {
setOpenIn(openInEnum.CURRENT_TAB);
} else if (id.startsWith('resurrect-new-tab-')) {
setOpenIn(openInEnum.NEW_TAB);
} else if (id.startsWith('resurrect-bg-tab-')) {
setOpenIn(openInEnum.NEW_BGTAB);
} else if (id.startsWith('resurrect-new-window-')) {
setOpenIn(openInEnum.NEW_WINDOW);
}
});