Untitled

mail@pastecode.io avatarunknown
plain_text
a month ago
3.7 kB
2
Indexable
Never
(function (w) {
  "use strict";
  var tag = "cv-2-0", // TO DO: test name
    debug = document.cookie.indexOf("cfQA") > -1,
    window = typeof unsafeWindow !== "undefined" ? unsafeWindow : w;

  window[tag] = {
    log: function (msg) {
      if (debug) console.log("[CONV]", tag, "-->", msg);
    },
    waitForElement: function (cssSelector, callback) {
      var stop,
        elementCached,
        timeout,
        check = function () {
          try {
            elementCached = document.querySelector(cssSelector);

            if (stop) return;

            if (elementCached) {
              callback(elementCached);
              clearTimeout(timeout);

              window[tag].log(cssSelector + " found");
            } else {
              window.requestAnimationFrame(check);
            }
          } catch (err) {
            window[tag].log(err.message);
          }
        };

      window.requestAnimationFrame(check);

      timeout = setTimeout(function () {
        stop = true;
        window[tag].log(cssSelector + " not found");
      }, 15000);
    },
    start: function () {
      try {
        this.waitForElement("body", function (docBody) {
          docBody.classList.add(tag);
        });

        if (debug && document.title.indexOf("CONV QA") < 0) {
          document.title = "[CONV QA] " + document.title;
        }

        initVariation();

        window[tag].log("test running");
      } catch (err) {
        window[tag].log(err.message);
      }
    }
  };

  var cvReview = '' +
    '<div class="eg-main-container">' +
    '  <div class="eg-badge content_cards-row block background--full-width background--transparent">' +
    '      <div class="block__container">' +
    '      <div class="eg-badge-inr">' +
    '          <h2 class="eg-badge-heading">ACCREDITED BY</h2>' +
    '          <div class="eg-badge-img-container">' +
    '              <div class="eg-badge-img">' +
    '                  <img src="https://cfactory-img.s3.amazonaws.com/pitches/Oanda/cvTrust1.svg" alt="cvTrust1">' +
    '              </div>' +
    '              <div class="eg-badge-img">' +
    '                  <img src="https://cfactory-img.s3.amazonaws.com/pitches/Oanda/cvTrust2.svg" alt="cvTrust2">' +
    '              </div>' +
    '              <div class="eg-badge-img">' +
    '                  <img src="https://cfactory-img.s3.amazonaws.com/pitches/Oanda/cvTrust3.svg.svg" alt="cvTrust3">' +
    '              </div>' +
    '          </div>' +
    '      </div>' +
    '  </div>' +
    '  </div>' +
    '  <div class="eg-review content_cards-row block background--full-width background--transparent">' +
    '      <div class="block__container">' +
    '      <div class="eg-review-inr">' +
    '          <div class="eg-review-left-container">' +
    '              <img src="https://cfactory-img.s3.amazonaws.com/pitches/Oanda/cvLogo.png" alt="cvLogoAll">' +
    '              <h2 class="eg-review-title">Trusted by <span>1.2 M</span> worldwide traders</h2>' +
    '          </div>' +
    '          <div class="eg-review-right-container">' +
    '              <img src="https://cfactory-img.s3.amazonaws.com/pitches/Oanda/cvImgRating.png" alt="cvImgRating">' +
    '          </div>' +
    '      </div>' +
    '      </div>' +
    '      </div>' +
    '  </div>';

  window[tag].start();
  function initVariation() {
    window[tag].waitForElement('main .content_cards-row:nth-child(1)', function (ele) {
      ele.insertAdjacentHTML('afterend', cvReview);
    }, 50, 15000);
  }
})(window);