Gmail: Remove Upgrade Button

Removes the upgrade button with data-pep-id="global-pep-gmail" from Gmail

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @license MIT 
// @name         Gmail: Remove Upgrade Button
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Removes the upgrade button with data-pep-id="global-pep-gmail" from Gmail
// @match        https://mail.google.com/*
// @run-at       document-start
// @grant        none
// @noframes
// ==/UserScript==

(function () {
  "use strict";

  const TARGET_SELECTOR = '[data-pep-id="global-pep-gmail"]';

  function removeUpgradeButton() {
    const element = document.querySelector(TARGET_SELECTOR);
    if (element) {
      element.remove();
      console.log("Gmail upgrade button removed");
    }
  }

  // Attempt removal multiple times during initial page load
  let attempts = 0;
  const burstInterval = setInterval(() => {
    removeUpgradeButton();
    attempts++;
    if (attempts >= 80) {
      clearInterval(burstInterval);
    }
  }, 100);

  // Watch for Gmail dynamically inserting the button later
  const observer = new MutationObserver(() => {
    removeUpgradeButton();
  });

  observer.observe(document.documentElement, {
    childList: true,
    subtree: true
  });

  // Handle Gmail's SPA navigation (view changes without full page reload)
  const originalPushState = history.pushState;
  const originalReplaceState = history.replaceState;

  history.pushState = function () {
    const result = originalPushState.apply(this, arguments);
    setTimeout(removeUpgradeButton, 0);
    return result;
  };

  history.replaceState = function () {
    const result = originalReplaceState.apply(this, arguments);
    setTimeout(removeUpgradeButton, 0);
    return result;
  };
})();