finviz quote assistant

insert a link go tradingview chart link

当前为 2024-09-19 提交的版本,查看 最新版本

// ==UserScript==
// @name         finviz quote assistant
// @namespace    http://tampermonkey.net/
// @version      2024-09-19
// @description  insert a link go tradingview chart link
// @author       goodzhuwang
// @match        https://finviz.com/quote.ashx?t=*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  "use strict";

  const ext_name = "finviz_quote_assistant";

  console.debug(`${ext_name} running`);
  // @todo 找到代码,生成tv链接
  let links = document.querySelectorAll(".fullview-links a");

  if (!links || !links.length) {
    console.log(`没有找到链接`);
    return;
  }
  let exchange_symbol = "";

  links.forEach((e) => {
    let a = e.getAttribute("href");
    console.log(e, a);

    let link = "https://www.google.com/finance/quote/NVDA:NASDAQ";

    let m = link.match(/(\w+):(\w+)$/);
    if (m) {
      console.log(`${m[2]}:${m[1]}`);
      exchange_symbol = `${m[2]}%3A${m[1]}`;
    }
  });

  if (!exchange_symbol) {
    console.log(`没有找到包含交易所和代码的链接`);
    return;
  }

  let tradingview_link = `https://cn.tradingview.com/chart/700qUKjc/?symbol=${exchange_symbol}`;

  // 在特定的的位置插入一个a
  const domElement = document.querySelector(".js-stock-detail-link");
  if (!domElement) {
    console.log(`没有找到插入位置`);
    return;
  }

  const aTag = document.createElement("a");
  aTag.href = tradingview_link;
  aTag.textContent = "TradingView Chart";
  aTag.target = "_blank";
  aTag.style.marginRight = "10px";
  domElement.parentNode.insertBefore(aTag, domElement);
})();