From e0155d5ab6decddd83f1116bbab4797ed836fbd3 Mon Sep 17 00:00:00 2001 From: Albirew Date: Thu, 29 Mar 2018 19:09:11 +0200 Subject: [PATCH] Updated with latest version from Arrantius - Add "list all versions" for The Internet Archive. - Add MementoWeb TimeTravel source. -Updated translation --- README.md | 8 +++- _locales/en/messages.json | 10 ++++ _locales/fr/messages.json | 10 ++++ background.js | 99 ++++++++++++++++++++++----------------- common.js | 39 +++++++++------ manifest.json | 2 +- popup.htm | 9 +++- popup.js | 6 ++- 8 files changed, 121 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index b7e4b9b..987c00c 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,12 @@ Or, the easier route, use this extension. ## Features - * Searches through seven page cache/mirrors: + * Searches through six page cache/mirrors: * [Google Cache](http://www.google.com/) (plus text-only version) * [The Internet Archive](http://web.archive.org/) * [WebCite](http://www.webcitation.org/) * [archive.is](https://archive.is/) + * [Memento Time Travel](http://timetravel.mementoweb.org/) * [Down for everyone?](http://www.isup.me/) Of course, not every page can be in every cache. @@ -27,6 +28,11 @@ Hit back and try another one! * With the keyboard: press `Ctrl-Shift-U` # Changelog + + * Version 6 + * Merged with latest version from Arrantius + * Add "list all versions" for The Internet Archive. + * Add MementoWeb TimeTravel source. * Version 5 * Merged with WebExtensions version from Arrantius (#3 #10) * Does not include netError page ([not currently possible](http://bugzil.la/1376793)) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 68fedc9..3a54535 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -34,6 +34,11 @@ "description": "with The Internet Archive" }, + "resurrectArchiveList": { + "message": "with The Internet Archive (list all)", + "description": "with The Internet Archive (list all)" + }, + "resurrectArchiveIs": { "message": "with archive.is", "description": "with archive.is" @@ -44,6 +49,11 @@ "description": "with WebCite" }, + "resurrectMementoWeb": { + "message": "with Memento Timetravel", + "description": "with Memento Timetravel" + }, + "resurrectIsUp": { "message": "check if really down", "description": "with isup.me" diff --git a/_locales/fr/messages.json b/_locales/fr/messages.json index 645be26..61fa8c1 100644 --- a/_locales/fr/messages.json +++ b/_locales/fr/messages.json @@ -34,6 +34,11 @@ "description": "with The Internet Archive" }, + "resurrectArchiveList": { + "message": "avec l'Archive Internet (historique)", + "description": "with The Internet Archive (list all)" + }, + "resurrectArchiveIs": { "message": "avec archive.is", "description": "with archive.is" @@ -44,6 +49,11 @@ "description": "with WebCite" }, + "resurrectMementoWeb": { + "message": "avec Memento Timetravel", + "description": "with Memento Timetravel" + }, + "resurrectIsUp": { "message": "VĂ©rifier si le site est mort", "description": "with isup.me" diff --git a/background.js b/background.js index d0477cd..340ddbb 100644 --- a/background.js +++ b/background.js @@ -1,65 +1,73 @@ -function onCreated(n) { -} - chrome.storage.local.get('openIn', item => { if (item.openIn) { openIn = item.openIn; } - function addResurrectItem(context, i18n, id, icon) { - chrome.contextMenus.create({ - id: 'resurrect-' + id + '-' + context, - title: chrome.i18n.getMessage('resurrect' + i18n), - icons: {16: 'icons/cacheicons/' + icon + '.png'}, - contexts: [context], - parentId: 'resurrect-' + context - }, onCreated); - } - - function addConfigItem(context, i18n, where, checked) { - chrome.contextMenus.create({ - id: 'resurrect-' + where + '-' + context, - type: 'radio', - title: chrome.i18n.getMessage('resurrectConfig' + i18n), - contexts: [context], - checked: checked, - parentId: 'resurrect-' + context - }, onCreated); - } - ['page', 'link'].forEach(context => { chrome.contextMenus.create({ + contexts: [context], id: 'resurrect-' + context, - title: chrome.i18n.getMessage('resurrect_' + context), - contexts: [context] - }, onCreated); + title: chrome.i18n.getMessage('resurrect' + i18n) + context, + }, logLastError); - addResurrectItem(context, 'Google', 'google', 'google'); - addResurrectItem(context, 'GoogleText', 'google-text', 'google'); - addResurrectItem(context, 'Archive', 'archive', 'waybackmachine'); - addResurrectItem(context, 'ArchiveIs', 'archiveis', 'archiveis'); - addResurrectItem(context, 'Webcitation', 'webcitation', 'webcitation'); - addResurrectItem(context, 'IsUp', 'isup', 'isup'); + chrome.contextMenus.create({ + enabled: false, + id: 'resurrect-' + where + '-' + context, + parentId: 'resurrect-' + context, + title: chrome.i18n.getMessage('resurrectConfig' + i18n), + }); + + for (let [name, id, icon] of [ + ['Google', 'google', 'google'], + ['Google (text only)', 'googletext', 'google'], + ['The Internet Archive', 'archive', 'waybackmachine'], + ['The Internet Archive (list all)', 'archivelist', 'waybackmachine'], + ['archive.is', 'archiveis', 'archiveis'], + ['WebCite', 'webcitation', 'webcitation'], + ['Memento Timetravel', 'mementoweb', 'mementoweb'], + ['isup.me', 'IsUp', 'isup'], + ]) { + chrome.contextMenus.create({ + contexts: [context], + icons: {16: 'icons/cacheicons/' + icon + '.png'}, + id: 'resurrect-' + id + '-' + context, + parentId: 'resurrect-' + context, + title: chrome.i18n.getMessage('resurrect_' + context), + }, logLastError); + } chrome.contextMenus.create({ id: 'resurrect-separator-config-' + context, type: 'separator', contexts: [context], parentId: 'resurrect-' + context - }, onCreated); + }, logLastError); - addConfigItem( - context, 'CurrentTab', 'current-tab', openIn == openInEnum.CURRENT_TAB); - addConfigItem( - context, 'NewTab', 'new-tab', openIn == openInEnum.NEW_TAB); - addConfigItem( - context, 'BgTab', 'bg-tab', openIn == openInEnum.BG_TAB); - addConfigItem( - context, 'NewWindow', 'new-window', openIn == openInEnum.NEW_WINDOW); + chrome.contextMenus.create({ + enabled: false, + id: 'resurrect-in-' + context, + parentId: 'resurrect-' + context, + title: 'In:', + }); + + for (let [name, where, checked] of [ + ['the current tab', 'current-tab', openIn == openInEnum.CURRENT_TAB], + ['a new tab (foreground)', 'new-tab', openIn == openInEnum.NEW_TAB], + ['a new tab (background)', 'bg-tab', openIn == openInEnum.NEW_BGTAB], + ['a new window', 'new-window', openIn == openInEnum.NEW_WINDOW], + ]) { + chrome.contextMenus.create({ + id: 'resurrect-' + where + '-' + context, + type: 'radio', + title: name, + contexts: [context], + checked: checked, + parentId: 'resurrect-' + context + }, logLastError); + } }); }); - chrome.contextMenus.onClicked.addListener(function(info, tab) { let id = info.menuItemId; let url = null; @@ -68,19 +76,22 @@ chrome.contextMenus.onClicked.addListener(function(info, tab) { } else if (id.endsWith('-link')) { url = info.linkUrl; } - if (id.startsWith('resurrect-google-')) { goToUrl(genGoogleUrl(url), openIn); } else if (id.startsWith('resurrect-googletext-')) { goToUrl(genGoogleTextUrl(url), openIn); } else if (id.startsWith('resurrect-archive-')) { goToUrl(genIaUrl(url), openIn); + } else if (id.startsWith('resurrect-archivelist-')) { + goToUrl(genIaListUrl(url), openIn); } else if (id.startsWith('resurrect-archiveis-')) { goToUrl(genArchiveIsUrl(url), openIn); } else if (id.startsWith('resurrect-isup-')) { goToUrl(genIsUpUrl(url), openIn); } else if (id.startsWith('resurrect-webcitation-')) { goToUrl(genWebCiteUrl(url), openIn); + } else if (id.startsWith('resurrect-mementoweb-')) { + goToUrl(genMementoUrl(url), openIn); } else if (id.startsWith('resurrect-current-tab-')) { setOpenIn(openInEnum.CURRENT_TAB); } else if (id.startsWith('resurrect-new-tab-')) { diff --git a/common.js b/common.js index a8f0865..231830d 100644 --- a/common.js +++ b/common.js @@ -12,25 +12,30 @@ 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, ''); + return 'https://web.archive.org/web/*/'+url; +} + function genArchiveIsUrl(url) { return 'https://archive.is/'+url; } @@ -39,30 +44,36 @@ 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}, onError); + 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}); + 'resurrect-current-tab-' + context, + {checked: openIn == openInEnum.CURRENT_TAB}); chrome.contextMenus.update( - 'resurrect-new-tab-' + context, - {checked: openIn == openInEnum.NEW_TAB}); + 'resurrect-new-tab-' + context, + {checked: openIn == openInEnum.NEW_TAB}); chrome.contextMenus.update( - 'resurrect-bg-tab-' + context, - {checked: openIn == openInEnum.NEW_BGTAB}); + 'resurrect-bg-tab-' + context, + {checked: openIn == openInEnum.NEW_BGTAB}); chrome.contextMenus.update( - 'resurrect-new-window-' + context, - {checked: openIn == openInEnum.NEW_WINDOW}); + 'resurrect-new-window-' + context, + {checked: openIn == openInEnum.NEW_WINDOW}); }); } diff --git a/manifest.json b/manifest.json index 783834d..7bdc0d3 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "__MSG_extensionName__", "short_name": "__MSG_extensionName__", "description": "__MSG_extensionDescription__", - "version": "5", + "version": "6", "default_locale": "en", "homepage_url": "https://github.com/Albirew/resurrect-pages", diff --git a/popup.htm b/popup.htm index ea74356..58a2389 100644 --- a/popup.htm +++ b/popup.htm @@ -18,6 +18,7 @@ label { } img { vertical-align: bottom; + height: 16px; }
@@ -30,17 +31,23 @@ img { + + -
+