YouTube Revert Icon Dropdown

Remove the 'Google Account' Button from the Icon Dropdown

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YouTube Revert Icon Dropdown
// @namespace    https://greasyfork.org/en/users/1008366-trickyclock
// @author       TrickyClock
// @version      1.1
// @description  Remove the 'Google Account' Button from the Icon Dropdown
// @icon         https://www.youtube.com/favicon.ico
// @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==
"use strict";

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

(async () => {
  const channelIcon = `<div style="width: 100%; height: 100%; fill: currentcolor;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" focusable="false" style="pointer-events: none; display: block; width: 100%; height: 100%;">
  <path d="M3,3v18h18V3H3z M4.99,20c0.39-2.62,2.38-5.1,7.01-5.1s6.62,2.48,7.01,5.1H4.99z M9,10c0-1.65,1.35-3,3-3s3,1.35,3,3 c0,1.65-1.35,3-3,3S9,11.65,9,10z M12.72,13.93C14.58,13.59,16,11.96,16,10c0-2.21-1.79-4-4-4c-2.21,0-4,1.79-4,4 c0,1.96,1.42,3.59,3.28,3.93c-4.42,0.25-6.84,2.8-7.28,6V4h16v15.93C19.56,16.73,17.14,14.18,12.72,13.93z"></path>
  </svg></div>`;

  // Hide 'Your channel' button from the sidebar
  waitForElement('#contentContainer #endpoint[title="Your channel"]').then((yourChannelButton) => {
    yourChannelButton.parentNode.style.display = "none";
  });

  // Observe when Icon Dropdown changes
  const observer = new MutationObserver(mutations => {
    const intervalId = setInterval(async () => {
      // Find 'Google Account' Button
      var googleAccountButton = await waitForElement('tp-yt-iron-dropdown #sections yt-multi-page-menu-section-renderer:nth-child(1) #endpoint:nth-child(1)');

      // Copy 'Google Account Button' to make sure it doesn't get too modified again
      if (!googleAccountButton.parentNode.hasAttribute('cloned')) {
        const newFullGoogleAccountButton = googleAccountButton.parentNode.cloneNode(true);
        const newGoogleAccountButton = newFullGoogleAccountButton.querySelector('#endpoint');
        newFullGoogleAccountButton.setAttribute('cloned', '');
        googleAccountButton.parentNode.parentNode.replaceChild(newFullGoogleAccountButton, googleAccountButton.parentNode);
        googleAccountButton = newGoogleAccountButton;
      }

      // Find 'View your channel' Button, Get the Channel URL, and replace it with 'Manage your Google Account'
      var viewYourChannelButton = await waitForElement('#channel-container #manage-account a:nth-child(1)');
      const dataInYouTubeButton = await waitForElement('tp-yt-iron-dropdown #sections yt-multi-page-menu-section-renderer:nth-child(3) #endpoint:nth-child(1)');
      const channelUrl = viewYourChannelButton.hasAttribute('prevHref') ? viewYourChannelButton.getAttribute('prevHref') : viewYourChannelButton.href;

      if (!viewYourChannelButton.parentNode.hasAttribute('cloned')) {
        const clonedViewYourChannelButton = viewYourChannelButton.cloneNode(true);
        clonedViewYourChannelButton.setAttribute('cloned', '');
        viewYourChannelButton.parentNode.replaceChild(clonedViewYourChannelButton, viewYourChannelButton);
        viewYourChannelButton = clonedViewYourChannelButton;
      }

      viewYourChannelButton.innerHTML = "Manage your Google Account";
      viewYourChannelButton.setAttribute('prevHref', channelUrl);
      viewYourChannelButton.href = dataInYouTubeButton.href;
      viewYourChannelButton.target = "_blank";

      // 'Google Account' Button Icons and Labels
      const googleAccountIcon = googleAccountButton.querySelector('#content-icon yt-icon');
      const googleAccountLabel = googleAccountButton.querySelector('#primary-text-container #label .yt-formatted-string');

      // Put things onto the copied 'YouTube Studio' Button
      googleAccountButton.href = channelUrl;
      googleAccountButton.tabIndex = -1;
      googleAccountButton.dir = "auto";
      googleAccountLabel.innerHTML = "Your channel";
      googleAccountIcon.innerHTML = channelIcon;

      // Move 'YouTube Studio' Button below 'Your channel' Button
      const youTubeStudioButton = document.querySelector('tp-yt-iron-dropdown #endpoint[href^="https://studio.youtube.com"]');
      if (youTubeStudioButton) {
        insertAfter(youTubeStudioButton.parentNode, googleAccountButton.parentNode);
      }

      // Clear Interval so it doesn't run forever!
      clearInterval(intervalId);
    }, 1000);
  });

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