Created
December 7, 2019 23:17
-
-
Save topherPedersen/a834d013a6739e09cbaa3afaab752af7 to your computer and use it in GitHub Desktop.
Programmatically Submit Websites & Webpages to the Internet Archive's Wayback Machine
This file contains 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
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment