1
1
Bifurcation 0

code style, more comprehensively log errors

Cette révision appartient à :
Anthony Lieuallen 2018-02-25 13:10:29 -05:00
Parent 24fbfd4080
révision e59d1891a0
3 fichiers modifiés avec 21 ajouts et 19 suppressions

Voir le fichier

@ -1,7 +1,3 @@
function onCreated(n) {
}
chrome.storage.local.get('openIn', item => {
if (item.openIn) {
openIn = item.openIn;
@ -14,7 +10,7 @@ chrome.storage.local.get('openIn', item => {
icons: {16: 'icons/cacheicons/' + icon + '.png'},
contexts: [context],
parentId: 'resurrect-' + context
}, onCreated);
}, logLastError);
}
function addConfigItem(context, i18n, where, checked) {
@ -25,7 +21,7 @@ chrome.storage.local.get('openIn', item => {
contexts: [context],
checked: checked,
parentId: 'resurrect-' + context
}, onCreated);
}, logLastError);
}
['page', 'link'].forEach(context => {
@ -33,7 +29,7 @@ chrome.storage.local.get('openIn', item => {
id: 'resurrect-' + context,
title: chrome.i18n.getMessage('resurrect_' + context),
contexts: [context]
}, onCreated);
}, logLastError);
addResurrectItem(context, 'Google', 'google', 'google');
addResurrectItem(context, 'GoogleText', 'googletext', 'google');
@ -48,7 +44,7 @@ chrome.storage.local.get('openIn', item => {
type: 'separator',
contexts: [context],
parentId: 'resurrect-' + context
}, onCreated);
}, logLastError);
addConfigItem(
context, 'CurrentTab', 'current-tab', openIn == openInEnum.CURRENT_TAB);

Voir le fichier

@ -2,7 +2,7 @@ openInEnum = {
CURRENT_TAB : 0,
NEW_TAB : 1,
NEW_BGTAB : 2,
NEW_WINDOW : 3
NEW_WINDOW : 3,
}
let openIn = openInEnum.CURRENT_TAB;
@ -14,28 +14,28 @@ chrome.storage.local.get('openIn', item => {
});
function onError(error) {
function logLastError() {
if (chrome.runtime.lastError) {
console.error('Resurrect error: ', chrome.runtime.lastError);
console.error('Resurrect error:', chrome.runtime.lastError);
}
}
function genGoogleUrl(url) {
return 'https://www.google.com/search?q=cache:'+encodeURIComponent(url);
return 'https://www.google.com/search?q=cache:' + encodeURIComponent(url);
}
function genGoogleTextUrl(url) {
return 'https://www.google.com/search?strip=1&q=cache:'+encodeURIComponent(url);
return 'https://www.google.com/search?strip=1&q=cache:' + encodeURIComponent(url);
}
function genIaUrl(url) {
let dateStr =(new Date()).toISOString().replace(/-|T|:|\..*/g, '');
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, '');
let dateStr = (new Date()).toISOString().replace(/-|T|:|\..*/g, '');
return 'https://web.archive.org/web/*/'+url;
}
@ -48,14 +48,15 @@ function genWebCiteUrl(url) {
}
function genMementoUrl(url) {
let dateStr =(new Date()).toISOString().replace(/-|T|:|\..*/g, '');
return 'http://timetravel.mementoweb.org/list/'+dateStr+'/'+encodeURIComponent(url);
let dateStr = (new Date()).toISOString().replace(/-|T|:|\..*/g, '');
return 'http://timetravel.mementoweb.org/list/'
+ dateStr + '/' + encodeURIComponent(url);
}
function setOpenIn(where) {
openIn = where;
chrome.storage.local.set({openIn: openIn}, onError);
chrome.storage.local.set({openIn: openIn}, logLastError);
updateContextRadios();
}

Voir le fichier

@ -23,11 +23,16 @@ document.querySelectorAll('input[type=radio]').forEach(el => {
function resurrect(gen) {
return function() {
chrome.tabs.query({active: true, currentWindow: true}, tabObj => {
goToUrl(gen(tabObj[0].url), openIn);
logLastError();
let url = gen(tabObj[0].url);
console.info('Resurrecting via URL', url);
goToUrl(url, openIn);
window.close();
});
}
}
document.querySelectorAll('button').forEach(el => {
el.addEventListener(
'click', resurrect(window[el.getAttribute('data-gen')]), true);