Update Archive Site Links to 1.1.2
- Fix properly navigating to pages with a fragment - Fix handling https://web.archive.org/web/<url> URLs
This commit is contained in:
parent
65a219c844
commit
5120b11375
|
@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue