Only Follow

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

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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();
    }

})();