tradingview chart assistant

insert a link go finviz chart link

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         tradingview chart assistant
// @namespace    http://tampermonkey.net/
// @version      2025-11-14
// @description  insert a link go finviz chart link
// @author       goodzhuwang
// @match        https://*.tradingview.com/chart/*/?symbol=*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

function findElementsByClassRegex(classNameRegex) {
    const selector = `*[class*="${classNameRegex.source}"]`;
    return document.querySelectorAll(selector);
}

(function() {
        "use strict";


        // 1. 定义你的 CSS 样式字符串
        const myCss = `
        	/* 定义一个你想要使用的 CSS 类 */
			._TCA_finviz-link {
			    display: flex;
			    align-items: center;
			    justify-content: center;
			    height: 44px;
			    cursor: pointer;
	        }

	        ._TCA_finviz-link_inner{
		        display: flex;
		    	align-items: center;
		    	justify-content: center;
		        height: 38px;
		        width: 38px;
		        border-radius: 8px;
			    color:#333;
	        }

	        ._TCA_finviz-link_inner:hover{
				background-color:#ebebeb;
	        }
	    `;

        // 2. 调用 GM_addStyle 将 CSS 注入页面
        GM_addStyle(myCss);

        const ext_name = "tradingview_chart_assistant";

        console.debug(`${ext_name} running`);

        let max_times = 10;
        let times = 0;
        let _interval = setInterval(function() {
                // 达到最大次数,就算了。
                if (times >= max_times) {
                    console.debug(`${ext_name}达到最大检测次数,算了`);
                    if (_interval) {
                        clearInterval(_interval);
                        _interval = null;
                    }
                }
                let symbol = document.querySelector(".js-button-text") ?.textContent;
                if (!symbol) {
                    console.debug(`没有找到股票代码`);
                    return;
                }

                // 在特定的的位置插入一个a
                const targets = findElementsByClassRegex(/filler-/);
                const domElement = targets && targets.length && targets[0];

                if (!domElement) {
                    console.debug(`没有找到插入位置`);
                } else {
                    let finviz_link_url = `https://finviz.com/quote.ashx?t=${symbol}&ty=c&ta=1&p=d`;

                    let finviz_link = document.querySelector("._TCA_finviz-link");
                    if (!finviz_link) {
                        const finviz_link = document.createElement("div");


                        // 你要插入的 HTML 字符串
                        const newHTML = `
				          <a class="_TCA_finviz-link" href=${finviz_link_url} target="_blank" title="点击查看finviz图表">
				            <div class="_TCA_finviz-link_inner">
				              Finv
				            </div>
				          </a>
				        `;

                        finviz_link.innerHTML = newHTML;

                        domElement.insertAdjacentHTML('beforeend', newHTML);
                    }

                    times++;
                }
        }, 5000);
})();