Block Most Redirects (Simple)

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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.');
})();