Only Follow

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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

})();