Tradingview Hide Unwanted Broker List Buttons

Hide buttons except those for TradeStation, OANDA, and Paper on TradingView

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Tradingview Hide Unwanted Broker List Buttons
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Hide buttons except those for TradeStation, OANDA, and Paper on TradingView
// @author       ChatGPT
// @icon          https://www.google.com/s2/favicons?sz=64&domain=tradingview.com
// @match        https://www.tradingview.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function hideUnwantedButtons() {
        // Define the brokers you want to keep
        const brokersToKeep = ['Paper', 'TRADESTATION']

        // Get all elements with the data-broker attribute
        const buttons = document.querySelectorAll('[data-broker]');

        // Loop through all buttons and hide the ones not in the brokersToKeep list
        buttons.forEach(button => {
            const broker = button.getAttribute('data-broker');
            if (!brokersToKeep.includes(broker)) {
                button.style.display = 'none';
            }
        });
    }

    // Run the function when the page loads
    window.addEventListener('load', hideUnwantedButtons);

    // Optionally, run the function again when there are changes in the DOM
    const observer = new MutationObserver(hideUnwantedButtons);
    observer.observe(document.body, { childList: true, subtree: true });

    // Adding a slight delay to ensure all elements are loaded
    setTimeout(hideUnwantedButtons, 2000);
})();