aremesh / ETFDBLink

// ==UserScript==
// @name         ETFDBLink
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  LinkToTradingView and Robinhood
// @author       You
// @match        https://moviehdz.com/movies/*
// @grant        none
// @require      https://code.jquery.com/jquery-3.3.1.slim.js
// @license      MIT
// ==/UserScript==


(function () {
  
  'use strict';
  AddTopLinks()
  AddIndLinks();
  AddPortfolioLinks();
  DetectAjaxChanges();
  AddLinksToAll();
  Add_to_tradingview_watchList();
  // Your code here...
})();

function AddLinksToAll() {
  var newall = $("a[href*='quote.ashx']");

  newall.each(function (x) {
    var stockName = $(this).html();
    var existing = $(this).parents("td").html();
    var finalLink1 = GenerateSimpleLinks(stockName, existing)

    $(this).parent("td").html(finalLink1)

  })
}

function AddTopLinks() {
  var bullbearChart = "<td><a target='_blank' class='nav-link' href='https://bullbearcharts.blogspot.com/' class='tab-link'>Bull Bear Chart</a> </td><td><a target='_blank' class='nav-link' href='http://insiderbuyingselling.com' class='tab-link'>Insider Buying</a> </td><td><a target='_blank' class='nav-link' href='https://etfdb.com' class='tab-link'>ETF DB</a> </td>"
  $(".navbar td[style='width: 100%']").html(bullbearChart)
}

function AddIndLinks() {
  var stockName = window.location.search.split("&")[0].split("=")[1]
  var existing = $(".ta-settings-button").html()
  var finalLink = GenerateLinks(stockName, existing, false)
  $(".ta-settings-button").html(finalLink)
}

function AddPortfolioLinks() {

  var all = $("td[title] a.screener-link-primary");

  if (all.length === 0) {
    all = $("#body-table-portfolio td[title] a b")
  }
  all.each(function (x) {
    var stockName = $(this).html();
    var existing = $(this).parents("td").html();
    var finalLink = GenerateLinks(stockName, existing)
    $(this).parent("a").parent("td").removeAttr("onclick").parent("tr").removeAttr("onclick");
    $(this).parent("a").parent("td").html(finalLink)
    $(this).parent("td").html(finalLink)

  })
}

function DetectAjaxChanges() {
  var _send = XMLHttpRequest.prototype.send;
  XMLHttpRequest.prototype.send = function () {

    /* Wrap onreadystaechange callback */
    var callback = this.onreadystatechange;
    this.onreadystatechange = function () {
      if (this.readyState == 4) {

        /* We are in response; do something,
           like logging or anything you want */
      }
      callback.apply(this, arguments);
      AddPortfolioLinks();
    }

    _send.apply(this, arguments);

  }
}

function Add_to_tradingview_watchList() {
  var newall = $(".screener-link-primary");
  var allLink = ""
  var stockName = []
  newall.each(function (x) {

    stockName.push($(this).html())

  })

  $(".fullview-links").each(function () {
    if ($(this).html().indexOf("save as portfolio") > 0) {
      $(this).prepend("<a class='tab-link'   href='https://www.tradingview.com/symbols/F/?" + stockName.join(",") + "'>Add to tradingview watchlist</a> | ")
    }
  })
}