Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Instagram Iframe Reloader
- // @namespace http://tampermonkey.net/
- // @version 1.1
- // @description Adds reload buttons to Instagram iframes
- // @author YourName
- // @include */threads/*
- // @grant none
- // @run-at document-idle
- // ==/UserScript==
- (function() {
- 'use strict';
- function throttle(fn, delay) {
- let last = 0, timer;
- return function() {
- const now = Date.now(), args = arguments;
- if (now - last < delay) {
- clearTimeout(timer);
- timer = setTimeout(() => {
- last = now;
- fn.apply(this, args);
- }, delay);
- } else {
- last = now;
- fn.apply(this, args);
- }
- };
- }
- function processIframe(iframe) {
- if (iframe.dataset.reloadButtonAdded) return;
- iframe.dataset.reloadButtonAdded = '1';
- const container = iframe.parentNode;
- const containerStyle = getComputedStyle(container);
- // Position container if needed
- if (containerStyle.position === 'static') {
- container.style.position = 'relative';
- }
- // Create button
- const btn = document.createElement('button');
- btn.innerHTML = '↻';
- btn.title = 'Reload iframe';
- Object.assign(btn.style, {
- position: 'absolute',
- right: '-22px',
- top: '50%',
- transform: 'translateY(-50%)',
- width: '24px',
- height: '24px',
- borderRadius: '50%',
- background: '#3897f0',
- color: 'white',
- border: 'none',
- cursor: 'pointer',
- fontSize: '14px',
- zIndex: '10000',
- boxShadow: '0 1px 2px rgba(0,0,0,0.2)',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- opacity: '0.85',
- transition: 'all 0.2s',
- padding: '0'
- });
- // Hover effects
- btn.addEventListener('mouseover', () => {
- btn.style.opacity = '1';
- btn.style.transform = 'translateY(-50%) scale(1.05)';
- });
- btn.addEventListener('mouseout', () => {
- btn.style.opacity = '0.85';
- btn.style.transform = 'translateY(-50%)';
- });
- // Click handler
- btn.addEventListener('click', (e) => {
- e.stopPropagation();
- const src = iframe.src;
- iframe.src = '';
- setTimeout(() => { iframe.src = src; }, 10);
- });
- container.appendChild(btn);
- }
- function scanIframes() {
- document.querySelectorAll('iframe[data-s9e-mediaembed="instagram"]:not([data-reload-button-added])').forEach(processIframe);
- }
- // Initialize with throttling
- const throttledScan = throttle(scanIframes, 200);
- const observer = new MutationObserver(throttledScan);
- observer.observe(document.body, { childList: true, subtree: true });
- scanIframes();
- })();
Advertisement
Add Comment
Please, Sign In to add comment