Guest User

Untitled

a guest
Sep 5th, 2025
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Multi-site mediaembed iframe reloader
  3. // @namespace    https://example.com/
  4. // @version      1.2
  5. // @description  Adds reload buttons to all s9e-mediaembed iframes
  6. // @include      */threads/*
  7. // @grant        none
  8. // ==/UserScript==
  9.  
  10. (function(){
  11.   'use strict';
  12.  
  13.   const DEBUG = false; // true = logs, false = silent
  14.   const BUTTON_POSITION = 'right'; // 'right' | 'left' | 'top' | 'bottom'
  15.  
  16.   const STYLE_ID = 'insta-iframe-reloader-style';
  17.   const BTN_CLASS = 'insta-reload-btn';
  18.   const WRAP_CLASS = 'insta-iframe-wrapper';
  19.   const FLAG = 'reloadAttached';
  20.  
  21.   // 1. List of all supported ids:
  22.   const SUPPORTED_IDS = [    "abcnews","acast","anchor","applepodcasts","audioboom","audiomack",
  23.     "audius","bandcamp","bbcnews","bitchute","bluesky","brightcove","bunny",
  24.     "captivate","castos","cbsnews","clyp","cnbc","cnn","cnnmoney","codepen",
  25.     "comedycentral","coub","crankers","dailymotion","democracynow","dumpert",
  26.     "eighttracks","espn","facebook","falstad","flickr","foxnews","funnyordie",
  27.     "gamespot","getty","gifs","giphy","gist","globalnews","gofundme",
  28.     "googledrive","googleplus","googlesheets","hudl","hulu","ign","imdb",
  29.     "imgur","indiegogo","instagram","internetarchive","izlesene","jsfiddle",
  30.     "jwplatform","kaltura","khl","kickstarter","libsyn","liveleak",
  31.     "livestream","mailru","mastodon","medium","megaphone","metacafe",
  32.     "mixcloud","mlb","mrctv","msnbc","nachovideo","natgeochannel",
  33.     "natgeovideo","nbcnews","nhl","npr","nytimes","odysee","omny","on3",
  34.     "orfium","pastebin","pinterest","podbean","prezi","reddit","rumble",
  35.     "rutube","scribd","sendvid","slideshare","soundcloud","sporcle",
  36.     "sportsnet","spotify","spreaker","steamstore","strawpoll","streamable",
  37.     "teamcoco","ted","telegram","theatlantic","theguardian","theonion",
  38.     "threads","tiktok","tmz","tradingview","traileraddict","trendingviews",
  39.     "tumblr","twentyfoursevensports","twitch","twitter","ustream","vbox7",
  40.     "veoh","vevo","videodetective","vimeo","vine","vk","vocaroo","vox",
  41.     "washingtonpost","wavekit","wistia","wshh","wsj","xboxclips","xboxdvr",
  42.     "xenforo","youku","youmaker","youtube"
  43.   ];
  44.  
  45.   // 2. Build the CSS selector:
  46.   const SELECTOR = SUPPORTED_IDS.map(id => `iframe[data-s9e-mediaembed="${id}"]`).join(',');
  47.  
  48.   function log(...args){ if(DEBUG) console.log('[InstaReloader]', ...args); }
  49.  
  50.   if (!document.getElementById(STYLE_ID)) {
  51.     const style = document.createElement('style');
  52.     style.id = STYLE_ID;
  53.     style.textContent = `
  54.       .${WRAP_CLASS} {
  55.         position: relative;
  56.         display: inline-block;
  57.         padding: ${BUTTON_POSITION==='right'||BUTTON_POSITION==='left' ? '0 32px' : '32px 0'};
  58.       }
  59.       .${BTN_CLASS} {
  60.         position: absolute;
  61.         background: #fff;
  62.         border: 1px solid #ccc;
  63.         border-radius: 50%;
  64.         width: 24px;
  65.         height: 24px;
  66.         font-size: 14px;
  67.         line-height: 22px;
  68.         text-align: center;
  69.         cursor: pointer;
  70.         box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  71.         z-index: 2147483647;
  72.         user-select: none;
  73.       }
  74.       .${BTN_CLASS}:hover { filter: brightness(0.97); }
  75.     `;
  76.     document.head.appendChild(style);
  77.   }
  78.  
  79.   function positionButton(btn){
  80.     if(BUTTON_POSITION==='right'){
  81.       btn.style.right='-28px'; btn.style.top='50%'; btn.style.transform='translateY(-50%)';
  82.     } else if(BUTTON_POSITION==='left'){
  83.       btn.style.left='-28px'; btn.style.top='50%'; btn.style.transform='translateY(-50%)';
  84.     } else if(BUTTON_POSITION==='top'){
  85.       btn.style.top='-28px'; btn.style.left='50%'; btn.style.transform='translateX(-50%)';
  86.     } else if(BUTTON_POSITION==='bottom'){
  87.       btn.style.bottom='-28px'; btn.style.left='50%'; btn.style.transform='translateX(-50%)';
  88.     }
  89.   }
  90.  
  91.   function forceReload(iframe){
  92.     const prev = iframe.getAttribute('src') || '';
  93.     log('Reload requested:', prev);
  94.     try {
  95.       const url = new URL(prev, document.baseURI);
  96.       url.searchParams.set('_reload', Date.now().toString());
  97.       const next = url.toString();
  98.       if(next === prev){
  99.         iframe.src = 'about:blank';
  100.         requestAnimationFrame(()=>iframe.src=prev);
  101.       } else {
  102.         iframe.src = next;
  103.       }
  104.     } catch {
  105.       iframe.src = 'about:blank';
  106.       requestAnimationFrame(()=>iframe.src=prev);
  107.     }
  108.   }
  109.  
  110.   function addButton(iframe){
  111.     if(iframe.dataset[FLAG]==='true') return;
  112.     iframe.dataset[FLAG]='true';
  113.  
  114.     let wrapper = iframe.parentElement;
  115.     if(!wrapper.classList.contains(WRAP_CLASS)){
  116.       wrapper=document.createElement('span');
  117.       wrapper.className=WRAP_CLASS;
  118.       iframe.parentNode.insertBefore(wrapper, iframe);
  119.       wrapper.appendChild(iframe);
  120.     }
  121.  
  122.     const btn=document.createElement('div');
  123.     btn.textContent='⟳';
  124.     btn.className=BTN_CLASS;
  125.     btn.title='Reload this iframe';
  126.     positionButton(btn);
  127.     btn.addEventListener('click',e=>{
  128.       e.preventDefault(); e.stopPropagation(); forceReload(iframe);
  129.     });
  130.     wrapper.appendChild(btn);
  131.   }
  132.  
  133.   let scheduled = false;
  134.   function scan(){
  135.     if(scheduled) return;
  136.     scheduled = true;
  137.     setTimeout(()=>{
  138.       document.querySelectorAll(SELECTOR).forEach(addButton);
  139.       scheduled = false;
  140.     }, 300);
  141.   }
  142.  
  143.   scan();
  144.   const obs = new MutationObserver(scan);
  145.   obs.observe(document.body, {childList: true, subtree: true});
  146. })();
  147.  
Add Comment
Please, Sign In to add comment