From e59d1891a0c96c996033eb5084920f245080d301 Mon Sep 17 00:00:00 2001 From: Anthony Lieuallen Date: Sun, 25 Feb 2018 13:10:29 -0500 Subject: [PATCH] code style, more comprehensively log errors --- background.js | 12 ++++-------- common.js | 21 +++++++++++---------- popup.js | 7 ++++++- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/background.js b/background.js index e097779..96650c4 100644 --- a/background.js +++ b/background.js @@ -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); diff --git a/common.js b/common.js index b520ed5..6736331 100644 --- a/common.js +++ b/common.js @@ -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(); } diff --git a/popup.js b/popup.js index 888354b..1f5e118 100644 --- a/popup.js +++ b/popup.js @@ -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);