Block Most Redirects (Simple)

Quietly block most redirects used by ad-heavy streaming sites (movieshd.watch, etc.) without breaking main page.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Block Most Redirects (Simple)
// @namespace    https://github.com/osuobiem
// @version      1.5
// @description  Quietly block most redirects used by ad-heavy streaming sites (movieshd.watch, etc.) without breaking main page.
// @author       Gabriel Osuobiem
// @match        *://*/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const log = (...args) => console.debug('[NoRedirect]', ...args);

    // Block window.open popups (ads)
    window.open = () => {
        log('Blocked window.open');
        return null;
    };

    // Block common location changes
    ['assign', 'replace', 'reload'].forEach(method => {
        try {
            const orig = window.location[method].bind(window.location);
            window.location[method] = (...args) => {
                log(`Blocked location.${method}`, args[0]);
            };
        } catch (_) {}
    });

    // Block direct location set
    try {
        Object.defineProperty(window, 'location', {
            set: (url) => log('Blocked direct location set to', url),
            get: () => document.location
        });
    } catch (_) {}

    // Remove meta refresh tags (initial and added later)
    const removeMeta = () => {
        document.querySelectorAll('meta[http-equiv="refresh"]').forEach(m => {
            log('Removed meta refresh', m.content);
            m.remove();
        });
    };
    new MutationObserver(removeMeta).observe(document.documentElement, { childList: true, subtree: true });
    removeMeta();

    // Block ad link clicks that cause immediate redirect
    document.addEventListener('click', (e) => {
        const a = e.target.closest('a[href]');
        if (!a) return;
        if (!a.href.startsWith(window.location.origin)) {
            e.preventDefault();
            log('Blocked external link click', a.href);
        }
    }, true);

    log('Simple redirect blocking active.');
})();