diff --git a/background.js b/background.js index 7c57bda..ab28604 100644 --- a/background.js +++ b/background.js @@ -70,32 +70,36 @@ chrome.contextMenus.onClicked.addListener(function(info, tab) { let id = info.menuItemId; let url = null; if (id.endsWith('-page')) { - url = info.pageUrl; + url = processPageUrlEdgeCases(info.pageUrl); } else if (id.endsWith('-link')) { url = info.linkUrl; } - if (id.startsWith('resurrect-google-')) { - goToUrl(genGoogleUrl(url), openIn, tab.id); - } else if (id.startsWith('resurrect-googletext-')) { - goToUrl(genGoogleTextUrl(url), openIn, tab.id); - } else if (id.startsWith('resurrect-archive-')) { - goToUrl(genIaUrl(url), openIn, tab.id); - } else if (id.startsWith('resurrect-archivelist-')) { - goToUrl(genIaListUrl(url), openIn, tab.id); - } else if (id.startsWith('resurrect-archiveis-')) { - goToUrl(genArchiveIsUrl(url), openIn, tab.id); - } else if (id.startsWith('resurrect-webcitation-')) { - goToUrl(genWebCiteUrl(url), openIn, tab.id); - } else if (id.startsWith('resurrect-mementoweb-')) { - goToUrl(genMementoUrl(url), openIn, tab.id); - } else if (id.startsWith('resurrect-current-tab-')) { + if (url != null) { + if (id.startsWith('resurrect-google-')) { + goToUrl(genGoogleUrl(url), openIn, tab.id); + } else if (id.startsWith('resurrect-googletext-')) { + goToUrl(genGoogleTextUrl(url), openIn, tab.id); + } else if (id.startsWith('resurrect-archive-')) { + goToUrl(genIaUrl(url), openIn, tab.id); + } else if (id.startsWith('resurrect-archivelist-')) { + goToUrl(genIaListUrl(url), openIn, tab.id); + } else if (id.startsWith('resurrect-archiveis-')) { + goToUrl(genArchiveIsUrl(url), openIn, tab.id); + } else if (id.startsWith('resurrect-webcitation-')) { + goToUrl(genWebCiteUrl(url), openIn, tab.id); + } else if (id.startsWith('resurrect-mementoweb-')) { + goToUrl(genMementoUrl(url), openIn, tab.id); + } + } + + if (id.startsWith('resurrect-current-tab-')) { setOpenIn(openInEnum.CURRENT_TAB); } else if (id.startsWith('resurrect-new-tab-')) { - setOpenIn(openInEnum.NEW_TAB); + setOpenIn(openInEnum.NEW_TAB); } else if (id.startsWith('resurrect-bg-tab-')) { - setOpenIn(openInEnum.NEW_BGTAB); + setOpenIn(openInEnum.NEW_BGTAB); } else if (id.startsWith('resurrect-new-window-')) { - setOpenIn(openInEnum.NEW_WINDOW); + setOpenIn(openInEnum.NEW_WINDOW); } }); diff --git a/common.js b/common.js index dce9aa6..afa1ca7 100644 --- a/common.js +++ b/common.js @@ -54,6 +54,20 @@ function genMementoUrl(url) { } +/* process edge cases in the page URL + * file:// scheme pages and FF reader mode + */ +function processPageUrlEdgeCases(url) { + if (url.startsWith('about:reader?url=')) { + return decodeURIComponent(url.replace('about:reader?url=', '')); + } + else if (url.startsWith('file:') || url.startsWith('about:')) { + return null + } + return url; +} + + function setOpenIn(where) { openIn = where; chrome.storage.local.set({openIn: openIn}, logLastError); diff --git a/popup.js b/popup.js index 879da25..24d2377 100644 --- a/popup.js +++ b/popup.js @@ -17,9 +17,16 @@ function resurrect(gen) { return function() { chrome.tabs.query({active: true, currentWindow: true}, tabObj => { logLastError(); - let url = gen(tabObj[0].url); - console.info('Resurrecting via URL', url); - goToUrl(url, openIn, tabObj[0].id); + + var url = processPageUrlEdgeCases(tabObj[0].url); + + if (url != null) + { + let archiveUrl = gen(url); + console.info('Resurrecting via URL', archiveUrl); + goToUrl(archiveUrl, openIn, tabObj[0].id); + } + window.close(); }); }