Greasy Fork is available in English.

讨论 » 创建请求

Request: Make "Videoes" the default tab on Youtube-channels

§
发表于:2018-11-27

Request: Make "Videoes" the default tab on Youtube-channels

When you visit a Youtube-channel the HOME tab is the default, but I would love a script which changed the default tab to VIDEOS:



Imgur

wOxxOm管理员
§
发表于:2018-11-27
修改于:2018-11-27

This works for me in Tampermonkey:

// ==UserScript==
// @name          YT channel shows Videos
// @match         https://www.youtube.com/*
// @run-at        document-start
// @license       MIT License
// @grant         none
// ==/UserScript==

(() => {
  const RX_CHANNEL_HOME = /^(https?:\/\/www\.youtube\.com\/(user|channel)\/[^/]+)(\/?$|\/featured)/;
  if (RX_CHANNEL_HOME.test(location.href)) {
    location.href = RegExp.$1 + '/videos';
    return;
  }
  addEventListener('mousedown', event => {
    const a = event.target.closest('a');
    if (a && RX_CHANNEL_HOME.test(a.href)) {
      a.href = RegExp.$1 + '/videos';
      try { a.data.commandMetadata.webCommandMetadata.url = a.href; } catch (e) {}
    }
  }, true);
})();
§
发表于:2018-11-28

Thank you!

It also works using Violentmonkey.

§
发表于:2019-03-09

Nice, still works !

§
发表于:2020-11-28
修改于:2021-01-06

This didn't work for me anymore so I just wanted to leave my updated version here for anyone else who might stumble upon this (as this thread was my top result on Google):

// ==UserScript==
// @name          Youtube channel default tab
// @match         https://www.youtube.com/*
// @run-at        document-start
// @license       MIT License
// @grant         none
// ==/UserScript==

(() => {
  const RX_CHANNEL_HOME = /^(https?:\/\/www\.youtube\.com)(\/(user|channel|c)\/[^/]+)(\/?$|\/featured)/;
  const DEFAULT_TAB_HREF = "/videos";
  // the byte/ascii sequence '0x12 0x06 v i d e o s' encoded with base64 and uri component encoding seems to correspond to the videos tab
  const DEFAULT_TAB_ENDPOINT_PARAMS = encodeURIComponent(btoa(String.fromCharCode(0x12, 0x06) + "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
    // where we didn't rewrite the link
    location.href = RegExp.$2 + DEFAULT_TAB_HREF;
    return;
  }

  addEventListener('mousedown', event => {
    const a = event.target.closest('a');
    if (a && RX_CHANNEL_HOME.test(a.href)) {
      // 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
      a.href = RegExp.$2 + DEFAULT_TAB_HREF;

      // without this the url in the browsers navigation bar will show the wrong url but the videos tab is still being loaded
      try { a.data.commandMetadata.webCommandMetadata.url = RegExp.$2 + DEFAULT_TAB_HREF; } catch (e) {}

      // this makes sure that the videos tab is the one actually being loaded
      try { a.data.browseEndpoint.params = DEFAULT_TAB_ENDPOINT_PARAMS; } catch (e) {}
    }
  }, true);
})();

Basically the only relevant change is line 35 where a.data.browseEndpoint.params now has to be set as well. Not sure how those params are built so this might break in the future. I found the current value by navigating to a channels video tab and looking at document.getElementsByTagName("yt-navigation-manager")[0].currentEndpoint_.

Edit 2021-01-06: Added /c/channel_name URLs to the regex.

§
发表于:2020-12-13

This didn't work for me anymore so I just wanted to leave my updated version here for anyone else who might stumble upon this (as this thread was my top result on Google):

...

Basically the only relevant change is line 35 where a.data.browseEndpoint.params now has to be set as well. Not sure how those params are built so this might break in the future. I found the current value by navigating to a channels video tab and looking at document.getElementsByTagName("yt-navigation-manager")[0].currentEndpoint_.

Can't thank you enough Schuwi.
§
发表于:2020-12-19
修改于:2020-12-19

Thank you Schuwi!

Another thing to add is |c after |channel because I found some channel URL's have /c/channel_name.

Replace line 10 with: const RX_CHANNEL_HOME = /^(https?:\/\/www\.youtube\.com)(\/(user|channel|c)\/[^/]+)(\/?$|\/featured)/;

§
发表于:2021-01-06
修改于:2021-01-06
Thanks flowscript :)
I just noticed as well when I found a channel that had such a link.

I edited it into my original comment for anyone doing just a quick copy-and-paste.

Edit: Also: glad I could help :)

发表回复

登录以发表回复。