Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.8 kB
2
Indexable
Never
(function () {
  try {
    /* main variables */
    var debug = 0;
    var variation_name = "";
    /* all Pure helper functions */
    function waitForElement(selector, trigger, delayInterval, delayTimeout) {
      var interval = setInterval(function () {
        if (
          document &&
          document.querySelector(selector) &&
          document.querySelectorAll(selector).length > 0
        ) {
          clearInterval(interval);
          trigger();
        }
      }, delayInterval);
      setTimeout(function () {
        clearInterval(interval);
      }, delayTimeout);
    }

    function live(selector, event, callback, context) {
      function addEvent(el, type, handler) {
        if (el.attachEvent) el.attachEvent('on' + type, handler);
        else el.addEventListener(type, handler);
      }
      this.Element &&
        (function (ElementPrototype) {
          ElementPrototype.matches =
            ElementPrototype.matches ||
            ElementPrototype.matchesSelector ||
            ElementPrototype.webkitMatchesSelector ||
            ElementPrototype.msMatchesSelector ||
            function (selector) {
              var node = this,
                nodes = (node.parentNode || node.document).querySelectorAll(selector),
                i = -1;
              while (nodes[++i] && nodes[i] != node);
              return !!nodes[i];
            };
        })(Element.prototype);
      function live(selector, event, callback, context) {
        addEvent(context || document, event, function (e) {
          var found,
            el = e.target || e.srcElement;
          while (el && el.matches && el !== context && !(found = el.matches(selector))) el = el.parentElement;
          if (found) callback.call(el, e);
        });
      }
      live(selector, event, callback, context);
    };

    live(".black-friday__text > div.hero__btns a._type-cols", "click", function () {
      console.log("Request Access Now")
    });

    if (window.location.href.indexOf("https://www.altium.com/altium-365/supply-chain/siliconexpert") !== -1) {
      live(".form-actions", "click", function () {
        console.log("Contact Sales Now")
      });
    }

    function init() {
      document.querySelector(".black-friday__text h2 ").innerText = "Altium 365 Integrates with SiliconExpert";
      document.querySelector(".black-friday__text p ").innerText = "Delivering Unmatched Component Data Access Directly in Your Design Environment";
      document.querySelector(".black-friday__text > p.hero__note").innerText = "Empower your engineering and sourcing teams with the comprehensive data to make informed components selection and minimize supply chain risks.";
      document.querySelector(".black-friday__text > div.hero__btns > a").innerText = ("Request access now");

      waitForElement(".hero-wrapper div.hero__bg img", function () {
        document.querySelector(".hero-wrapper div.hero__bg img").setAttribute('src', 'https://cdn.optimizely.com/img/8453775962/69da3ef7515b4a339b18992a3e590c27.png');
      }, 100, 25000);
      waitForElement(".l-container .black-friday__logo img", function () {
        document.querySelector(".l-container .black-friday__logo img").setAttribute('src', 'https://cdn.optimizely.com/img/8453775962/c7eebc8e6ac741adabf308b91f35dd7c.svgz');
        if (!document.querySelector(".eg-logo-alt")) {
          document.querySelector(".l-container .black-friday__logo img").insertAdjacentHTML("afterend", `<img class='eg-logo-alt' src='https://cdn.optimizely.com/img/8453775962/4412374a390f4368bf0b68313d6b7bc5.svgz'>`);
        }
      }, 100, 25000);
    }
    waitForElement(".black-friday__text > div.hero__btns > a", init, 100, 35000);
  } catch (e) {
    if (debug) console.log(e, "error in Test" + variation_name);
  }
})();