2017-08-19 23:09:49 +02:00
|
|
|
openInEnum = {
|
|
|
|
CURRENT_TAB : 0,
|
|
|
|
NEW_TAB : 1,
|
|
|
|
NEW_BGTAB : 2,
|
|
|
|
NEW_WINDOW : 3
|
|
|
|
}
|
2017-08-20 18:10:19 +02:00
|
|
|
let openIn = openInEnum.CURRENT_TAB;
|
|
|
|
|
|
|
|
|
|
|
|
chrome.storage.local.get('openIn', item => {
|
|
|
|
if (item.openIn) {
|
|
|
|
openIn = item.openIn;
|
|
|
|
}
|
|
|
|
});
|
2017-08-19 23:09:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
function onError(error) {
|
2017-08-20 18:10:19 +02:00
|
|
|
if (chrome.runtime.lastError) {
|
|
|
|
console.error('Resurrect error: ', chrome.runtime.lastError);
|
|
|
|
}
|
2017-08-19 23:09:49 +02:00
|
|
|
}
|
|
|
|
|
2017-08-20 18:10:19 +02:00
|
|
|
|
|
|
|
function genGoogleUrl(url) {
|
2017-08-19 23:09:49 +02:00
|
|
|
return 'https://www.google.com/search?q=cache:'+encodeURIComponent(url);
|
|
|
|
}
|
|
|
|
|
2017-08-20 18:10:19 +02:00
|
|
|
function genGoogleTextUrl(url) {
|
2017-08-19 23:09:49 +02:00
|
|
|
return 'https://www.google.com/search?strip=1&q=cache:'+encodeURIComponent(url);
|
|
|
|
}
|
|
|
|
|
2017-08-20 18:10:19 +02:00
|
|
|
function genIaUrl(url) {
|
|
|
|
let dateStr =(new Date()).toISOString().replace(/-|T|:|\..*/g, '');
|
2017-08-19 23:09:49 +02:00
|
|
|
return 'https://web.archive.org/web/'+dateStr+'/'+url;
|
|
|
|
}
|
|
|
|
|
2017-08-20 18:10:19 +02:00
|
|
|
function genArchiveIsUrl(url) {
|
2017-08-19 23:09:49 +02:00
|
|
|
return 'https://archive.is/'+url;
|
|
|
|
}
|
|
|
|
|
2017-08-20 18:10:19 +02:00
|
|
|
function genWebCiteUrl(url) {
|
2017-08-19 23:09:49 +02:00
|
|
|
return 'http://webcitation.org/query.php?url='+encodeURIComponent(url);
|
|
|
|
}
|
|
|
|
|
2017-08-20 18:10:19 +02:00
|
|
|
|
|
|
|
function setOpenIn(where) {
|
2017-08-19 23:09:49 +02:00
|
|
|
openIn = where;
|
2017-08-20 18:10:19 +02:00
|
|
|
chrome.storage.local.set({openIn: openIn}, onError);
|
|
|
|
updateContextRadios();
|
2017-08-19 23:09:49 +02:00
|
|
|
}
|
|
|
|
|
2017-08-20 18:10:19 +02:00
|
|
|
|
|
|
|
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(
|
2017-08-20 18:58:14 +02:00
|
|
|
'resurrect-bg-tab-' + context,
|
2017-08-20 18:10:19 +02:00
|
|
|
{checked: openIn == openInEnum.NEW_BGTAB});
|
|
|
|
chrome.contextMenus.update(
|
|
|
|
'resurrect-new-window-' + context,
|
|
|
|
{checked: openIn == openInEnum.NEW_WINDOW});
|
|
|
|
});
|
2017-08-19 23:09:49 +02:00
|
|
|
}
|
|
|
|
|
2017-08-20 18:10:19 +02:00
|
|
|
|
|
|
|
function goToUrl(url, where) {
|
|
|
|
switch(Number(where)) {
|
|
|
|
case openInEnum.CURRENT_TAB:
|
|
|
|
chrome.tabs.update({'url': url});
|
|
|
|
break;
|
|
|
|
case openInEnum.NEW_TAB:
|
|
|
|
chrome.tabs.create({'url': url});
|
|
|
|
break;
|
|
|
|
case openInEnum.NEW_BGTAB:
|
|
|
|
chrome.tabs.create({'url': url, 'active': false});
|
|
|
|
break;
|
|
|
|
case openInEnum.NEW_WINDOW:
|
|
|
|
chrome.windows.create({'url': url});
|
|
|
|
break;
|
2017-08-19 23:09:49 +02:00
|
|
|
}
|
|
|
|
}
|