Hide Portainer Business Upgrade Button (attribute based)

本脚本仅隐藏界面中的“升级到商业版”提示,让界面更清爽。

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Hide Portainer Business Upgrade Button (attribute based)
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  本脚本仅隐藏界面中的“升级到商业版”提示,让界面更清爽。
//               感谢 Portainer CE 提供出色的容器管理工具。
//               对于个人用户,社区版已足够使用。
//               脚本简单,若随版本更新失效,可自行调整匹配规则。
// @match        *://*/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 判断是否 Portainer 页面
    function isPortainerPage() {
        const html = document.documentElement;
        return (
            html.getAttribute('ng-app') === 'portainer' ||
            html.dataset.edition === 'CE'
        );
    }

    // 屏蔽按钮逻辑(彻底删除)
    function removeUpgradeButton() {
        const btns = document.querySelectorAll('button');
        btns.forEach(btn => {
            if (btn.textContent.includes('Upgrade to Business Edition') ||
                btn.textContent.includes('升级到商业版')) {
                btn.remove(); // 直接删除节点,而非隐藏
            }
        });
    }

    // 主逻辑
    function init() {
        if (!isPortainerPage()) return;

        console.log('[Tampermonkey] Portainer detected — removing Business Edition button');

        removeUpgradeButton();

        // 监听 DOM 变化,防止按钮重新渲染出来
        const observer = new MutationObserver(removeUpgradeButton);
        observer.observe(document.body, { childList: true, subtree: true });
    }

    // 等待 DOM 加载完成
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        init();
    } else {
        window.addEventListener('DOMContentLoaded', init);
    }
})();