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 2024.08.05
- // @description Seamlessly insert Stealthgram media links under s9e Instagram embeds on any page, with duplicate prevention 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); }
- 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 <br> and then link
- const br = 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;';
- iframe.insertAdjacentElement('afterend', br);
- br.insertAdjacentElement('afterend', link);
- iframe.setAttribute('data-stealthgram-done', '1');
- log('Inserted for ' + mediaId);
- }
- let throttleTimeout;
- function processEmbeds() {
- if (throttleTimeout) return;
- throttleTimeout = setTimeout(() => {
- throttleTimeout = null;
- const embeds = document.querySelectorAll('iframe[data-s9e-mediaembed="instagram"]');
- for (let iframe of embeds) {
- const mediaId = getInstagramMediaId(iframe);
- if (mediaId) insertStealthgramLink(iframe, mediaId);
- }
- }, 200);
- }
- processEmbeds();
- // Observe for dynamically-added embeds
- const observer = new MutationObserver(() => { processEmbeds(); });
- observer.observe(document.body, {childList: true, subtree: true});
- log('Instagram Stealthgram userscript loaded.');
- })();
Advertisement
Add Comment
Please, Sign In to add comment