Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
6.6 kB
6
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 waitforMarketo(trigger) {
      var interval = setInterval(function () {
        if (
          window.MktoForms2
        ) {
          clearInterval(interval);
          trigger();
        }
      }, 50);
      setTimeout(function () {
        clearInterval(interval);
      }, 10000);
    }
    const submitForm = () => {
      const fNEl = document.querySelector('#eg-name');
      const eMEl = document.querySelector('#eg-email');
      if (fNEl.value.trim() == "") {
        fNEl.parentElement.classList.add("eg-err-cms");
      } else if ((eMEl.value.trim() == "") || (!validateEmail(eMEl.value))) {
        eMEl.parentElement.classList.add("eg-err-cms");
      } else {
        fNEl.parentElement.classList.remove("eg-err-cms");
        eMEl.parentElement.classList.remove("eg-err-cms");
        // ori
        const OFnel = document.querySelector("form.footer-subscribe #FirstName");
        const OEmel = document.querySelector("form.footer-subscribe #Email");
        OFnel.value = fNEl.value;
        OEmel.value = eMEl.value;
        document.querySelector('form.footer-subscribe [type="submit"]').click();
      }
    }

    const validateEmail = (email) => {
      return email.match(
        /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
      );
    };

    const detectFormSub = () => {
      waitforMarketo(function () {
        MktoForms2.whenReady(function (form) {
          form.onSuccess(function (values, followUpUrl) {
            document.querySelector(".eg-des-form-container") && document.querySelector(".eg-des-form-container").classList.add("eg-frm-submitted")
          });
        });
      });
    }
    let thankuHTML = `
    <div class="eg-mailbox">
        <div class="eg-cutimage">
            <img src="https://svgshare.com/i/wck.svg">
        </div>
        <h4>Thank you</h4>
        <p>Thank you for your request, an email will be sent to you shortly. If you don’t receive it within 30 minutes
            please
            contact <a href="mailto:info@betashares.com.au">info@betashares.com.au</a></p>
    </div>
    `;
    let frmHTML = `
    <div class="eg-form"><div class="eg-cutimage">
            <img src="https://svgshare.com/i/wck.svg">
        </div>
    
    <h4 class="eg-headline"> <span>Stay informed</span> with Betashares' weekly insights.</h4>
    <p class="eg-subheadline">Receive the latest analysis and updates on markets and the economy, plus tips to help you be a better investor.</p>
    <div>
        <form action="" class="eg-contact-frm">
            <div class="eg-input-field">
                <input type="text" class="user" id="eg-name" placeholder="First name"><div class="eg-err-tooltip mktoError"><div class="eg-err-arrow"><div></div></div><div id="egValidMsgFirstName" class="eg-err-msg">This field is required.</div></div>
            </div>
            <div class="eg-input-field">
                <input type="text" class="user" id="eg-email" placeholder="Your email"><div class="eg-err-tooltip mktoError"><div class="eg-err-arrow"><div></div></div><div id="egValidMsgFirstName" class="eg-err-msg">
Must be valid email.
<br>example@yourdomain.com</div></div>
            </div>
            <div class="eg-subscribenow">
                <button type="submit">Subscribe now</button>
            </div>
        </form>
    </div>
</div>
    `;
    let egHTML = `
    <div class="eg-des-form-container">
      ${thankuHTML}
      ${frmHTML}
    </div>`;
    function init() {
      if (!document.querySelector(".eg-des-form-container")) {
        const target = document.querySelector("html body .post-meta-date").closest(".content-container").querySelector(".grid-cols-1>div:nth-child(2)");
        console.log(target);
        target.insertAdjacentHTML("afterend", egHTML);
        if (window.innerWidth > 1023) {
          const frmContianer = document.querySelector(".eg-des-form-container");
          const nextDiv = frmContianer.nextElementSibling;
          frmContianer.insertAdjacentHTML("beforebegin", `<div class="des-wrapper"></div>`);
          document.querySelector(".des-wrapper").insertAdjacentElement("beforeend", frmContianer);
          if (nextDiv) {
            document.querySelector(".des-wrapper").insertAdjacentElement("beforeend", nextDiv);
          }
        }
        detectFormSub();
        document.querySelector("html body .eg-contact-frm").addEventListener('submit', function (e) {
          e.preventDefault();
          submitForm();
        });
        document.querySelectorAll(".eg-input-field>input").forEach(field => {
          field.addEventListener("input", function () {
            field.parentElement.classList.remove("eg-err-cms");
          })
        });
        document.querySelectorAll(".eg-cutimage").forEach(cut => {
          cut.addEventListener("click", function () {
            document.querySelector(".eg-des-form-container").classList.remove("eg-show");
          });
        });
        document.querySelector(".eg-des-form-container").addEventListener("click", function (e) {
          if (e.target.classList.contains("eg-show")) {
            e.target.classList.remove("eg-show");
          }
        });
        if (window.innerWidth < 1025) {
          waitForElement('div.sticky>a[href="#body"]', function () {
            let egmailboxicon = `<a class="eg-mailicon"><img src="https://svgshare.com/i/wdm.svg" alt=""></a>`
            document.querySelector('div.sticky>a[href="#body"]').insertAdjacentHTML("afterend", egmailboxicon);
            document.querySelector(".eg-mailicon").addEventListener("click", function () {
              document.querySelector(".eg-des-form-container").classList.add("eg-show");
            });
          }, 1000, 15000);
        }
      }
    }
    waitForElement("html body .post-meta-date", init, 100, 35000);
  } catch (e) {
    if (debug) console.log(e, "error in Test" + variation_name);
  }
})();