Guest User

Untitled

a guest
Aug 18th, 2025
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Instagram Iframe Reloader
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.1
  5. // @description  Adds reload buttons to Instagram iframes
  6. // @author       YourName
  7. // @include      */threads/*
  8. // @grant        none
  9. // @run-at       document-idle
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.   'use strict';
  14.  
  15.   function throttle(fn, delay) {
  16.     let last = 0, timer;
  17.     return function() {
  18.       const now = Date.now(), args = arguments;
  19.       if (now - last < delay) {
  20.         clearTimeout(timer);
  21.         timer = setTimeout(() => {
  22.           last = now;
  23.           fn.apply(this, args);
  24.         }, delay);
  25.       } else {
  26.         last = now;
  27.         fn.apply(this, args);
  28.       }
  29.     };
  30.   }
  31.  
  32.   function processIframe(iframe) {
  33.     if (iframe.dataset.reloadButtonAdded) return;
  34.     iframe.dataset.reloadButtonAdded = '1';
  35.    
  36.     const container = iframe.parentNode;
  37.     const containerStyle = getComputedStyle(container);
  38.    
  39.     // Position container if needed
  40.     if (containerStyle.position === 'static') {
  41.       container.style.position = 'relative';
  42.     }
  43.    
  44.     // Create button
  45.     const btn = document.createElement('button');
  46.     btn.innerHTML = '↻';
  47.     btn.title = 'Reload iframe';
  48.     Object.assign(btn.style, {
  49.       position: 'absolute',
  50.       right: '-22px',
  51.       top: '50%',
  52.       transform: 'translateY(-50%)',
  53.       width: '24px',
  54.       height: '24px',
  55.       borderRadius: '50%',
  56.       background: '#3897f0',
  57.       color: 'white',
  58.       border: 'none',
  59.       cursor: 'pointer',
  60.       fontSize: '14px',
  61.       zIndex: '10000',
  62.       boxShadow: '0 1px 2px rgba(0,0,0,0.2)',
  63.       display: 'flex',
  64.       alignItems: 'center',
  65.       justifyContent: 'center',
  66.       opacity: '0.85',
  67.       transition: 'all 0.2s',
  68.       padding: '0'
  69.     });
  70.    
  71.     // Hover effects
  72.     btn.addEventListener('mouseover', () => {
  73.       btn.style.opacity = '1';
  74.       btn.style.transform = 'translateY(-50%) scale(1.05)';
  75.     });
  76.    
  77.     btn.addEventListener('mouseout', () => {
  78.       btn.style.opacity = '0.85';
  79.       btn.style.transform = 'translateY(-50%)';
  80.     });
  81.    
  82.     // Click handler
  83.     btn.addEventListener('click', (e) => {
  84.       e.stopPropagation();
  85.       const src = iframe.src;
  86.       iframe.src = '';
  87.       setTimeout(() => { iframe.src = src; }, 10);
  88.     });
  89.    
  90.     container.appendChild(btn);
  91.   }
  92.  
  93.   function scanIframes() {
  94.     document.querySelectorAll('iframe[data-s9e-mediaembed="instagram"]:not([data-reload-button-added])').forEach(processIframe);
  95.   }
  96.  
  97.   // Initialize with throttling
  98.   const throttledScan = throttle(scanIframes, 200);
  99.   const observer = new MutationObserver(throttledScan);
  100.   observer.observe(document.body, { childList: true, subtree: true });
  101.   scanIframes();
  102. })();
Advertisement
Add Comment
Please, Sign In to add comment