Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
8.0 kB
2
Indexable
Never
(function () {
  try {
    var debug = 0;
    var variation_name = "";
    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) {
      /****Helper Functions****/
      // helper for enabling IE 8 event bindings
      function addEvent(el, type, handler) {
        if (el.attachEvent) el.attachEvent("on" + type, handler);
        else el.addEventListener(type, handler);
      }
      // matches polyfill
      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);
      // live binding helper using matchesSelector
      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);
    }
    // CONTACT US PAGE JS
    function updateBtnHtml() {
      const textEl = document.querySelector(`div[class^='contact-header__mobile-menu'] button[class^='dropdown-list__button'] [class*="contact-header-dropdown__label"]`);
      if (textEl && (textEl.innerText == 'Business query' || textEl.innerText == "Account opening enquiries")) {
        textEl.innerText = "Account opening enquiries";
        document.body.classList.add("eg-tab-active");
      } else {
        document.body.classList.remove("eg-tab-active");
      }
    }
    let egTabContent = `
      <div class="eg-tab-content">
          <p class="eg-tab-heading">Open an HSBC Business Account in three easy steps:</p>
          <!-- steps -->
          <ul class="eg-steps">
              <li class="eg-step">
                  <p>Step 1</p>
                  <p>Schedule a meeting with us</p>
              </li>
              <li class="eg-step">
                  <p>Step 2</p>
                  <p>We'll get in touch within two working days to find out more about your business</p>
              </li>
              <li class="eg-step">
                  <p>Step 3</p>
                  <p>We'll help you through the process to set up your Business Account</p>
              </li>
          </ul>
      </div>
      `;
    function contactUs() {
      const egContactContent = document.querySelector("#contact-content");
      //====desktop + tab only===+
      if (window.innerWidth > 759) {
        const egTabBtn = document.querySelector("div[class^='contact-header__content'] > div[class^='Box-sc']>div:nth-child(1)");
        if (egTabBtn.getAttribute("aria-selected") && egTabBtn.getAttribute("aria-selected") === 'true') {
          if (!document.querySelector('.eg-tab-content')) {
            egContactContent.insertAdjacentHTML("afterbegin", egTabContent);
            document.body.classList.add("eg-tab-active");
          }
        }
        // change btn text 
        egTabBtn.childNodes[1].textContent = "Account opening enquiries";
        // desktop and tablet tab click
        live(['html body #tab-GenericTab', 'html body #tab-PhoneUs', 'html body #tab-FindBranch'], 'click', function () {
          if (this.getAttribute("id") === "tab-GenericTab") {
            if (!document.querySelector('.eg-tab-content')) {
              egContactContent.insertAdjacentHTML("afterbegin", egTabContent);

            }
            document.body.classList.add("eg-tab-active");
          } else {
            document.body.classList.remove("eg-tab-active");
          }
        });
      } else {
        const textEl = document.querySelector(`div[class^='contact-header__mobile-menu'] button[class^='dropdown-list__button'] [class*="contact-header-dropdown__label"]`);
        if (textEl && (textEl.innerText == 'Business query' || textEl.innerText == "Account opening enquiries")) {
          textEl.innerText = "Account opening enquiries";
          document.body.classList.add("eg-tab-active");
        }
        if (!document.querySelector('.eg-tab-content')) {
          egContactContent.insertAdjacentHTML("afterbegin", egTabContent);
        }
        // mobile drop down btn click detect
        live([`div[class^='contact-header__mobile-menu'] button[class^='dropdown-list__button']`,
          `div[class*='dropdown-list__button-icon']`,
          `ul[class^='dropdown-list__listbox'] > li:first-child`], 'click', function () {
            updateBtnHtml();
            setTimeout(() => {
              updateBtnHtml();
            }, 50);
            const egSibling = document.querySelector(`ul[class^='dropdown-list__listbox']>li:first-child`);
            if (egSibling != null) {
              egSibling.querySelector(`[class*="contact-header-dropdown__label"]`).innerText = "Account opening enquiries";
            }
          });
        live(`ul[class^='dropdown-list__listbox'] > li:not(:first-child)`, 'click', function () {
          document.body.classList.remove("eg-tab-active");
        });
      }
    }
    waitForElement('#contact-content', contactUs, 150, 15000);
    // CONTACT US PAGE JS END

    // BUSSINESS BANKING PAGE JS
    waitForElement('html body #request-a-call-back [class*="flexible-form-step__legend"]', function () {
      if (window.location.pathname === '/en-sg/business-banking/business-account-opening-process') {
        document.querySelector('html body #request-a-call-back [class*="flexible-form-step__legend"]').innerText = "Apply for a Business Banking account";
        document.querySelector('html body #request-a-call-back [class*="flexible-form-step__text-block"] p').innerText = "Every customer enquiry is important to us. By providing details about your business, using the form below, we can start the simple process of opening your Business Banking account with us. We will get in touch with you to understand your requirements and guide you through the onboarding process. All fields are mandatory unless otherwise indicated as optional";
      } else {
        document.querySelector('html body #request-a-call-back [class*="flexible-form-step__legend"]').innerText = "For all your business banking enquiries – we’re here to help";
      }
    }, 500, 15000);
    // BUSSINESS BANKING PAGE JS

    // EMAIL PAGE
    if (window.location.pathname === '/en-sg/email-us') {
      waitForElement('html body [class*="tab-header__title"]', function () {
        document.querySelector('html body [class*="tab-header__title"]').innerText = "Get In Touch With Us";
        document.querySelector('html body [class*="flexible-form-step__text-block"] p').innerText = "Every customer enquiry is important to us. Whether you’re looking to open a business banking account or you’re an existing customer wanting to find out more about our range of products and solutions, then we’re here to help. Please don’t enter confidential information such as your bank account details here. All fields are mandatory unless otherwise indicated as optional";
      }, 500, 15000);
    }
  } catch (e) {
    if (debug) console.log(e, "error in Test" + variation_name);
  }
})();