aremesh / Motley Fool Linkage

// ==UserScript==
// @name         Motley Fool  Linkage
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.fool.com/*
// @require      https://code.jquery.com/jquery-3.3.1.slim.js
// @require      https://openuserjs.org/src/libs/aremesh/External_Lib.js
// @license      MIT
// ==/UserScript==

(function () {

  'use strict';

  AddLinksToAll();
  Open_Finviz();
  // DetectAjaxChanges()
  // Your code here...
})();

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);
      AddLinksToAll();
    }

    _send.apply(this, arguments);

  }
}

function AddLinksToAll() {

  var newall = $("[href*='premium/company']");

  newall.each(function (x) {
    var stockName = $(this).html();
    var existing = $(this).parent().html();
    stockName = stockName.replace(")", "").replace("(NASDAQ:", "")
    if (existing.indexOf("<img") < 0) {

      var finalLink1 = GenerateLowfloatLinks(stockName, existing)
      $(this).parent("span").html(finalLink1)

    }

  })
}

function Open_Finviz() {
  var newall = $("[href*='premium/company']");
  var allLink = ""
  var stockName = []
  newall.each(function (x) {
    var stkname = $(this).html()
    if (stkname.indexOf("<img") < 0) {
      stockName.push($(this).html())

    }

  })
  var stockString = stockName.join(",");

  stockString = stockString.replaceAll('(', '').replaceAll(')', '').replaceAll('NASDAQ:', '').replaceAll('NYSE:', '').replaceAll(' ', '');
  $("#nav-home").parent().prepend("<a class='tab-link' target='_blank'  href='https://finviz.com/screener.ashx?t=" + stockString + "'>Open In Finviz</a>  ")
}