Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
13 kB
1
Indexable
Never
/*fecli-injected JavaScript*/
  ;(function(){
    var style=document.createElement('style');style.type='text/css';style.appendChild(document.createTextNode('.eg-new-slide+div {    display: none !important;}[data-item="result-card"]>div:not(.eg-new-slide):not(.result-cards-info)>*:not(.loading) {    /* display: none !important; */    opacity: 0 !important;}.eg-new-slide {    margin-bottom: 5px !important;    aspect-ratio: 4/2.981;    isolation: isolate;}.eg-new-slide .slick-dots {    bottom: 0 !important;    display: flex;    justify-content: center;    align-items: center;    padding: 10px;}.eg-new-slide .slick-dots li button:before {    font-size: 6px !important;    color: white !important;    opacity: 1 !important;    width: 6px !important;    height: 6px !important;    transform: translateY(-100%) !important;}.eg-new-slide .slick-dots li.slick-active button:before {    color: transparent !important;    background-color: transparent;    box-shadow: 0 0 0 2px #fff;    border-radius: 100vmax !important;    transform: translateY(0) !important;}.eg-new-slide .slick-dots li button {    padding: 0 !important;    width: 6px !important;    height: 6px !important;    margin: 0 !important;}.eg-new-slide .slick-dots li {    width: 6px !important;    height: 6px !important;}.eg-new-slide .eg-img {    display: block;}.eg-new-slide .slick-track,.eg-new-slide .slick-list {    height: 100% !important;}.eg-new-slide img {    display: block !important;    object-fit: cover !important;    object-position: center !important;}.eg-new-slide .slick-prev {    left: 0 !important;    z-index: 999 !important;    display: flex;    align-items: center;    justify-content: center;    border-radius: 100vmax;    width: 30px;    height: 16.9px;}.eg-new-slide .slick-prev::before,.eg-new-slide .slick-next::before {    color: rgb(0 0 0 /38%) !important;    line-height: normal;    display: block !important;    height: 17px;    width: 20px;}.eg-new-slide .slick-next {    right: 0 !important;    z-index: 999 !important;    display: flex !important;    align-items: center;    justify-content: center;    border-radius: 100vmax;    width: 30px;    height: 16.9px;}html body .eg-new-slide:not(.slick-initialized) *:not(.eg-dot),html body .eg-new-slide.slick-initialized .eg-dot {    display: none !important;}/* dot animation */.loading {    align-items: center;    display: flex;    justify-content: center;    height: 100%;    position: absolute;    width: 100%;    --ori-bg: rgba(0, 0, 0, 0.1);    --after-bg: rgba(0, 0, 0, 0.18);}.loading__dot {    animation: dot ease-in-out 1s infinite;    background-color: var(--ori-bg);    display: inline-block;    height: 8px;    margin: 2px;    width: 8px;    border-radius: 100vmax;}.loading__dot:nth-of-type(2) {    animation-delay: 0.2s;}.loading__dot:nth-of-type(3) {    animation-delay: 0.3s;}@keyframes dot {    0% {        background-color: var(--ori-bg);        transform: scale(1);    }    50% {        background-color: var(--after-bg);        transform: scale(1.3);    }    100% {        background-color: var(--ori-bg);        transform: scale(1);    }}'));document.head.appendChild(style);
(function () {
  try {
    var debug = 1;
    var variation_name = "";
    var $;
    var tag = "egSwipeTest";
    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);
    }
    // wait for jquery
    function waitForjQuery(trigger) {
      var interval = setInterval(function () {
        if (window.jQuery != undefined) {
          clearInterval(interval);
          trigger();
        }
      }, 50);
      setTimeout(function () {
        clearInterval(interval);
      }, 15000)
    }

    function waitForSlick(trigger) {
      var interval = setInterval(function () {
        if (window.jQuery.fn.slick != undefined) {
          clearInterval(interval);
          trigger();
        }
      }, 50);
      setTimeout(function () {
        clearInterval(interval);
      }, 15000)
    }

    // slick script and css cdn
    function addScript() {
      var cssScript = '' +
        "<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css'/>";
      let themeCssScript = `<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick-theme.css'/>`;
      document.querySelector('head').insertAdjacentHTML('beforeend', cssScript);
      document.querySelector('head').insertAdjacentHTML('beforeend', themeCssScript);

      var swiperScript = document.createElement('script');
      swiperScript.src = 'https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js';
      document.getElementsByTagName('head')[0].appendChild(swiperScript);
    }
    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 (el && found) callback.call(el, e);
        });
      }
      live(selector, event, callback, context);
    }


    live('button', 'click', function () {
      if (this.querySelector(".icon-refresh")) {
        waitForElement('[data-item="result-card"] img[data-testid="rendered-image"][src]', initVariation, 1200, 30000);
      }
    });
    live(['.eg-new-slide .slick-prev', '.eg-new-slide .slick-next', '.eg-new-slide .slick-dots'], 'click', function (e) {
      e.stopPropagation();
      e.preventDefault();
    });

    function listener() {
      /* These are the modifications: */
      window.addEventListener("locationchange", function () {
        waitForElement('[data-item="result-card"] img[data-testid="rendered-image"][src]', initVariation, 1200, 30000);
      });
      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"));
      });
    }
    waitForjQuery(function () {
      $ = window.jQuery;
      addScript();
    });
    function initVariation() {
      let stop,
        cachedList = JSON.parse(localStorage.getItem(tag)) || JSON.parse("{}"),
        check = function () {
          try {
            let productTiles = document.querySelectorAll('[data-item="result-card"]:not(.eg-swipe-added)');

            if (stop) return;

            if (productTiles.length) {
              productTiles.forEach((rC) => {
                if (rC && rC.href) {
                  const fChild = rC.children[0];
                  if (fChild && fChild.tagName === "DIV" && !fChild.classList.contains("eg-new-slide")) {
                    fChild.insertAdjacentHTML("afterbegin", `<div class="loading">
  <span class="loading__dot"></span>
  <span class="loading__dot"></span>
  <span class="loading__dot"></span>
</div>`);
                  }
                  let pdpUrl = new URL(rC.href);
                  let pdpUrlPathName = new URL(rC.href).pathname;
                  // rC.removeAttribute("href");
                  rC.setAttribute("data-href", pdpUrl);
                  rC.classList.add("eg-swipe-added");
                  let cachedVal = cachedList[pdpUrlPathName];

                  if (cachedVal) {
                    insertCopy(pdpUrl, cachedVal);
                    console.log("product retrieved from cache");
                  } else {
                    getHTML(pdpUrl, function (response) {
                      try {
                        var egDesEle = [...response.querySelectorAll('[data-hero="true"]>div>div:nth-of-type(2)>div>div:last-of-type source[media*="(min-width: 1440px)"]')];
                        // checking if element exists or not
                        if (egDesEle) {
                          const imgHTML = egDesEle.reduce((t, crr) => {
                            return t += `<img class="eg-img" src="${crr.srcset}"/>`;
                          }, "");
                          insertCopy(pdpUrl, imgHTML);
                          if (localStorage.getItem(tag) === null) {
                            let caList = {}
                            caList[pdpUrlPathName] = imgHTML;
                            localStorage.setItem(tag, JSON.stringify(caList));
                          } else {
                            let oCalist = JSON.parse(localStorage.getItem(tag));
                            oCalist[pdpUrlPathName] = imgHTML;
                            localStorage.setItem(tag, JSON.stringify(oCalist));
                            console.log(oCalist);
                          }
                        } else {
                          console.log('error', rC);
                        }
                      } catch (err) {
                        console.log(err.message);
                      }
                    });
                  }
                } else {
                  console.log("no target and/or link for product tile:");
                  console.log(rC);
                }
              });
            }

          } catch (err) {
            console.log(err.message);
          }
        };

      window.requestAnimationFrame(check);

      setTimeout(function () {
        stop = true;
      }, 5000);
    }

    function getHTML(url, callback) {
      try {
        if (!window.XMLHttpRequest) return;

        var xhr = new XMLHttpRequest();

        if (callback && typeof callback === "function") {
          xhr.onload = function () {
            callback(this.responseXML);
          };

          xhr.onerror = function () {
            console.log("XHR error");
          };
        }

        xhr.open("GET", url);
        xhr.responseType = "document";
        xhr.send();
      } catch (err) {
        console.log(err.message);
      }
    }

    function insertCopy(pdpUrl, imgHTML) {
      var stop,
        check = function () {
          try {
            if (stop) return;
            let targetElem = document.querySelector('a.eg-swipe-added[data-href="' + pdpUrl + '"]');
            if (targetElem && !targetElem.querySelector(".eg-new-slide")) {
              targetElem.insertAdjacentHTML("afterbegin", `<div class="eg-new-slide">${imgHTML}</div>`);
              waitForSlick(function () {
                if ($('a.eg-swipe-added[data-href*="' + pdpUrl + '"] .eg-new-slide')) {
                  $('a.eg-swipe-added[data-href*="' + pdpUrl + '"] .eg-new-slide').slick({
                    dots: true,
                    arrows: true,
                    infinite: true,
                    speed: 300,
                    slidesToShow: 1
                  });
                }
              });
            }
          } catch (err) {
            console.log(err.message);
          }
        };

      window.requestAnimationFrame(check);

      setTimeout(function () {
        stop = true;
      }, 2000);
    }
    waitForElement('[data-item="result-card"] img[data-testid="rendered-image"][src]', initVariation, 1200, 30000);
    listener();
  } catch (e) {
    if (debug) console.log(e, "error in Test" + variation_name);
  }
})();



})();
/*fecli-injected JavaScript*/