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

  • Email Subscription

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

    Join 717 other subscribers

Bookmarklets for going from the Wayback Machine to Archive Today

Posted by jpluimers on 2026/08/20

To ease my blogging, I wrote two more Bookmarklets that help me navigate to or save from a Wayback machine archived page to Archive Today.

A key thing I learned over the past 2+ decades is that “the cloud” (i.e. cloud computing) is “just someone else’s computer” which tends to be unavailable right when you need it no matter the applicable service-level agreement.

Which means that a long while ago, I switched to archiving external links to both the Wayback machine and Archive Today.

Since the Wayback machine is my primary, it helps to have Bookmarklets to go from such an archived page to the equivalent one on Archive Today, or even save it if it isn’t there.

So I made two more Bookmarklets which I will illustrate using the example.org based links https://example.org and http://example.org:

  1. From https://web.archive.org/web/20230613073639/https://wiert.me/ to https://archive.is/https://web.archive.org/web/20230613073639/https://wiert.me/
  2. From https://web.archive.org/web/20230613090050/http://wiert.me/ to https://archive.is/https://web.archive.org/web/20230613090050/http://wiert.me/
  3. From https://web.archive.org/web/20230613073639/https://wiert.me/ to https://archive.is/https://wiert.me/
  4. From https://web.archive.org/web/20230613090050/http://wiert.me/ to https://archive.is/http://wiert.me/

Note I disregarded ftp as I think was never supported by Archive.is and it has been phased out at the Wayback machine: [Wayback/Archive] Internet Archive Forums: FTP read-access is going away

Apr 8, 2009 10:53am
Forum: etree Subject: FTP read-access is going away

The Archive will continue to support FTP uploading for some time, but we are phasing out FTP read access in favor of HTTP (web) access.

FTP is pretty ancient and makes it hard for us to support well.

We hope this will not be a major inconvenience.

-brewster
Digital Librarian, Internet Archive

I put 1. and 2. first up front as at first I thought those would be the easiest as they would not require a regular expression. But then I figured I would only want the Bookmarklet to execute if the URL originated from a valid Wayback machine archived link.

So I came up with this regular expression:

^((https:\/\/web\.archive\.org\/web\/\d+\/)((http|https):\/\/.+))$

It solves all four cases by embedding the various bits in groups, so lets try to explain the various bits and the grouping by converting the groups into a tree:

^((https:\/\/web\.archive\.org\/web\/\d+\/)((http|https):\/\/.+))$
bit explanation
^ ^ asserts position at start of a line (which makes it easier to skip non-URLs in regex101)
 ( start of group 1 ($1 in the output)
  ( start of group 2 ($2 in the output)
   https:\/\/web\.archive\.org\/web\/\d+\/ group 2 ($2 in the output):
matches “https://web\.archive\.org/web/d+/” where “\d+” matches one or more digits: the Wayback machine archival timestamp
  ) end of group 2 ($2 in the output)
  ( start of group 3 ($3 in the output)
   ( start of group 4 ($4 in the output)
    http|https group 4 ($4 in the output):
because this is inside a group, it matches either “http” or “https”
alternatively replace “(http|https)” with “https?“
   ) end of group 4 ($4 in the output)
  :\/\/.+ trailing bit of group 3 ($3 in the output):
this matches the “://” bit of a URL where “.+” matches one or more characters; together with the previous group, this completes group 3 into “((http|https):\/\/.+)”  which matches an http or https URL.
   ) end of group 3 ($3 in the output)
 ) end of group 1 ($1 in the output)
$ $ asserts position at the end of a line

You can see the results in these two regex101 examples:

Now I used what I learned in XKCD to ExplainXKCD Bookmarklet to write the Bookmarklets:

  1. javascript:{ url = new URL(location.href.replace( /^((https:\/\/web\.archive\.org\/web\/\d+\/)((http|https):\/\/.+))$/g, 'https:/archive.is/$3')); if (location.href !== url.href) { location=url }}
  2. javascript:{ url = new URL(location.href.replace( /^((https:\/\/web\.archive\.org\/web\/\d+\/)((http|https):\/\/.+))$/g, 'https:/archive.is/$1')); if (location.href !== url.href) { location=url }}

These look convoluted and they are. Like on the above blog post, I used the JavaScript runner on the [Wayback/Archive] String.prototype.replace() – JavaScript | MDN documentation page to work my way from simple to convoluted:

  1. javascript:{ prompt("URL", location.href.replace( /^((https:\/\/web\.archive\.org\/web\/\d+\/)((http|https):\/\/.+))$/g, 'https:/archive.is/$3') ); }
  2. javascript:{ prompt("URL", location.href.replace( /^((https:\/\/web\.archive\.org\/web\/\d+\/)((http|https):\/\/.+))$/g, 'https:/archive.is/$1') ); }
  3. javascript:{ url = new URL(location.href.replace( /^((https:\/\/web\.archive\.org\/web\/\d+\/)((http|https):\/\/.+))$/g, 'https:/archive.is/$3')); console.log(location.href); console.log(url.href); if (location.href !== url.href) { location=url }}
  4. javascript:{ url = new URL(location.href.replace( /^((https:\/\/web\.archive\.org\/web\/\d+\/)((http|https):\/\/.+))$/g, 'https:/archive.is/$1')); console.log(location.href); console.log(url.href); if (location.href !== url.href) { location=url }}
  5. javascript:{ url = new URL(location.href.replace( /^((https:\/\/web\.archive\.org\/web\/\d+\/)((http|https):\/\/.+))$/g, 'https:/archive.is/$3')); if (location.href !== url.href) { location=url }}
  6. javascript:{ url = new URL(location.href.replace( /^((https:\/\/web\.archive\.org\/web\/\d+\/)((http|https):\/\/.+))$/g, 'https:/archive.is/$1')); if (location.href !== url.href) { location=url }}

I really wish this worked with the [Wayback/Archive] Window: open() method – Web APIs | MDN, but somehow it fails as I documented in [Wayback/Archive] Bookmarklets that navigate from Wayback Machine to Archive Today: I wonder why changing location works, but open fails (it opens on the wrong address).

I got a really useful response to [Wayback/Archive] Jeroen Wiert Pluimers @wiert@mastodon.social on Twitter: “I need some help with JavaScript when writing Bookmarklets: Changing location navigates to the correct URLs, but window​.open goes to the wrong one (after first logging the correct one) Anyone with insights on this? … likely miss something obvious (:”

Solutions for now (will beautify this later, will also post about Wombat later at The Wayback Machine uses Wombat from Webrecorder (digipres.club/@webrecorder) (@webrecorder_io) / Twitter):

  • javascript:{ window.open().location = location.href.replace(/^https?:\/\/web\.archive\.org\/web\/\d+\//, 'https://archive.is/'); void(0); }
  • javascript:{ window.open().location = 'https://archive.is/' + location.href; void(0); }

By then I will also remove the void(0); hack (which ensures the bookmarklet will not leak the location assignment result as text in the originating page) by using an anonymous function as you can see in [Wayback/Archive] javascript – How to prevent bookmarklet from loading its result? – Stack Overflow (thanks [Wayback/Archive] Erics, [Wayback/Archive] DG. and [Wayback/Archive] Musa):

The accepted way these days is to wrap your code in an “immediately invoked function expression” like this
(function(){ /*your code */})();
This is better than adding void(0); at the end because wrapping your code in a function prevents conflicts between named variable and function in your bookmarklet and in those in the scope of the parent HTML document.

Related Bookmarklet posts:

  1. Need to write a proper bookmarklet for the wayback archive (:
  2. Bookmarklets for Archive.is and the WayBack Machine to go to the original page
  3. Bookmarklet to save a page both in the WayBack machine and Archive.is (ending on the latter to solve a reCAPTCHA)
  4. XKCD to ExplainXKCD Bookmarklet
  5. The Wayback Machine Chrome extension got a big update. Every journalist & researcher should install it ASAP! Faster URL archiving w/ customization, access to yr personal archive, and it tells you if the page you’re on has already been archived, etc.
  6. Notes for a Bookmarklet that fixes Wayback Machine archivals of Google Search queries

–jeroen

https://gist.github.com/jpluimers/daa25e6f98146ede71cbb8aee1f95148

Leave a Comment