The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,862 other subscribers

Bookmarklet for Archive.is to navigate to the canonical link with the “redirected from” instead of “saved from”

Posted by jpluimers on 2026/01/27

This is a follow-up on Bookmarklet for Archive.is to navigate to the canonical link which can be accessed from multiple URLs, some through redirection:

You can see the difference in these archived links (the navivate was a typo that I only spotted after the original blog post got published):

I wanted a Bookmarklet to find the last link; the one in the referenced blog post didn’t.

The actual use case leading to document all this was the Archive.is archived version of archive.org/download/beagle.applearchives.composters/Poster%2010.pdf (more on the posters in slightly less than a year at the blog post Beagle Bros recreated in modern color… | Applefritter).

That archived version can be reached through these URLs:

Inspiration for the below script is from another set of Bookmarklets I blogged about in The JavaScript bookmarklets that saved me a lot of time documenting the Embarcadero docwiki outage.

I first hesitated a bit to use the ` based template strings in that blog post, and opted to use join instead inspired by [Wayback/Archive] How can I build/concatenate strings in JavaScript? – Stack Overflow (thanks [Wayback/Archive] MrHaze and [Wayback/Archive] typically) which shows both methods combined.

Later I decided to revert, as using join, see below why.

Documentation for both methods is here:

Oh: one reason for not using template literals is that it is way easier to embed a one-liner into something like js-tokenizer for syntax highlighting.

Note that:

  1. the ?. operator prevents error messages when one or more of the queries return no output. The end result is one or more undefined to appear in the navigated URL. That’s better than crashing without navigating and having to check the browser debugger why that happened
  2. I wipe most of the anchor (basically everything on the right side) because setting the pathname will not clear the search (query) and hash (fragment) parts if redirectFrom does not have those. This sort of makes the starting point a Clean URL as much as possible.
  3. I now prefer the ` version as the second note in this list caused the join construct to need two of them: one for the separator bit, and the other with an empty separator. This made the code too convoluted.

join version of the Bookmarklet script

javascript: (function() {
  canonical = document.querySelector('link[rel="canonical"]')?.href;
  anchor = document.createElement("a");
  anchor.href = canonical;
  pathname = anchor.pathname;
  separator = "/";
  splitPathname = pathname.split(separator);
  timestamp = splitPathname[1];
  redirectFrom = document.querySelectorAll('input[readonly]')[0]?.value;
  anchor.pathname = "";
  anchor.search = "";
  anchor.fragment = "";
  hrefLeftParts = [anchor.href, timestamp];
  hrefLeft = hrefLeftParts.join("");
  hrefFullParts = [hrefLeft, redirectFrom];
  href = hrefFullParts.join(separator);
  location = href;
})();

As one-liner:

javascript:(function(){canonical = document.querySelector('link[rel="canonical"]')?.href; anchor = document.createElement("a"); anchor.href = canonical; pathname = anchor.pathname; separator = "/"; splitPathname = pathname.split(separator); timestamp = splitPathname[1]; redirectFrom = document.querySelectorAll('input[readonly]')[0]?.value; anchor.pathname = ""; anchor.search = ""; anchor.fragment = ""; hrefLeftParts = [anchor.href, timestamp]; hrefLeft = hrefLeftParts.join(""); hrefFullParts = [hrefLeft, redirectFrom]; href = hrefFullParts.join(separator); location = href;})();

` version of the Bookmarklet script

javascript: (function() {
  canonical = document.querySelector('link[rel="canonical"]')?.href;
  anchor = document.createElement("a");
  anchor.href = canonical;
  pathname = anchor.pathname;
  separator = "/";
  splitPathname = pathname.split(separator);
  timestamp = splitPathname[1];
  redirectFrom = document.querySelectorAll('input[readonly]')[0]?.value;
  anchor.pathname = "";
  anchor.search = "";
  anchor.hash = "";
  href = anchor.href;
  hrefTemplate = `${href}${timestamp}${separator}${redirectFrom}`;
  anchor.href = hrefTemplate;
  location = anchor.href;
})();

As one-liner:

javascript:(function(){canonical = document.querySelector('link[rel="canonical"]')?.href; anchor = document.createElement("a"); anchor.href = canonical; pathname = anchor.pathname; separator = "/"; splitPathname = pathname.split(separator); timestamp = splitPathname[1]; redirectFrom = document.querySelectorAll('input[readonly]')[0]?.value; anchor.pathname = ""; anchor.search = ""; anchor.hash = ""; href = anchor.href; hrefTemplate = `${href}${timestamp}${separator}${redirectFrom}`; anchor.href = hrefTemplate; location = anchor.href;})();

Tools used

Documentation references

--jeroen


Both scripts syntax highlighted from in a gist

[Wayback/Archive] Bookmarklet for Archive.is to navigate to the canonical link with the “redirected from” instead of “saved from” · GitHub


javascript: (function() {
canonical = document.querySelector('link[rel="canonical"]')?.href;
anchor = document.createElement("a");
anchor.href = canonical;
pathname = anchor.pathname;
separator = "/";
splitPathname = pathname.split(separator);
timestamp = splitPathname[1];
redirectFrom = document.querySelectorAll('input[readonly]')[0]?.value;
anchor.pathname = "";
anchor.search = "";
anchor.hash = "";
href = anchor.href;
hrefTemplate = `${href}${timestamp}${separator}${redirectFrom}`;
anchor.href = hrefTemplate;
location = anchor.href;
})();


javascript:(function(){canonical = document.querySelector('link[rel="canonical"]')?.href; anchor = document.createElement("a"); anchor.href = canonical; pathname = anchor.pathname; separator = "/"; splitPathname = pathname.split(separator); timestamp = splitPathname[1]; redirectFrom = document.querySelectorAll('input[readonly]')[0]?.value; anchor.pathname = ""; anchor.search = ""; anchor.hash = ""; href = anchor.href; hrefTemplate = `${href}${timestamp}${separator}${redirectFrom}`; anchor.href = hrefTemplate; location = anchor.href;})();


javascript: (function() {
canonical = document.querySelector('link[rel="canonical"]')?.href;
anchor = document.createElement("a");
anchor.href = canonical;
pathname = anchor.pathname;
separator = "/";
splitPathname = pathname.split(separator);
timestamp = splitPathname[1];
redirectFrom = document.querySelectorAll('input[readonly]')[0]?.value;
anchor.pathname = "";
anchor.search = "";
anchor.fragment = "";
hrefLeftParts = [anchor.href, timestamp];
hrefLeft = hrefLeftParts.join("");
hrefFullParts = [hrefLeft, redirectFrom];
href = hrefFullParts.join(separator);
location = href;
})();


javascript:(function(){canonical = document.querySelector('link[rel="canonical"]')?.href; anchor = document.createElement("a"); anchor.href = canonical; pathname = anchor.pathname; separator = "/"; splitPathname = pathname.split(separator); timestamp = splitPathname[1]; redirectFrom = document.querySelectorAll('input[readonly]')[0]?.value; anchor.pathname = ""; anchor.search = ""; anchor.fragment = ""; hrefLeftParts = [anchor.href, timestamp]; hrefLeft = hrefLeftParts.join(""); hrefFullParts = [hrefLeft, redirectFrom]; href = hrefFullParts.join(separator); location = href;})();

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.