Untitled

 avatar
unknown
plain_text
9 months ago
8.6 kB
3
Indexable
(function () {
  try {
    /* main variables */
    var debug = 0;
    var variation_name = "";
    var $;
    /* 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 listener() {
      window.addEventListener('locationchange', function () {
        waitForElement('[class*="cardWrapper"]', init, 50, 15000);
      })
      history.pushState = ((f) =>
        function pushState() {
          var ret = f.apply(this, arguments);
          window.dispatchEvent(new Event('pushstate'));
          window.dispatchEvent(new Event('locationchange'));
          return ret;
        })(history.pushState);
      history.replaceState = ((f) =>
        function replaceState() {
          var ret = f.apply(this, arguments);
          window.dispatchEvent(new Event('replacestate'));
          window.dispatchEvent(new Event('locationchange'));
          return ret;
        })(history.replaceState);
      window.addEventListener('popstate', () => {
        window.dispatchEvent(new Event('locationchange'));
      });
    }
    listener();

    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);
    };
    var clickOnce = true;

    live('.cardsMapHolder [class*="loadMoreButton"]', 'click', function () {
      waitForElement('[class*="cardWrapper"]', init, 1000, 15000);
    });

    live('[class*="getSearchInputContainerStyles"] + [data-testid="form-submit"], [class*="dropdownSolutions"] [class*="solutionsList"] li', 'mouseover', function () {
      setTimeout(() => {
        waitForElement('[class*="cardWrapper"]', init, 50, 15000);
      }, 3000);
    });
    live('div[class*="dropdownSolutions"] button[class*="-openButton"]', 'click', function () {
      setTimeout(function () {
        if (clickOnce == true) {
          live('div[class*="dropdownSolutions"] #solution-dropdown ul li button', 'mousedown', function () {
            console.log('dropdown called');
            waitForElement('[class*="cardWrapper"]', init, 50, 15000);
          });
        }
        clickOnce = false;
      }, 1000);
    });

    function init() {
      const cards = document.querySelectorAll('[class*="cardWrapper"]');
      cards.forEach(card => {
        if (!card.querySelector('.eg-button-wrapper')) {

          const pictureWrapper = card.querySelector('[class*="pictureWrapper"]');
          let buttonWrapper = pictureWrapper.querySelector('.eg-button-wrapper');
          if (!buttonWrapper) {
            buttonWrapper = document.createElement('div');
            buttonWrapper.classList.add('eg-button-wrapper');
          }
          let quoteButton = buttonWrapper.querySelector('.eg-quote-button');
          if (!quoteButton) {
            quoteButton = document.createElement('a');
            quoteButton.classList.add('eg-quote-button');
            quoteButton.textContent = "Get a quote";
          }
          let readMoreButton = buttonWrapper.querySelector('.eg-learn-more-button');
          if (!readMoreButton) {
            readMoreButton = document.createElement('a');
            readMoreButton.classList.add('eg-learn-more-button');
            readMoreButton.textContent = "View Location";
            readMoreButton.setAttribute('href', card.querySelector('a[data-item="result-card"]').getAttribute('href'));
          }
          let arrangeButton = buttonWrapper.querySelector('.eg-arrange-button');
          if (!arrangeButton) {
            arrangeButton = document.createElement('a');
            arrangeButton.classList.add('eg-arrange-button');
            arrangeButton.textContent = "Arrange a Visit";
            var url = card.querySelector('a[data-item="result-card"] + a').getAttribute('href');
            console.log('url', url);
            var newUrl = url.replace('/get-a-quote','/arrange-a-centre-tour');
            arrangeButton.setAttribute('href', newUrl);
          }
          const href = card.querySelector('[class*="cardBottomCta"]').getAttribute('href');
          quoteButton.setAttribute('href', href);
          buttonWrapper.appendChild(quoteButton);
          buttonWrapper.appendChild(arrangeButton);
          buttonWrapper.appendChild(readMoreButton);
          pictureWrapper.appendChild(buttonWrapper);
          card.querySelector('a[data-item="result-card"]').insertAdjacentElement('beforebegin', buttonWrapper);
        }

      });

      var solutionName = document.querySelector("[class*='searchSolutionWrapper'] > [class*='dropdownSolutions'] img + span");
      if (solutionName.innerText.trim() === "Meeting rooms" || solutionName.innerText.trim() === "Day Office" || solutionName.innerText.trim() === "Day Coworking") {
        document.querySelectorAll('.eg-quote-button').forEach(function (e) {
          updateHref(e,'Book now','Arrange a Visit');
        })
      }

      var searchname = document.querySelector("[class*='searchSolutionWrapper'] > [class*='dropdownSolutions'] img + span");
      if (searchname.innerText.trim() === "Virtual Offices") {
        document.querySelectorAll('.eg-quote-button').forEach(function (e) {
          updateHref(e,'Buy now','Get a Quote');
          })
      }

      var searchname = document.querySelector("[class*='searchSolutionWrapper'] > [class*='dropdownSolutions'] img + span");
      if (searchname.innerText.trim() === "Office space" || searchname.innerText.trim() === "Coworking") {
        document.querySelectorAll('.eg-quote-button').forEach(function (e) {
          updateHref(e,'Get a quote','Arrange a Visit');
         
        })
      }
    }
  function updateHref(e,egCopy,egCopy1){
    var href = e.parentElement.nextElementSibling.nextElementSibling.getAttribute('href');
    e.href = href;
    var href1 = e.parentElement.nextElementSibling.getAttribute('href');
    e.nextElementSibling.nextElementSibling.href = href1
    e.innerText = egCopy;
    e.nextElementSibling.href = href.replace('/get-a-quote','/arrange-a-centre-tour');
    e.nextElementSibling.innerText = egCopy1;
    if(egCopy1 == 'Get a Quote')
      e.nextElementSibling.href = href;
  }
    waitForElement("[class*='listingsContainer']", function () {
      var targetNode = document.querySelector('[class*="listingsContainer"]');
      var callback = function (mutationsList, observer) {
        for (var mutation of mutationsList) {
          if (mutation.type === 'childList') {
            for (var removedNode of mutation.removedNodes) {
              if (removedNode.nodeName === 'SECTION') {
                setTimeout(function () {
                  waitForElement('[class*="cardWrapper"]', init, 50, 15000);
                }, 1500);
              }
            }
          }
        }
      };
      var observer = new MutationObserver(callback);
      if (targetNode) {
        observer.observe(targetNode, { attributes: true, childList: true, subtree: true });
      }
    }, 50, 15000);


    waitForElement('[class*="cardWrapper"]', init, 50, 15000);
  } catch (e) {
    if (debug) console.log(e, "error in Test" + variation_name);
  }
})();


Editor is loading...
Leave a Comment