Skip to content

Instantly share code, notes, and snippets.

@felipebueno
Last active March 12, 2024 22:06
Show Gist options
  • Save felipebueno/b44f9d2e7709d8c6e67c0bdc08dce133 to your computer and use it in GitHub Desktop.
Save felipebueno/b44f9d2e7709d8c6e67c0bdc08dce133 to your computer and use it in GitHub Desktop.
TamperMonkey script to help DarthCoin find the Stacker Saloon on https://stacker.news
// ==UserScript==
// @name stacker saloon
// @namespace http://tampermonkey.net/
// @version 2024-03-12
// @description try to take over the world!
// @author You
// @match https://stacker.news/
// @icon https://www.google.com/s2/favicons?sz=64&domain=stacker.news
// @grant none
// ==/UserScript==
(function () {
'use strict';
// https://stacker.news/items/461163
const anchors = document.querySelectorAll('a');
for (const anchor of anchors) {
const text = anchor.textContent.trim();
let theOne;
if (text.includes('Stacker Saloon')) {
// Check if any child element contains the string "@saloon" just to make sure we are in the correct place
for (const child of anchor.parentNode.parentNode.childNodes) {
if (child.textContent && child.textContent.includes('@saloon')) {
theOne = anchor;
break; // Done! We can break the loop now
}
}
if (theOne != null) {
const postAnchor = document.querySelector('a[href="/post"]');
if (postAnchor) {
console.log("Anchor tag found:", postAnchor.getAttribute('href'));
} else {
return;
}
const buttonHtml = `<div class="d-none d-lg-flex mx-2 btn btn-md btn-primary px-3 py-1" style="align-items: center;"><svg class="ms-1" height="16" width="16" xmlns="http://www.w3.org/2000/svg" viewBox="80 200 450 400"><path class="st0" d="M499.9,315.6c-17.2-10.5-28.7,0.6-36.6,7.9c-7.9,7.2-26.6,30.8-36.6,38.1c-10,7.2-27.5,13.6-53.9,16.7 c-26.3,3.1-50.5,1.4-47.8,1c2.7-0.4,10.6-2.2,12.4-3c1.8-0.9,11.3-4.3,33.7-11.9c22.4-7.6,36.5-17,39.4-18.7 c2.9-1.7,5.9-3.9,5.4-5.2s-2.2-8.1-5.1-15.8c-2.9-7.7-8.5-29.4-10.1-34.2c-1.6-4.8-3-13.1-5.9-19.5s-4.4-21.3-11.3-38.5 c-6.9-17.2-11.8-19.5-31.7-27.7c-19.8-8.2-57.8-6.9-57.8-6.9s-41.1,1.3-59.5,9.2c-18.4,7.9-22.8,19-23.4,20.6 c-0.6,1.6-12.9,44.2-12.9,44.2l-27.4,93.1c0,0-6-5.6-10.7-10.8c-4.5-5-29.9-36.9-44-41.1c-14.1-4.2-20.4,0.8-26.2,5.5 c-5.8,4.7-11.1,18.3-8.5,32.7c2.6,14.4,29.8,45.3,51,59.7c21.2,14.4,40.8,21.5,43.6,23.1c2.8,1.6,6.5,2.8,16,15.2 s32.5,32.3,45.8,41.6c13.4,9.4,34.8,22.1,44.6,26.8c9.8,4.7,14.9,3.6,14.9,3.6c8.8,0,36.1-15.4,50.6-25.1 c14.4-9.7,32.3-25.1,34.1-26.6c1.6-1.3,3.2-3.4,3.7-3.9c0.7-0.8,6-8.1,15.3-17s14.6-12.4,14.6-12.4l0.2-1.8c0,0,27-9.2,53.4-30.3 c26.5-21.1,39.1-43.5,41.4-48.5C512.8,350.8,517.1,326,499.9,315.6L499.9,315.6z M366.5,413.2c-17,7.4-32,14.7-53.7,17.6 c-21.7,2.9-39.3,0.3-57.4-5.8c-18.1-6.1-38.3-16.6-49.2-23.6c-10.9-7-22.7-16.6-22.7-16.6s74.7,8.7,110.6,8.4 c36-0.3,71.5-2.9,83.3-4.2c11.8-1.3,32.8-4.2,32.8-4.2S383.5,405.7,366.5,413.2L366.5,413.2z"></path><path class="st0" d="M415.7,449.1c0,0.1-0.2,1.2-6,4.5c-6.3,3.6-21.6,22.6-25.8,27.2c-4.2,4.7-27.5,22.3-27.5,22.3 S310.7,535,295.9,535s-43.1-21.3-58.4-31.3c-15.3-10-26.9-21.4-31.2-25.9c-4.2-4.5-13.8-15-20.5-21.7c-6.7-6.7-8.7-7-8.7-7 s-0.4,2.3,0,5.1c0.4,2.8,3.5,16.6,5.1,20.1s4.4,8.3,4.4,8.3s13.1,49.1,15.1,53.5s11.9,16.9,11.9,16.9l6,0.2l0.7,9 c0,0,0.7,0.9,2.5,2.5c1.8,1.6,18.6,20.4,22.3,23.6c3.6,3.2,15.6,15.6,28.3,17.8c12.7,2.2,23.3,2,40.8,0.9 c17.5-1.2,36.7-18.8,54.6-39.9c17.9-21.1,24.3-31.8,26.4-40.5s3.1-40.5,3.2-41.4c0.1-0.9,1.9,1.3,4.7,1.5c2.8,0.1,6.9-7.9,10.4-19.4 C416.6,456,415.8,449.5,415.7,449.1L415.7,449.1z M318.4,556.4c-6.8,7-16.8,12-20.7,12s-11.4-2.5-19.9-10.2 c-8.5-7.7-11.9-13-11.9-13s15.9,1.8,31,1.8s31-1.8,31-1.8S325.2,549.4,318.4,556.4L318.4,556.4z"></path></svg><a class="text-reset" href="${theOne.href}">Saloon</a></div>`;
const newElement = document.createElement('div');
newElement.innerHTML = buttonHtml;
setTimeout(() => {
postAnchor.insertAdjacentElement('afterend', newElement);
}, 333);
break;
}
// else keep searching until the end of anchors
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment