Guest User

Untitled

a guest
Aug 6th, 2025
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Instagram s9e Stealthgram Link Inserter
  3. // @namespace    https://stealthgram.com/
  4. // @version      2024.08.05
  5. // @description  Seamlessly insert Stealthgram media links under s9e Instagram embeds on any page, with duplicate prevention and dynamic embed handling
  6. // @match        *://*www.thecoli.com/threads/*
  7. // @match        *://*/threads/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.   'use strict';
  13.  
  14.   const debug = false; // Set to true for console.log debugging
  15.  
  16.   function log(msg) { if (debug) console.log('[Stealthgram userscript]', msg); }
  17.  
  18.   function getInstagramMediaId(iframe) {
  19.     if (!iframe || !iframe.src) return null;
  20.     const match = iframe.src.match(/#([A-Za-z0-9_-]{5,})/);
  21.     return match ? match[1] : null;
  22.   }
  23.  
  24.   function insertStealthgramLink(iframe, mediaId) {
  25.     if (!iframe || !mediaId) return;
  26.     if (iframe.getAttribute('data-stealthgram-done')) return;
  27.  
  28.     // Add <br> and then link
  29.     const br = document.createElement('br');
  30.     const link = document.createElement('a');
  31.     link.href = 'https://stealthgram.com/media/' + mediaId;
  32.     link.textContent = 'Stealthgram link';
  33.     link.target = '_blank';
  34.     link.rel = 'noopener noreferrer';
  35.     link.className = 'stealthgram-link';
  36.     link.style = 'font-size:90%;font-family:monospace;';
  37.     iframe.insertAdjacentElement('afterend', br);
  38.     br.insertAdjacentElement('afterend', link);
  39.     iframe.setAttribute('data-stealthgram-done', '1');
  40.     log('Inserted for ' + mediaId);
  41.   }
  42.  
  43.   let throttleTimeout;
  44.   function processEmbeds() {
  45.     if (throttleTimeout) return;
  46.     throttleTimeout = setTimeout(() => {
  47.       throttleTimeout = null;
  48.       const embeds = document.querySelectorAll('iframe[data-s9e-mediaembed="instagram"]');
  49.       for (let iframe of embeds) {
  50.         const mediaId = getInstagramMediaId(iframe);
  51.         if (mediaId) insertStealthgramLink(iframe, mediaId);
  52.       }
  53.     }, 200);
  54.   }
  55.  
  56.   processEmbeds();
  57.  
  58.   // Observe for dynamically-added embeds
  59.   const observer = new MutationObserver(() => { processEmbeds(); });
  60.   observer.observe(document.body, {childList: true, subtree: true});
  61.  
  62.   log('Instagram Stealthgram userscript loaded.');
  63. })();
Advertisement
Add Comment
Please, Sign In to add comment