Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name RedGifs AutoHD Ultimate
- // @namespace https://greasyfork.org/
- // @version 2026.11
- // @icon https://www.google.com/s2/favicons?sz=64&domain=redgifs.com
- // @description Forces HD, unmutes, blocks redirects, and optionally allows fullscreen with just a click on anywhere in the video.
- // @author Acoolrocket, Google Gemini, 137547-invertex @Sleazy Fork for the initial version to work off
- // @match *://*.redgifs.com/*
- // @run-at document-start
- // @grant none
- // ==/UserScript==
- (function () {
- 'use strict';
- // ==========================================
- // USER CONFIGURATION
- // ==========================================
- const CONFIG = {
- AUTO_FULLSCREEN: false,
- BLOCK_ANNOYING_REDIRECTS: true
- };
- // ==========================================
- // STAGE 1: THE NETWORK HIJACKER (HD FORCER)
- // ==========================================
- const originalFetch = window.fetch;
- window.fetch = async function (...args) {
- try {
- let requestUrl = '';
- if (typeof args[0] === 'string') requestUrl = args[0];
- else if (args[0] && typeof args[0].url === 'string') requestUrl = args[0].url;
- if (requestUrl && requestUrl.includes('.m3u8')) {
- if (requestUrl.includes('sd.m3u8') || requestUrl.includes('-sd.m3u8') || requestUrl.includes('mobile.m3u8')) {
- const newUrl = requestUrl.replace(/(sd|-sd|mobile)\.m3u8/i, 'hd.m3u8');
- if (typeof args[0] === 'string') args[0] = newUrl;
- else args[0] = new Request(newUrl, args[0]);
- }
- }
- } catch (e) {
- console.error('RedGifs AutoHD Fetch Intercept Error:', e);
- }
- return originalFetch.apply(this, args);
- };
- // ==========================================
- // STAGE 2: AUDIO & UI ENFORCER
- // ==========================================
- const processedVideos = new WeakSet();
- function fixVideo(video) {
- if (!video || processedVideos.has(video)) return;
- processedVideos.add(video);
- try {
- video.muted = false;
- video.defaultMuted = false;
- video.volume = 1.0;
- video.autoplay = true;
- video.loop = true;
- video.controls = false; // Default to false for windowed mode
- video.playsInline = true;
- const playAttempt = video.play();
- if (playAttempt && typeof playAttempt.catch === 'function') {
- playAttempt.catch(() => {
- video.muted = true;
- video.play().catch(() => {});
- });
- }
- const unmuteInterval = setInterval(() => {
- if (!document.contains(video)) {
- clearInterval(unmuteInterval);
- processedVideos.delete(video);
- return;
- }
- if (video.muted) {
- video.muted = false;
- video.volume = 1.0;
- }
- }, 1500);
- } catch (err) {
- console.log('RedGifs AutoHD execution error:', err);
- }
- }
- function scanDOM() {
- document.querySelectorAll('video').forEach(fixVideo);
- }
- // ==========================================
- // STAGE 3: SMART CLICK HIJACKER
- // ==========================================
- let hasFullscreened = false;
- let scriptTriggeredFullscreen = false; // The new tracking flag
- if (CONFIG.BLOCK_ANNOYING_REDIRECTS || CONFIG.AUTO_FULLSCREEN) {
- document.addEventListener('click', (e) => {
- const isControl = e.target.closest('button, input, label, svg, img, a:not([href*="/watch/"]), [role="button"], [role="slider"], [class*="progress"], [class*="bar"], [class*="control"]');
- const isWatchLink = e.target.closest('a[href*="/watch/"]');
- if (!isControl || isWatchLink) {
- if (CONFIG.BLOCK_ANNOYING_REDIRECTS) {
- e.preventDefault();
- e.stopImmediatePropagation();
- }
- const video = document.querySelector('video');
- if (!video) return;
- const isFullscreen = !!(document.fullscreenElement || document.webkitFullscreenElement);
- if (CONFIG.AUTO_FULLSCREEN && !isFullscreen && !hasFullscreened) {
- const container = video.parentElement || video;
- try {
- scriptTriggeredFullscreen = true; // Tell Stage 4 the script did this
- if (container.requestFullscreen) container.requestFullscreen();
- else if (container.webkitRequestFullscreen) container.webkitRequestFullscreen();
- hasFullscreened = true;
- if (video.paused) video.play();
- } catch (err) {
- scriptTriggeredFullscreen = false; // Reset if it failed
- console.log('Fullscreen blocked:', err);
- }
- }
- else if (CONFIG.BLOCK_ANNOYING_REDIRECTS) {
- if (video.paused) {
- video.play();
- } else {
- video.pause();
- }
- }
- }
- }, true);
- }
- // ==========================================
- // STAGE 4: DYNAMIC FULLSCREEN CONTROLS
- // ==========================================
- function toggleControlsOnFullscreen() {
- const video = document.querySelector('video');
- if (!video) return;
- const isFullscreen = !!(document.fullscreenElement || document.webkitFullscreenElement);
- if (isFullscreen) {
- // ONLY show Chrome controls if our script forced the fullscreen.
- // If the user clicked the Redgifs fullscreen button, let Redgifs handle it.
- if (scriptTriggeredFullscreen) {
- video.controls = true;
- } else {
- video.controls = false;
- }
- } else {
- // When exiting fullscreen, always hide Chrome controls
- video.controls = false;
- // Reset the flag for the next interaction
- scriptTriggeredFullscreen = false;
- }
- }
- document.addEventListener('fullscreenchange', toggleControlsOnFullscreen);
- document.addEventListener('webkitfullscreenchange', toggleControlsOnFullscreen);
- // ==========================================
- // AGGRESSIVE BOOTSTRAPPER
- // ==========================================
- function initScanner() {
- scanDOM();
- if (document.body) {
- const observer = new MutationObserver(scanDOM);
- observer.observe(document.body, { childList: true, subtree: true });
- } else {
- requestAnimationFrame(initScanner);
- }
- }
- initScanner();
- setInterval(scanDOM, 2000);
- })();
Advertisement
Add Comment
Please, Sign In to add comment