Greasy Fork

Greasy Fork is available in English.

Block Sites and Redirect

自动屏蔽微博、联合早报等指定网站,跳转至百度

当前为 2025-04-30 提交的版本,查看 最新版本

// ==UserScript==
// @name         Block Sites and Redirect
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  自动屏蔽微博、联合早报等指定网站,跳转至百度
// @author       YourName
// @match        *://*/*
// @run-at       document-start
// @grant        none
// @license     GPL version 3
// ==/UserScript==

(function() {
    'use strict';

    // 需要屏蔽的域名列表(支持主域名及其所有子域名)
    const blockedDomains = [
        'weibo.com',
        'zaobao.com',
        'tophub.today'
    ];

    // 获取当前页面完整域名
    const currentHost = window.location.hostname;

    // 检查当前域名是否需要屏蔽
    const shouldBlock = blockedDomains.some(domain => {
        // 精确匹配主域名或子域名
        return currentHost === domain || currentHost.endsWith('.' + domain);
    });

    // 如果匹配到屏蔽域名则立即跳转
    if (shouldBlock) {
        // 使用replace防止浏览器历史记录被污染
        window.location.replace('https://www.baidu.com/');
    }
})();