Gmail: Remove Upgrade Button

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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;
  };
})();