Created
October 11, 2022 14:55
-
-
Save antiops/00a37a1de289415fa7cbd9b5d1d29c54 to your computer and use it in GitHub Desktop.
Automatically save the page you're on 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
// ==UserScript== | |
// @name Auto Wayback | |
// @description Automatically save the page you're on to the Internet Archive's Wayback Machine. | |
// @version 1.0.0 | |
// | |
// @match https://wsj.com/* | |
// @match https://cnn.com/* | |
// @match https://*.cnn.com/* | |
// @match https://theguardian.com/* | |
// @match https://snopes.com/* | |
// @match https://theverge.com/* | |
// @match https://bloomberg.com/* | |
// @match https://*.foxnews.com/* | |
// @match https://washingtonpost.com/* | |
// @match https://theregister.com/* | |
// @match https://wired.com/* | |
// @match https://cbsnews.com/* | |
// @match https://nytimes.com/* | |
// @match https://forbes.com/* | |
// @match https://newyorker.com/* | |
// @match https://theatlantic.com/* | |
// @match https://variety.com/* | |
// @match https://bbc.com/* | |
// @match https://reason.com/* | |
// @match https://techdirt.com/* | |
// @match https://slate.com/* | |
// @match https://*.wikipedia.org/* | |
// @match https://wikipedia.org/* | |
// @match https://*.spiegel.de/* | |
// @match https://spiegel.de/* | |
// @match https://news.ycombinator.com/* | |
// @match https://arstechnica.com/* | |
// @match https://medium.com/* | |
// @match https://smithsonianmag.com/* | |
// | |
// @grant GM_xmlhttpRequest | |
// @run-at document-start | |
// ==/UserScript== | |
(async () => { | |
const save_visited = true | |
const save_all_links = false // Enable 'Save outlinks' (Requires Cookie) | |
const save_all_links_no_host_restriction = true | |
const IAcookie = '' | |
const saveAllLinks = () => { | |
let sent_array = [] | |
for (var elements1 = document.getElementsByTagName("a"), i = elements1.length - 1; i >= 0; i--) { | |
const URL1 = decodeURI(elements1[i].href) | |
if ((save_all_links_no_host_restriction || URL1.match(location.hostname)) && -1 === sent_array.indexOf(URL1)) { | |
sent_array[sent_array.length] = URL1 | |
GM_xmlhttpRequest({ | |
method: 'POST', | |
url: `http://web.archive.org/save/${encodeURI(URL1)}`, | |
data: `url=${encodeURI(URL1)}&capture_outlinks=on&capture_all=on&capture_screenshot=on`, | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'cookie': IAcookie, | |
'referer': 'https://web.archive.org/save' | |
} | |
}) | |
console.log('http://web.archive.org/' + encodeURI(URL1)) | |
// Print URI lists you have sent the request to save. (on console, for debug) | |
} | |
} | |
} | |
// Save the page you have just visited. | |
if (save_visited) { | |
GM_xmlhttpRequest({ | |
method: 'POST', | |
url: `http://web.archive.org/save/${encodeURI(decodeURI(location.href))}`, | |
data: `url=${encodeURI(decodeURI(location.href))}&capture_outlinks=on&capture_all=on&capture_screenshot=on`, | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'cookie': IAcookie, | |
'referer': 'https://web.archive.org/save' | |
} | |
}) | |
console.log('http://web.archive.org/' + encodeURI(decodeURI(location.href))); | |
}; | |
// Save all links you can see on a page. | |
if (save_all_links) { | |
setTimeout(function() { | |
saveAllLinks() | |
}, 5000) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment