Greasy Fork

Greasy Fork is available in English.

YouTube Revert Icon Dropdown

Remove the 'Google Account' Button from the Icon Dropdown

当前为 2023-10-31 提交的版本,查看 最新版本

// ==UserScript==
// @name         YouTube Revert Icon Dropdown
// @namespace    http://greasyfork.icu/en/users/1008366-trickyclock
// @author       TrickyClock
// @version      1.0
// @description  Remove the 'Google Account' Button from the Icon Dropdown
// @license      MIT
// @match        https://www.youtube.com/*
// @grant        none
// @run-at       document-body
// @require      https://cdn.jsdelivr.net/gh/rybak/userscript-libs@e86c722f2c9cc2a96298c8511028f15c45180185/waitForElement.js
// ==/UserScript==

function insertAfter(newNode, referenceNode) {
  referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}

(async () => {
  waitForElement('#contentContainer #endpoint[title="Your channel"]').then((yourChannelButton) => {
    yourChannelButton.parentNode.style.display = "none";
  });

  const observer = new MutationObserver(mutations => {
    const intervalId = setInterval(() => {
      waitForElement('tp-yt-iron-dropdown #sections yt-multi-page-menu-section-renderer:nth-child(1) #endpoint:nth-child(1)').then(async (googleAccountButton) => {
        const yourChannelButton = await waitForElement('#contentContainer #endpoint[title="Your channel"]');
        const yourDataInYoutubeButton = await waitForElement('tp-yt-iron-dropdown #sections yt-multi-page-menu-section-renderer:nth-child(3) #endpoint:nth-child(1)');

        const channelUrl = yourChannelButton.href;
        const channelIcon = yourChannelButton.querySelector('yt-icon yt-icon-shape')
        const googleAccountIcon = googleAccountButton.querySelector('yt-icon yt-icon-shape');
        const googleAccountLabel = googleAccountButton.querySelector('#primary-text-container span');

        googleAccountButton.href = channelUrl;
        googleAccountButton.tabindex = "0";

        googleAccountLabel.innerHTML = "Your channel";
        googleAccountIcon.innerHTML = channelIcon.innerHTML;


        const youtubeStudioButton = document.querySelector('tp-yt-iron-dropdown #endpoint[href^="https://studio.youtube.com"]');
        if (youtubeStudioButton) {
          insertAfter(youtubeStudioButton.parentNode, googleAccountButton.parentNode);
        }

        clearInterval(intervalId);
      });
    }, 100);
 });

  observer.observe((await waitForElement('#contentWrapper ytd-multi-page-menu-renderer')), {
    childList: true,
    subtree: true
  });
})();