upcoming / upcoming-www

Upcoming.org Site
Apache License 2.0
168 stars 15 forks source link

Rewrite outgoing links to point to the Internet Archive Wayback Machine #7

Open hubgit opened 8 years ago

hubgit commented 8 years ago

As many of the pages linked to from event descriptions have disappeared, it would be nice to link to an appropriate point in time in the Wayback Machine instead.

This client-side JS should do the job:

// select links in the event description
var links = document.querySelectorAll('.recommend-quote a[href]')

if (links.length) {
  // this would be unnecessary if the event date was already in ISO format (ideally in a time[datetime] tag)
  var eventDate = document.querySelector('h1 small').textContent
  var archiveDate = new Date(eventDate).toISOString().substr(0, 10).replace(/-/g, '')

  Array.prototype.forEach.call(links, function(link) {
    // link to the closest available snapshot of the URL in the Wayback Machine
    link.href = 'https://web.archive.org/web/' + archiveDate + '/' + link.href
  })
}