From 5120b11375890d83b1a5359cdfe8526a8f674a52 Mon Sep 17 00:00:00 2001 From: blankie Date: Thu, 28 Mar 2024 18:32:44 +1100 Subject: [PATCH] Update Archive Site Links to 1.1.2 - Fix properly navigating to pages with a fragment - Fix handling https://web.archive.org/web/ URLs --- Archive Site Links.user.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Archive Site Links.user.js b/Archive Site Links.user.js index 76b4d8a..e1608f3 100644 --- a/Archive Site Links.user.js +++ b/Archive Site Links.user.js @@ -4,7 +4,7 @@ // @match http*://*/* // @grant GM_openInTab // @grant GM_registerMenuCommand -// @version 1.1.0 +// @version 1.1.2 // @author blankie // @description Adds buttons to the monkey menu to open/archive in the Wayback Machine and archive.today // @inject-into content @@ -23,11 +23,11 @@ const ARCHIVE_SITES = [ return newUrl.href; }, getArchivedUrl: function(url) { - return `https://web.archive.org/web/2/${url}`; + return `https://web.archive.org/web/${url}${window.location.hash}`; }, getArchivedUrlBase: function() { if (window.location.host !== "web.archive.org") return null; - let match = /^\/web\/[0-9a-z_*]+\/(.+)$/.exec(window.location.pathname); + let match = /^\/web\/(?:[0-9a-z_*]+\/)?(.+)$/.exec(window.location.pathname); return match ? match[1] : null; }, }, @@ -39,7 +39,7 @@ const ARCHIVE_SITES = [ return newUrl.href; }, getArchivedUrl: function(url) { - return `https://archive.today/newest/${url}`; + return `https://archive.today/newest/${url}${window.location.hash}`; }, getArchivedUrlBase: function() { // https://en.wikipedia.org/wiki/Archive.today?useskin=vector& @@ -50,8 +50,13 @@ const ARCHIVE_SITES = [ } ]; -let url = window.location.href; +let url = function() { + let urlObject = new URL(window.location.href); + urlObject.hash = ""; + return urlObject.href; +}(); let onArchiveSite; + for (const ARCHIVE_SITE of ARCHIVE_SITES) { let urlBase = ARCHIVE_SITE.getArchivedUrlBase(url); if (!urlBase) { @@ -64,7 +69,6 @@ for (const ARCHIVE_SITE of ARCHIVE_SITES) { let urlObject = new URL(urlBase); urlObject.search = window.location.search; - urlObject.hash = window.location.hash; url = urlObject.href; onArchiveSite = ARCHIVE_SITE; break; @@ -86,15 +90,11 @@ for (const ARCHIVE_SITE of ARCHIVE_SITES) { }); } - let urlObject = new URL(url); - urlObject.hash = ""; - let hashlessUrl = urlObject.href; - GM_registerMenuCommand(`Archive in ${ARCHIVE_SITE.name}`, function() { - window.location.href = ARCHIVE_SITE.getArchiveUrl(hashlessUrl); + window.location.href = ARCHIVE_SITE.getArchiveUrl(url); }); GM_registerMenuCommand(`Archive in ${ARCHIVE_SITE.name} (new tab)`, function() { - GM_openInTab(ARCHIVE_SITE.getArchiveUrl(hashlessUrl)); + GM_openInTab(ARCHIVE_SITE.getArchiveUrl(url)); }); }