Skip to content

Instantly share code, notes, and snippets.

@evanreichard
Last active September 15, 2023 07:40
Show Gist options
  • Save evanreichard/83467a4775f1672756140fc9719eb9be to your computer and use it in GitHub Desktop.
Save evanreichard/83467a4775f1672756140fc9719eb9be to your computer and use it in GitHub Desktop.
Auto Archive Redirect
// ==UserScript==
// @name Auto Archive Redirect
// @namespace Evan Reichard
// @version 0.0.3
// @match *://*/*
// @grant GM.xmlhttpRequest
// @grant GM.openInTab
// @noframes
// @run-at document-start
// ==/UserScript==
GM.xmlhttpRequest({
url: 'https://archive.is/' + document.location.href,
method: 'GET',
responseType: 'document',
onloadend: processArchiveResponse
});
function processArchiveResponse(response){
const { response: archiveDocument } = response;
const archiveURL = archiveDocument.querySelector('#CONTENT #row0 a')?.href;
if (archiveURL) createArchiveButton(archiveURL);
}
function createArchiveButton(archiveURL){
let myDiv = document.createElement('div')
myDiv.innerHTML = `<span href="#" style="all: initial; display: flex; justify-content: center; cursor: pointer; position: fixed; opacity: 0; transition: 1s; width: 60px; height: 60px; bottom: 40px; right: 40px; background-color: #0C9; color: #FFF; border-radius: 50px; text-align: center; box-shadow: 2px 2px 3px #999;">
<h2 style="all: initial; align-self: center; font-size: 25px; color: white; cursor: pointer;">A</h2>
</span>`;
let spanEl = myDiv.children[0];
document.body.append(spanEl)
spanEl.onclick = () => {
document.location.href = archiveURL;
}
setTimeout(() => {
spanEl.style.opacity = '1';
}, 0);
setTimeout(() => {
spanEl.style.opacity = '0';
}, 5000);
setTimeout(() => {
spanEl.remove();
}, 6000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment