Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Multi-site mediaembed iframe reloader
- // @namespace https://example.com/
- // @version 1.2
- // @description Adds reload buttons to all s9e-mediaembed iframes
- // @include */threads/*
- // @grant none
- // ==/UserScript==
- (function(){
- 'use strict';
- const DEBUG = false; // true = logs, false = silent
- const BUTTON_POSITION = 'right'; // 'right' | 'left' | 'top' | 'bottom'
- const STYLE_ID = 'insta-iframe-reloader-style';
- const BTN_CLASS = 'insta-reload-btn';
- const WRAP_CLASS = 'insta-iframe-wrapper';
- const FLAG = 'reloadAttached';
- // 1. List of all supported ids:
- const SUPPORTED_IDS = [ "abcnews","acast","anchor","applepodcasts","audioboom","audiomack",
- "audius","bandcamp","bbcnews","bitchute","bluesky","brightcove","bunny",
- "captivate","castos","cbsnews","clyp","cnbc","cnn","cnnmoney","codepen",
- "comedycentral","coub","crankers","dailymotion","democracynow","dumpert",
- "eighttracks","espn","facebook","falstad","flickr","foxnews","funnyordie",
- "gamespot","getty","gifs","giphy","gist","globalnews","gofundme",
- "googledrive","googleplus","googlesheets","hudl","hulu","ign","imdb",
- "imgur","indiegogo","instagram","internetarchive","izlesene","jsfiddle",
- "jwplatform","kaltura","khl","kickstarter","libsyn","liveleak",
- "livestream","mailru","mastodon","medium","megaphone","metacafe",
- "mixcloud","mlb","mrctv","msnbc","nachovideo","natgeochannel",
- "natgeovideo","nbcnews","nhl","npr","nytimes","odysee","omny","on3",
- "orfium","pastebin","pinterest","podbean","prezi","reddit","rumble",
- "rutube","scribd","sendvid","slideshare","soundcloud","sporcle",
- "sportsnet","spotify","spreaker","steamstore","strawpoll","streamable",
- "teamcoco","ted","telegram","theatlantic","theguardian","theonion",
- "threads","tiktok","tmz","tradingview","traileraddict","trendingviews",
- "tumblr","twentyfoursevensports","twitch","twitter","ustream","vbox7",
- "veoh","vevo","videodetective","vimeo","vine","vk","vocaroo","vox",
- "washingtonpost","wavekit","wistia","wshh","wsj","xboxclips","xboxdvr",
- "xenforo","youku","youmaker","youtube"
- ];
- // 2. Build the CSS selector:
- const SELECTOR = SUPPORTED_IDS.map(id => `iframe[data-s9e-mediaembed="${id}"]`).join(',');
- function log(...args){ if(DEBUG) console.log('[InstaReloader]', ...args); }
- if (!document.getElementById(STYLE_ID)) {
- const style = document.createElement('style');
- style.id = STYLE_ID;
- style.textContent = `
- .${WRAP_CLASS} {
- position: relative;
- display: inline-block;
- padding: ${BUTTON_POSITION==='right'||BUTTON_POSITION==='left' ? '0 32px' : '32px 0'};
- }
- .${BTN_CLASS} {
- position: absolute;
- background: #fff;
- border: 1px solid #ccc;
- border-radius: 50%;
- width: 24px;
- height: 24px;
- font-size: 14px;
- line-height: 22px;
- text-align: center;
- cursor: pointer;
- box-shadow: 0 2px 6px rgba(0,0,0,0.2);
- z-index: 2147483647;
- user-select: none;
- }
- .${BTN_CLASS}:hover { filter: brightness(0.97); }
- `;
- document.head.appendChild(style);
- }
- function positionButton(btn){
- if(BUTTON_POSITION==='right'){
- btn.style.right='-28px'; btn.style.top='50%'; btn.style.transform='translateY(-50%)';
- } else if(BUTTON_POSITION==='left'){
- btn.style.left='-28px'; btn.style.top='50%'; btn.style.transform='translateY(-50%)';
- } else if(BUTTON_POSITION==='top'){
- btn.style.top='-28px'; btn.style.left='50%'; btn.style.transform='translateX(-50%)';
- } else if(BUTTON_POSITION==='bottom'){
- btn.style.bottom='-28px'; btn.style.left='50%'; btn.style.transform='translateX(-50%)';
- }
- }
- function forceReload(iframe){
- const prev = iframe.getAttribute('src') || '';
- log('Reload requested:', prev);
- try {
- const url = new URL(prev, document.baseURI);
- url.searchParams.set('_reload', Date.now().toString());
- const next = url.toString();
- if(next === prev){
- iframe.src = 'about:blank';
- requestAnimationFrame(()=>iframe.src=prev);
- } else {
- iframe.src = next;
- }
- } catch {
- iframe.src = 'about:blank';
- requestAnimationFrame(()=>iframe.src=prev);
- }
- }
- function addButton(iframe){
- if(iframe.dataset[FLAG]==='true') return;
- iframe.dataset[FLAG]='true';
- let wrapper = iframe.parentElement;
- if(!wrapper.classList.contains(WRAP_CLASS)){
- wrapper=document.createElement('span');
- wrapper.className=WRAP_CLASS;
- iframe.parentNode.insertBefore(wrapper, iframe);
- wrapper.appendChild(iframe);
- }
- const btn=document.createElement('div');
- btn.textContent='⟳';
- btn.className=BTN_CLASS;
- btn.title='Reload this iframe';
- positionButton(btn);
- btn.addEventListener('click',e=>{
- e.preventDefault(); e.stopPropagation(); forceReload(iframe);
- });
- wrapper.appendChild(btn);
- }
- let scheduled = false;
- function scan(){
- if(scheduled) return;
- scheduled = true;
- setTimeout(()=>{
- document.querySelectorAll(SELECTOR).forEach(addButton);
- scheduled = false;
- }, 300);
- }
- scan();
- const obs = new MutationObserver(scan);
- obs.observe(document.body, {childList: true, subtree: true});
- })();
Add Comment
Please, Sign In to add comment