Untitled

 avatar
unknown
plain_text
a year ago
5.7 kB
3
Indexable
(function () {
  try {
    /* main variables */
    var debug = 0;
    var variation_name = "";
    var $;
    /* all Pure helper functions */

    waitForElement = function (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);
    }

    live = function (selector, event, callback, context) {
      addEvent = function (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);
      live = function (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', 'span'], 'click', function () {
      if (this.innerText.toUpperCase().indexOf("BAG") != -1) {
        console.log("clicked");
        setTimeout(function () {
          waitForElement('#__next .cart .star-ratings ', init, 1000, 15000);
          waitForElement('#__next .cart .star-ratings > div:nth-child(6)', init, 1000, 15000);
        }, 1200);
      } else if ((this.innerText.toUpperCase() == "ADD") || (this.innerText.toUpperCase() == "REMOVE") || this.parentElement.classList.contains("cart__item__quantity")) {
        console.log("clicked");
        setTimeout(function () {
          waitForElement('#__next .cart .star-ratings ', init, 1000, 15000);
          waitForElement('#__next .cart .star-ratings > div:nth-child(6)', init, 1000, 15000);
        }, 1200);
      }
    });

    listener = function () {
      window.addEventListener('locationchange', function () {
        waitForElement('#__next .cart .star-ratings ', init, 50, 15000);
        waitForElement('#__next .cart .star-ratings > div:nth-child(6)', init, 1000, 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();

    var newsvg = `
    <svg class="eg-last-star" height="24" viewBox="0 0 51 48" width="24">
    <defs>
      <linearGradient id="grad2">
        <stop offset="0%" stop-color="rgb(51 51 51)" />
        <stop offset="60%" stop-color="rgb(51 51 51)" />
        <stop offset="60%" stop-color="#f1d27a" />
        <stop offset="100%" stop-color="#f1d27a" />
      </linearGradient>            
    </defs>
    <path
          fill="url(#grad2)"
          stroke="black"
          stroke-width="2"
          d="m25,1 6,17h18l-14,11 5,17-15-10-15,10 5-17-14-11h18z"
    />
</svg>`

    /* Variation Init */
    init = function () {
      if (!document.querySelector(".eg-last-star")) {
        document.querySelector("#__next .cart .star-ratings > div:nth-child(6)").insertAdjacentHTML("afterend", newsvg);
      }
    }

    /* Initialize variation */
    waitForElement('#__next .cart .star-ratings ', init, 1000, 15000);
    waitForElement('#__next .cart .star-ratings > div:nth-child(6)', init, 1000, 15000);
  } catch (e) {
    if (debug) console.log(e, "error in Test" + variation_name);
  }
})();




















.rating-cart-wrapper.eg-rating-bar .star-ratings .star-container svg path {
    fill: rgb(51 51 51) !important;
}

.star-ratings+h4 {
    margin-top: 0 !important;
}

.star-ratings h4 {
    padding-top: 3px !important;
}

.rating-cart-wrapper.eg-rating-bar {
    margin-bottom: 13px !important;
    margin-top: 13px;
}

/* .rating-cart-wrapper.eg-rating-bar .star-ratings .star-container:nth-child(6) svg path {
    fill: rgb(51 51 51) !important;
    clip-path: inset(0 35% 0 0);
} */


#__next .cart .star-ratings>svg {
    width: 14px;
    height: 14px;
}

#__next .cart .star-ratings>div:nth-child(6) svg {
    display: none !important;
}

#__next .cart .star-ratings>.eg-last-star {
    display: block !important;
}
Leave a Comment