Greasy Fork

来自缓存

Greasy Fork is available in English.

禁止访问小红书首页

当访问小红书首页时自动跳转到搜索页,防止沉迷碎片信息

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Block Xiaohongshu Homepage
// @name:zh-CN   禁止访问小红书首页
// @description  Redirects to search page when visiting Xiaohongshu homepage to prevent addiction to fragmented information
// @description:zh-CN  当访问小红书首页时自动跳转到搜索页,防止沉迷碎片信息
// @namespace    https://github.com/Konano
// @version      1.0.3.20250429
// @author       Konano
// @homepageURL  https://github.com/Konano/greasyfork-script
// @match        https://www.xiaohongshu.com/*
// @icon         https://www.xiaohongshu.com/favicon.ico
// @license      MIT
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    const redirectTarget = 'https://www.xiaohongshu.com/search_result?type=51';

    // Check if the current URL is Xiaohongshu homepage
    function isExploreUrl(url) {
        if (!url) return false;

        // Exact match for https://www.xiaohongshu.com/explore
        if (url === 'https://www.xiaohongshu.com/explore' || url === 'https://www.xiaohongshu.com/explore/') {
            return true;
        }

        // Match explore page with query parameters
        if (url.match(/^https:\/\/www\.xiaohongshu\.com\/explore\?.*/)) {
            return true;
        }

        return false;
    }

    // Delayed redirect to search page
    function delayedRedirect() {
        setTimeout(function() {
            console.log('Redirecting to search page...');
            window.location.href = redirectTarget;
        }, 500);
    }

    // If current page is homepage, call redirect function
    if (isExploreUrl(window.location.href)) {
        console.log('Xiaohongshu homepage detected, redirecting to search page...');
        delayedRedirect();
        return;
    }

    // Periodically check current URL
    setInterval(function() {
        if (isExploreUrl(window.location.href)) {
            console.log('Xiaohongshu homepage detected, redirecting to search page...');
            delayedRedirect();
        }
    }, 1000);

})();