Only Follow

Redirect Bilibili/Zhihu homepages to follow feeds, even with URL parameters or new tab opens.

Você precisará instalar uma extensão como Tampermonkey, Greasemonkey ou Violentmonkey para instalar este script.

You will need to install an extension such as Tampermonkey to install this script.

Você precisará instalar uma extensão como Tampermonkey ou Violentmonkey para instalar este script.

Você precisará instalar uma extensão como Tampermonkey ou Userscripts para instalar este script.

Você precisará instalar uma extensão como o Tampermonkey para instalar este script.

Você precisará instalar um gerenciador de scripts de usuário para instalar este script.

(Eu já tenho um gerenciador de scripts de usuário, me deixe instalá-lo!)

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

(Eu já possuo um gerenciador de estilos de usuário, me deixar fazer a instalação!)

// ==UserScript==
// @name         Only Follow
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  Redirect Bilibili/Zhihu homepages to follow feeds, even with URL parameters or new tab opens.
// @author       Rive
// @match        *://*.bilibili.com/*
// @match        *://*.zhihu.com/*
// @grant        none
// @license MIT
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    /**
     * SILENT MODE:
     * Hide the body immediately to prevent the homepage from flashing.
     */
    function hidePage() {
        if (document.documentElement) {
            document.documentElement.style.display = 'none';
        }
    }

    /**
     * REDIRECT LOGIC:
     * Checks if the current page is the actual homepage (ignoring search parameters).
     */
    function performRedirect() {
        const hostname = window.location.hostname;
        const pathname = window.location.pathname;

        // Bilibili: Match www.bilibili.com/ or www.bilibili.com/index.html
        if (hostname === "www.bilibili.com" && (pathname === "/" || pathname === "/index.html")) {
            hidePage();
            window.location.replace("https://t.bilibili.com/");
        }

        // Zhihu: Match www.zhihu.com/ (usually the feed or login page)
        if (hostname === "www.zhihu.com" && pathname === "/") {
            hidePage();
            window.location.replace("https://www.zhihu.com/follow");
        }
    }

    /**
     * CLICK INTERCEPTION:
     * Handles left-clicks on logo/home links within the same tab.
     */
    function setupClickInterception() {
        document.addEventListener('click', function(e) {
            const anchor = e.target.closest('a');
            if (!anchor) return;

            try {
                const url = new URL(anchor.href);
                // Check if the link points to Bilibili homepage
                if (url.hostname === "www.bilibili.com" && (url.pathname === "/" || url.pathname === "/index.html")) {
                    e.preventDefault();
                    window.location.href = "https://t.bilibili.com/";
                }
                // Check if the link points to Zhihu homepage
                if (url.hostname === "www.zhihu.com" && url.pathname === "/") {
                    e.preventDefault();
                    window.location.href = "https://www.zhihu.com/follow";
                }
            } catch (err) {
                // Ignore invalid URLs
            }
        }, true);
    }

    // Execute immediately to handle direct access and "Open in new tab"
    performRedirect();

    // Initialize click listener after DOM begins to load
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', setupClickInterception);
    } else {
        setupClickInterception();
    }

})();