Created
February 15, 2023 18:29
-
-
Save piyush01123/f05a452bcafa85e523a3c7f1f72c17ec to your computer and use it in GitHub Desktop.
Auto WayBack - Load latest snapshot from Wayback Machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Auto Wayback | |
// @namespace http://tampermonkey.net/ | |
// @version 3.1.1 | |
// @description Load latest snapshot from Wayback Machine | |
// @author Piyush Singh | |
// @match *://*/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant unsafeWindow | |
// ==/UserScript== | |
// To Use just press Ctrl+L and you will be redirected to Wayback URL. | |
// Can also be used from your browser console by `wayback()` | |
function wayback() | |
{ | |
var url = "https://archive.org/wayback/available?url="+document.URL; | |
const xhr = new XMLHttpRequest(); | |
xhr.open("GET", url); | |
xhr.send(); | |
xhr.responseType = "json"; | |
xhr.onload = () => { | |
if (xhr.readyState == 4 && xhr.status == 200) { | |
console.log("valid"); | |
console.log(xhr.response); | |
if (Object.keys(xhr.response.archived_snapshots).length==0) | |
{ | |
window.alert("No snapshot found in Wayback Machine."); | |
return; | |
} | |
var wayback_url = xhr.response.archived_snapshots.closest.url; | |
window.location.replace(wayback_url); | |
} else { | |
console.log(`Error: ${xhr.status}`); | |
} | |
}; | |
} | |
(function() { | |
'use strict'; | |
if(!unsafeWindow.wayback) unsafeWindow.wayback = wayback; | |
document.onkeyup=function(ev){ | |
// var ev = ev || window.event; // for IE to cover IEs window object | |
if(ev.ctrlKey && ev.which == 76) { | |
wayback(); | |
return false; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment