Skip to content

Instantly share code, notes, and snippets.

@blackout314
Created January 15, 2024 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackout314/c1b5386914968dec776964468f937d45 to your computer and use it in GitHub Desktop.
Save blackout314/c1b5386914968dec776964468f937d45 to your computer and use it in GitHub Desktop.
altcoinstalks.com archiveis/shorturl utility v1.0
// ==UserScript==
// @name archive-is_altcoinstalks
// @namespace https://www.altcoinstalks.com/
// @description multi-utility v 1.0
// @include https://www.altcoinstalks.com/*
// @require https://code.jquery.com/jquery-2.2.4.min.js
// @grant window.focus
// ==/UserScript==
var links,thisLink;
const replace = 'https://';
const replaced = 'https://archive.is/?run=1&url=https://';
let loc;
var openAndClose = function(elem) {
var url = elem.originalTarget.dataset.www;
let newWindow = window.open(url, '_blank' /*, 'width=300,height=300'*/);
window.focus();
console.log('URL', url);
setTimeout(function(){
loc = newWindow.location;
console.log('ARCHIVE', loc);
elem.originalTarget.innerText = '✅';
//newWindow.close();
}, 2000);
}
function createPageLink() {
var archivethis = window.location.href;
var newHTML = document.createElement ('div');
newHTML.innerHTML = '&nbsp; <style>.g{background:green; color:white;} .o{background:orange;}</style><span id="toolbar-dash"> <span><a data-ref="current" title="archive-is" target="_blank" href="https://archive.is/?run=1&url='+archivethis+'">ARCHIVE 📦</a></span> '+
' <span><a data-ref="current" title="short-is" target="_blank" href="https://tinyurl.com/create.php?url='+archivethis+'">SHORT 🔗</a></span>'+
' <span id="extraspace">.</span> &nbsp; <span id="extracount"></span> </span> <span id="toolbar-close">✖️</span> &nbsp;';
newHTML.style = 'position:fixed;top:0;left:0px;border:1px black solid;background:white;font-size:8px;';
document.body.appendChild(newHTML);
}
function createArchiveLink(archivethis, thisLink, dataattrib) {
var newHTML = document.createElement ('span');
newHTML.innerHTML = '</a> ['+
'<a target="_blank" href="https://tinyurl.com/create.php?url='+thisLink+'">🔗</a> '+
'<a data-ref="'+dataattrib+'" title="archive-is" target="_blank" href="'+archivethis+'">📦</a>'+
']';
thisLink.parentNode.insertBefore(newHTML, thisLink.nextSibling);
}
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
function isForumLink(thisLink) {
return thisLink.href.indexOf('altcoinstalks') > 0;
}
links = document.evaluate("//td[@class='subject windowbg2']/div/span/a", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i=0;i<links.snapshotLength;i++) {
var thisLink = links.snapshotItem(i);
if(isForumLink(thisLink)) {
var archivethis = thisLink.href.replace(replace, replaced);
console.log(thisLink);
createArchiveLink(archivethis, thisLink, 'one');
}
}
links = document.evaluate("//div[@class='subject']/a[@href]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i=0;i<links.snapshotLength;i++) {
var thisLink = links.snapshotItem(i);
if(isForumLink(thisLink)) {
var archivethis = thisLink.href.replace(replace, replaced);
console.log(thisLink);
createArchiveLink(archivethis, thisLink, 'two');
}
}
links = document.evaluate("//a[text()='All']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i=0;i<links.snapshotLength;i++) {
var thisLink = links.snapshotItem(i);
if(isForumLink(thisLink)) {
var archivethis = thisLink.href.replace(replace, replaced);
console.log(thisLink);
createArchiveLink(archivethis, thisLink, 'three');
}
}
document.querySelectorAll('.new').forEach((elem) => {
elem.addEventListener('click', openAndClose, false);
});
createPageLink();
var closed_flag = false;
$('#toolbar-close').off('click');
$('#toolbar-close').on('click', function(e){
if(closed_flag) {
$('#toolbar-dash').css('display','initial');
closed_flag = false;
} else {
$('#toolbar-dash').css('display','none');
closed_flag = true;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment