Youtube channels default to "Videos" tab

By default, clicking on a channel while browsing Youtube loads the "Home" tab. This loads the "Videos" tab instead.

目前為 2025-07-20 提交的版本,檢視 最新版本

// ==UserScript==
// @name          Youtube channels default to "Videos" tab
// @description  By default, clicking on a channel while browsing Youtube loads the "Home" tab. This loads the "Videos" tab instead.
// @version      0.1
// @namespace       BawdyInkSlinger
// @author       BawdyInkSlinger
// @match         https://www.youtube.com/*
// @exclude       https://www.youtube.com/embed*
// @run-at        document-start
// @license       MIT License
// @grant         none
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// ==/UserScript==

// original version: https://gf.qytechs.cn/en/discussions/requests/56798-request-make-videoes-the-default-tab-on-youtube-channels#comment-455176
(() => {
    const RX_CHANNEL_HOME = /^(https?:\/\/www\.youtube\.com)((\/(user|channel|c)\/[^/]+)(\/?$|\/featured[^/])|(\/@(?!.*\/)[^/]+))/;
    const DEFAULT_TAB_HREF = "/videos";

    if (RX_CHANNEL_HOME.test(location.href)) {
        // this will get invoked when a youtube channel link is reached from a non-youtube origin page,
        // redirecting the link to /videos
        location.href = RegExp.$2 + DEFAULT_TAB_HREF;

        // I think there's a bug here but I've yet to prove it: If you navigate to another part of youtube, will
        // the script work due to this early return?
        return;
    }

    addEventListener('mousedown', event => {
        const anchorTag = event.target.closest('a');
        if (anchorTag && RX_CHANNEL_HOME.test(anchorTag.href)) {
            const channelName = RegExp.$2;
            // a channel link was clicked so it has to be rewritten before the actual navigation happens

            // this makes sure the redirect above in line 15-20 is not needed as long as the link clicked is on a youtube page
            // e.g. when opening a channel link in a new tab
            anchorTag.href = channelName + DEFAULT_TAB_HREF;

            setLinkAddressBar(channelName, anchorTag);
            setLinkToLoadVideosTab(anchorTag);
        }
    }, true);

    function setLinkAddressBar(channelName, anchorTag) {
        try {
            anchorTag.data.commandMetadata.webCommandMetadata.url = channelName + DEFAULT_TAB_HREF;
        } catch (e) {
            console.error(`Youtube channel default tab: setLinkAddressBar:`, e);
        }
    }

    function setLinkToLoadVideosTab(anchorTag) {
        try {
            /*
   How to get "anchorTag.data.browseEndpoint.params" if this stops working:
   1. Visit any channel's "Home" tab
   2. Below the tabs, there should be a few sub sections, one of them being "Videos". It should be a link.
   If this doesn't exist, find a different channel that matches this description.
   3. Using your browser's devtools, inspect the "Videos" sub section link.
   4. Right-click on the nearest "a" tag and select "Use in console" (Firefox). This creates a console variable named "temp0"
   5. In the console, type "temp0.data.browseEndpoint.params". Hit enter.
   6. This is the value that will bring you to the videos tab.
   7. Copy and paste it below.
   */
            anchorTag.data.browseEndpoint.params = `EgZ2aWRlb3MYAyAAcAHyBgsKCToCEASiAQIIAQ%3D%3D`;
        } catch (e) {
            console.error(`Youtube channel default tab: setLinkToLoadVideosTab:`, e);
        }
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址