Only Follow

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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

})();