How to Programmatically Submit Websites & Webpages to the Internet Archive’s Wayback Machine

This blog post is brought to you by the developer of BitBudget. BitBudget is an automated budgeting app for Android and iOS which syncs with your bank account and helps you avoid overspending. If you’d like to quit living paycheck-to-paycheck and get a better handle on your finances, download it today! https://bitbudget.io

Welcome back internet friend,

Tonight I started hacking on an old project on which I’m currently bringing back to life, a chrome extension which saves all of the pages you visit to the Internet Archive’s Wayback Machine. It’s called The Internet Archivist’s Intrepid Extension.

Unfortunately I had to kill off the first version of the extension because cloudflare started blocking all of my traffic. However, I discovered today that Archive.org has an API for submitting links programmatically. So the Intrepid Extension is back!

After an hour or so of hacking I’ve put together a pretty simple prototype and thought maybe I should share the source code here on the blog in case anyone else is stumbling around the internet looking for a solution. Enjoy!

<!DOCTYPE html>
<html>
<body>
<input id="urlInput" type="text" size="40" placeholder="Enter URL to Archive">
<button onclick="archive();">ARCHIVE</button>
<script>
var data;
function archive() {
var urlInput = document.getElementById('urlInput');
var url = document.getElementById('urlInput').value;
urlInput.value = ""; // clear url text input field
ajaxRequest = new XMLHttpRequest();
if (!ajaxRequest) {
alert("ERROR 0001: PC LOAD LETTER");
return; // kill, do not run rest of function
}
// json data which we will be sending to the server via ajax
data = {
"url": url
};
ajaxRequest.onreadystatechange = function() {
if (ajaxRequest.readyState === XMLHttpRequest.DONE) {
if (ajaxRequest.status === 200) {
// raw server response, may need to parse JSON if
// the server you are pinging will be responding
// with JSON
var serverResponse = ajaxRequest.responseText;
console.log(serverResponse);
alert(serverResponse);
} else {
alert("ERROR 0002: PC LOAD LETTER ");
}
}
};
ajaxRequest.open('POST', "https://pragma.archivelab.org");
ajaxRequest.setRequestHeader('Content-type', 'application/json');
ajaxRequest.send(JSON.stringify(data));
}
</script>
</body>
</html>
 

topherPedersen