code style, more comprehensively log errors
Cette révision appartient à :
Parent
24fbfd4080
révision
e59d1891a0
3 fichiers modifiés avec 21 ajouts et 19 suppressions
|
@ -1,7 +1,3 @@
|
||||||
function onCreated(n) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
chrome.storage.local.get('openIn', item => {
|
chrome.storage.local.get('openIn', item => {
|
||||||
if (item.openIn) {
|
if (item.openIn) {
|
||||||
openIn = item.openIn;
|
openIn = item.openIn;
|
||||||
|
@ -14,7 +10,7 @@ chrome.storage.local.get('openIn', item => {
|
||||||
icons: {16: 'icons/cacheicons/' + icon + '.png'},
|
icons: {16: 'icons/cacheicons/' + icon + '.png'},
|
||||||
contexts: [context],
|
contexts: [context],
|
||||||
parentId: 'resurrect-' + context
|
parentId: 'resurrect-' + context
|
||||||
}, onCreated);
|
}, logLastError);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addConfigItem(context, i18n, where, checked) {
|
function addConfigItem(context, i18n, where, checked) {
|
||||||
|
@ -25,7 +21,7 @@ chrome.storage.local.get('openIn', item => {
|
||||||
contexts: [context],
|
contexts: [context],
|
||||||
checked: checked,
|
checked: checked,
|
||||||
parentId: 'resurrect-' + context
|
parentId: 'resurrect-' + context
|
||||||
}, onCreated);
|
}, logLastError);
|
||||||
}
|
}
|
||||||
|
|
||||||
['page', 'link'].forEach(context => {
|
['page', 'link'].forEach(context => {
|
||||||
|
@ -33,7 +29,7 @@ chrome.storage.local.get('openIn', item => {
|
||||||
id: 'resurrect-' + context,
|
id: 'resurrect-' + context,
|
||||||
title: chrome.i18n.getMessage('resurrect_' + context),
|
title: chrome.i18n.getMessage('resurrect_' + context),
|
||||||
contexts: [context]
|
contexts: [context]
|
||||||
}, onCreated);
|
}, logLastError);
|
||||||
|
|
||||||
addResurrectItem(context, 'Google', 'google', 'google');
|
addResurrectItem(context, 'Google', 'google', 'google');
|
||||||
addResurrectItem(context, 'GoogleText', 'googletext', 'google');
|
addResurrectItem(context, 'GoogleText', 'googletext', 'google');
|
||||||
|
@ -48,7 +44,7 @@ chrome.storage.local.get('openIn', item => {
|
||||||
type: 'separator',
|
type: 'separator',
|
||||||
contexts: [context],
|
contexts: [context],
|
||||||
parentId: 'resurrect-' + context
|
parentId: 'resurrect-' + context
|
||||||
}, onCreated);
|
}, logLastError);
|
||||||
|
|
||||||
addConfigItem(
|
addConfigItem(
|
||||||
context, 'CurrentTab', 'current-tab', openIn == openInEnum.CURRENT_TAB);
|
context, 'CurrentTab', 'current-tab', openIn == openInEnum.CURRENT_TAB);
|
||||||
|
|
|
@ -2,7 +2,7 @@ openInEnum = {
|
||||||
CURRENT_TAB : 0,
|
CURRENT_TAB : 0,
|
||||||
NEW_TAB : 1,
|
NEW_TAB : 1,
|
||||||
NEW_BGTAB : 2,
|
NEW_BGTAB : 2,
|
||||||
NEW_WINDOW : 3
|
NEW_WINDOW : 3,
|
||||||
}
|
}
|
||||||
let openIn = openInEnum.CURRENT_TAB;
|
let openIn = openInEnum.CURRENT_TAB;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ chrome.storage.local.get('openIn', item => {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function onError(error) {
|
function logLastError() {
|
||||||
if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
console.error('Resurrect error:', chrome.runtime.lastError);
|
console.error('Resurrect error:', chrome.runtime.lastError);
|
||||||
}
|
}
|
||||||
|
@ -49,13 +49,14 @@ function genWebCiteUrl(url) {
|
||||||
|
|
||||||
function genMementoUrl(url) {
|
function genMementoUrl(url) {
|
||||||
let dateStr = (new Date()).toISOString().replace(/-|T|:|\..*/g, '');
|
let dateStr = (new Date()).toISOString().replace(/-|T|:|\..*/g, '');
|
||||||
return 'http://timetravel.mementoweb.org/list/'+dateStr+'/'+encodeURIComponent(url);
|
return 'http://timetravel.mementoweb.org/list/'
|
||||||
|
+ dateStr + '/' + encodeURIComponent(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function setOpenIn(where) {
|
function setOpenIn(where) {
|
||||||
openIn = where;
|
openIn = where;
|
||||||
chrome.storage.local.set({openIn: openIn}, onError);
|
chrome.storage.local.set({openIn: openIn}, logLastError);
|
||||||
updateContextRadios();
|
updateContextRadios();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
popup.js
7
popup.js
|
@ -23,11 +23,16 @@ document.querySelectorAll('input[type=radio]').forEach(el => {
|
||||||
function resurrect(gen) {
|
function resurrect(gen) {
|
||||||
return function() {
|
return function() {
|
||||||
chrome.tabs.query({active: true, currentWindow: true}, tabObj => {
|
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();
|
window.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
document.querySelectorAll('button').forEach(el => {
|
document.querySelectorAll('button').forEach(el => {
|
||||||
el.addEventListener(
|
el.addEventListener(
|
||||||
'click', resurrect(window[el.getAttribute('data-gen')]), true);
|
'click', resurrect(window[el.getAttribute('data-gen')]), true);
|
||||||
|
|
Chargement…
Référencer dans un nouveau ticket