Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Instagram s9e Stealthgram Link Inserter
- // @namespace https://stealthgram.com/
- // @version 2025.08.16.2
- // @description Seamlessly insert Stealthgram links under Instagram embeds and Twstalker/xstalk/archive/nitter/etc. links under Twitter embeds (s9e), with duplicate prevention, spacing, and dynamic embed handling
- // @match *://*www.thecoli.com/threads/*
- // @match *://*/threads/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- const debug = false; // Set to true for console.log debugging
- function log(msg) { if (debug) console.log('[Stealthgram userscript]', msg); }
- // =========================
- // Instagram support
- // =========================
- function getInstagramMediaId(iframe) {
- if (!iframe || !iframe.src) return null;
- const match = iframe.src.match(/#([A-Za-z0-9_-]{5,})/);
- return match ? match[1] : null;
- }
- function insertStealthgramLink(iframe, mediaId) {
- if (!iframe || !mediaId) return;
- if (iframe.getAttribute('data-stealthgram-done')) return;
- // Add spacing
- const br1 = document.createElement('br');
- const br2 = document.createElement('br');
- const link = document.createElement('a');
- link.href = 'https://stealthgram.com/media/' + mediaId;
- link.textContent = 'Stealthgram link';
- link.target = '_blank';
- link.rel = 'noopener noreferrer';
- link.className = 'stealthgram-link';
- link.style = 'font-size:90%;font-family:monospace;text-decoration:underline;';
- iframe.insertAdjacentElement('afterend', br1);
- br1.insertAdjacentElement('afterend', link);
- link.insertAdjacentElement('afterend', br2);
- iframe.setAttribute('data-stealthgram-done', '1');
- log('Inserted Stealthgram link for ' + mediaId);
- }
- // =========================
- // Twitter support
- // =========================
- function createTwitterLinks(tweetId) {
- const baseTwitter = `https://twitter.com/undefined/status/${tweetId}`;
- const baseTwstalker = `https://twstalker.com/undefined/status/${tweetId}`;
- const baseXstalk = `https://xstalk.com/profile/undefined/status/${tweetId}`;
- const baseXcancel = `https://xcancel.com/undefined/status/${tweetId}`;
- const baseNitter = `https://nitter.poast.org/undefined/status/${tweetId}`;
- return {
- twstalker: baseTwstalker,
- archiveOrgSave: `https://web.archive.org/save/${baseTwstalker}`,
- archiveIs: `https://archive.is/?run=1&url=${baseTwstalker}`,
- xstalk: baseXstalk,
- xstalkSave: `https://web.archive.org/save/${baseXstalk}`,
- archiveIsXstalk: `https://archive.is/?run=1&url=${baseXstalk}`,
- archiveIsX: `https://archive.is/?run=1&url=${baseTwitter}`,
- nitter: baseNitter,
- xcancel: baseXcancel,
- xcancelSave: `https://archive.is/?run=1&url=${baseXcancel}`
- };
- }
- function insertTwitterLinks(iframe, tweetId) {
- if (!iframe || !tweetId) return;
- if (iframe.getAttribute('data-twstalker-done')) return;
- const links = createTwitterLinks(tweetId);
- const container = document.createElement('div');
- container.style = 'font-size:90%;font-family:monospace;';
- container.innerHTML = `
- <a href="${links.twstalker}" target="_blank" style="text-decoration:underline;">twstalker</a> |
- <a href="${links.archiveOrgSave}" target="_blank" style="text-decoration:underline;">archive.org(save)</a> |
- <a href="${links.archiveIs}" target="_blank" style="text-decoration:underline;">archive.is</a> |
- <a href="${links.xstalk}" target="_blank" style="text-decoration:underline;">xstalk</a> |
- <a href="${links.xstalkSave}" target="_blank" style="text-decoration:underline;">xstalk(save)</a> |
- <a href="${links.archiveIsXstalk}" target="_blank" style="text-decoration:underline;">archive.is(xstalk)</a> |
- <a href="${links.archiveIsX}" target="_blank" style="text-decoration:underline;">archive.is(X)</a> |
- <a href="${links.nitter}" target="_blank" style="text-decoration:underline;">nitter</a> |
- <a href="${links.xcancel}" target="_blank" style="text-decoration:underline;">xcancel</a> |
- <a href="${links.xcancelSave}" target="_blank" style="text-decoration:underline;">xcancel(save)</a>
- `;
- // Add spacing
- const br1 = document.createElement('br');
- const br2 = document.createElement('br');
- iframe.insertAdjacentElement('afterend', br1);
- br1.insertAdjacentElement('afterend', container);
- container.insertAdjacentElement('afterend', br2);
- iframe.setAttribute('data-twstalker-done', '1');
- log('Inserted Twstalker/xstalk/etc links for tweet ' + tweetId);
- }
- function getTweetId(iframe) {
- if (!iframe || !iframe.src) return null;
- const match = iframe.src.match(/#(\d{5,})/);
- return match ? match[1] : null;
- }
- // =========================
- // Processing
- // =========================
- let throttleTimeout;
- function processEmbeds() {
- if (throttleTimeout) return;
- throttleTimeout = setTimeout(() => {
- throttleTimeout = null;
- // Instagram
- const igEmbeds = document.querySelectorAll('iframe[data-s9e-mediaembed="instagram"]');
- for (let iframe of igEmbeds) {
- const mediaId = getInstagramMediaId(iframe);
- if (mediaId) insertStealthgramLink(iframe, mediaId);
- }
- // Twitter
- const twEmbeds = document.querySelectorAll('iframe[data-s9e-mediaembed="twitter"]');
- for (let iframe of twEmbeds) {
- const tweetId = getTweetId(iframe);
- if (tweetId) insertTwitterLinks(iframe, tweetId);
- }
- }, 200);
- }
- processEmbeds();
- const observer = new MutationObserver(() => { processEmbeds(); });
- observer.observe(document.body, {childList: true, subtree: true});
- log('Instagram + Twitter userscript loaded.');
- })();
Advertisement
Add Comment
Please, Sign In to add comment