forked from arantius/resurrect-pages
-
Notifications
You must be signed in to change notification settings - Fork 3
/
common.js
89 lines (79 loc) · 2.26 KB
/
common.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
88
89
openInEnum = {
CURRENT_TAB : 0,
NEW_TAB : 1,
NEW_BGTAB : 2,
NEW_WINDOW : 3
}
let openIn = openInEnum.CURRENT_TAB;
chrome.storage.local.get('openIn', item => {
if (item.openIn) {
openIn = item.openIn;
}
});
function logLastError() {
if (chrome.runtime.lastError) {
console.error('Resurrect error:', chrome.runtime.lastError);
}
}
function genCachewUrl(url) {
return 'https://cachedview.nl/#' +url;
}
function genIaUrl(url) {
let dateStr = (new Date()).toISOString().replace(/-|T|:|\..*/g, '');
return 'https://web.archive.org/web/'+dateStr+'/'+url;
}
function genIaListUrl(url) {
let dateStr = (new Date()).toISOString().replace(/-|T|:|\..*/g, '');
return 'https://web.archive.org/web/*/'+url;
}
function genArchiveIsUrl(url) {
return 'https://archive.ph/'+url;
}
function genWebCiteUrl(url) {
return 'http://webcitation.org/query.php?url='+encodeURIComponent(url);
}
function genMementoUrl(url) {
let dateStr = (new Date()).toISOString().replace(/-|T|:|\..*/g, '');
return 'http://timetravel.mementoweb.org/list/'
+ dateStr + '/' +url;
}
function genIsUpUrl(url) {
return 'http://isup.me/'+url;
}
function setOpenIn(where) {
openIn = where;
chrome.storage.local.set({openIn: openIn}, logLastError);
updateContextRadios();
}
function updateContextRadios() {
['page', 'link'].forEach(context => {
chrome.contextMenus.update(
'resurrect-current-tab-' + context,
{checked: openIn == openInEnum.CURRENT_TAB});
chrome.contextMenus.update(
'resurrect-new-tab-' + context,
{checked: openIn == openInEnum.NEW_TAB});
chrome.contextMenus.update(
'resurrect-bg-tab-' + context,
{checked: openIn == openInEnum.NEW_BGTAB});
chrome.contextMenus.update(
'resurrect-new-window-' + context,
{checked: openIn == openInEnum.NEW_WINDOW});
});
}
function goToUrl(url, where, openerTabId) {
switch(Number(where)) {
case openInEnum.CURRENT_TAB:
chrome.tabs.update({'url': url});
break;
case openInEnum.NEW_TAB:
chrome.tabs.create({'url': url, openerTabId});
break;
case openInEnum.NEW_BGTAB:
chrome.tabs.create({'url': url, 'active': false, openerTabId});
break;
case openInEnum.NEW_WINDOW:
chrome.windows.create({'url': url});
break;
}
}