48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
// ==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);
|
|
} |