Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
23 kB
2
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 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);
    }

    live([".eg-pool-boy .eg-new-button", ".eg-air-freshener .eg-new-button"], "click", function () {
      // add to cart functionality
      let varientId = this.getAttribute("data-vId");
      let varientName = this.getAttribute("data-vName");
      fetch("https://checkout.vacation.inc/api/2020-07/graphql", {
        headers: {
          accept: "application/json",
          "accept-language": "*",
          "content-type": "application/json",
          "sec-ch-ua":
            '"Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"',
          "sec-ch-ua-mobile": "?0",
          "sec-ch-ua-platform": '"macOS"',
          "sec-fetch-dest": "empty",
          "sec-fetch-mode": "cors",
          "sec-fetch-site": "same-site",
          "x-sdk-variant": "javascript",
          "x-sdk-version": "2.11.0",
          "x-shopify-storefront-access-token":
            "fe00875189b0e661fdcf65285171dc0f",
        },
        referrer: "https://www.vacation.inc/",
        referrerPolicy: "strict-origin-when-cross-origin",
        body:
          '{"query":"fragment VariantFragment on ProductVariant  { id,title,price,priceV2 { amount,currencyCode },presentmentPrices (first: 20) { pageInfo { hasNextPage,hasPreviousPage },edges { node { price { amount,currencyCode },compareAtPrice { amount,currencyCode } } } },weight,available: availableForSale,sku,compareAtPrice,compareAtPriceV2 { amount,currencyCode },image { id,src: originalSrc,altText },selectedOptions { name,value },unitPrice { amount,currencyCode },unitPriceMeasurement { measuredType,quantityUnit,quantityValue,referenceUnit,referenceValue } },fragment DiscountApplicationFragment on DiscountApplication  { __typename,targetSelection,allocationMethod,targetType,value { ... on MoneyV2 { amount,currencyCode },... on PricingPercentageValue { percentage } },... on ManualDiscountApplication { title,description },... on DiscountCodeApplication { code,applicable },... on ScriptDiscountApplication { description },... on AutomaticDiscountApplication { title } },fragment AppliedGiftCardFragment on AppliedGiftCard  { amountUsedV2 { amount,currencyCode },balanceV2 { amount,currencyCode },presentmentAmountUsed { amount,currencyCode },id,lastCharacters },fragment VariantWithProductFragment on ProductVariant  { ...VariantFragment,product { id,handle } },fragment UserErrorFragment on UserError  { field,message },fragment CheckoutUserErrorFragment on CheckoutUserError  { field,message,code },fragment MailingAddressFragment on MailingAddress  { id,address1,address2,city,company,country,firstName,formatted,lastName,latitude,longitude,phone,province,zip,name,countryCode: countryCodeV2,provinceCode },fragment CheckoutFragment on Checkout  { id,ready,requiresShipping,note,paymentDue,paymentDueV2 { amount,currencyCode },webUrl,orderStatusUrl,taxExempt,taxesIncluded,currencyCode,totalTax,totalTaxV2 { amount,currencyCode },lineItemsSubtotalPrice { amount,currencyCode },subtotalPrice,subtotalPriceV2 { amount,currencyCode },totalPrice,totalPriceV2 { amount,currencyCode },completedAt,createdAt,updatedAt,email,discountApplications (first: 10) { pageInfo { hasNextPage,hasPreviousPage },edges { node { __typename,...DiscountApplicationFragment } } },appliedGiftCards { ...AppliedGiftCardFragment },shippingAddress { ...MailingAddressFragment },shippingLine { handle,price,priceV2 { amount,currencyCode },title },customAttributes { key,value },order { id,processedAt,orderNumber,subtotalPrice,subtotalPriceV2 { amount,currencyCode },totalShippingPrice,totalShippingPriceV2 { amount,currencyCode },totalTax,totalTaxV2 { amount,currencyCode },totalPrice,totalPriceV2 { amount,currencyCode },currencyCode,totalRefunded,totalRefundedV2 { amount,currencyCode },customerUrl,shippingAddress { ...MailingAddressFragment },lineItems (first: 250) { pageInfo { hasNextPage,hasPreviousPage },edges { cursor,node { title,variant { ...VariantWithProductFragment },quantity,customAttributes { key,value } } } } },lineItems (first: 250) { pageInfo { hasNextPage,hasPreviousPage },edges { cursor,node { id,title,variant { ...VariantWithProductFragment },quantity,customAttributes { key,value },discountAllocations { allocatedAmount { amount,currencyCode },discountApplication { __typename,...DiscountApplicationFragment } } } } } },mutation ($checkoutId:ID!,$lineItems:[CheckoutLineItemInput!]!)  { checkoutLineItemsAdd (checkoutId: $checkoutId lineItems: $lineItems) { userErrors { ...UserErrorFragment },checkoutUserErrors { ...CheckoutUserErrorFragment },checkout { ...CheckoutFragment } } }","variables":{"checkoutId":"' +
          readCookie("vacation_checkout_id") +
          '","lineItems":[{"variantId":"' +
          varientId +
          '","quantity":1,"customAttributes":[{"key":"_subtitle","value":"' +
          varientName +
          '"},{"key":"_sc","value":"undefined_undefined_undefined"}]}]}}',
        method: "POST",
        mode: "cors",
        credentials: "omit",
      })
        .then((response) => response.json())
        .then((data) => {
          setCookie("openCart", true, 1);

          window.location.reload();
        })
        .catch((error) => {
          console.error("Error:", error);
        });
    });

    const egLabels = ["Best seller", "Bundle & Save", "New"];

    const egTxt = [
      "GET THE SCENT OF THE WORLD'S BEST-SMELLING SUNSCREEN, FOR YOUR CAR OR HOME OFFICE FOR $5",
      "GET THE SUMMER LEISURE PACK FOR $30 AND SAVE $10! (1 X CLASSIC LOTION, 1 X SUPER SPRITZER, 2 X AIR FRESHENERS)",
      "GET THE POOL BOY SCENTED CANDLE FOR $34",
    ];

    let egInterval;
    let egTimeout;
    live(["button", "span"], "click", function () {
      if (this.innerText.toUpperCase().indexOf("BAG") != -1) {
        waitForElement(".cart .keen-slider .keen-slider__slide", init, 50, 15000);
      } else if (
        this.innerText.toUpperCase() == "ADD" ||
        this.innerText.toUpperCase() == "REMOVE" ||
        this.parentElement.classList.contains("cart__item__quantity")
      ) {
        clearInterval(egInterval);
        clearTimeout(egTimeout);

        let egItems = [...document.querySelectorAll(".cart .keen-slider .keen-slider__slide")];
        removeClasses(egItems);
        waitForElement(".cart .keen-slider .keen-slider__slide", changeContent, 3000, 15000);
      }
    });

    function checkIfInCart() {
      waitForElement(
        "#__next .cart .cart__item .cart__item__content >div >div >div >div .cart__content:nth-of-type(1)",
        function () {
          let egIsPresentBall = contains(
            "#__next .cart .cart__item .cart__item__content >div >div >div >div .cart__content:nth-of-type(1)",
            "AFTER SUN GEL"
          );

          let egIsPresentAir = contains(
            "#__next .cart .cart__item .cart__item__content >div >div >div >div .cart__content:nth-of-type(1)",
            "Vacation® Air Freshener"
          );

          if (egIsPresentBall.length > 0) {
            console.log("sun gel", egIsPresentBall);
            document.querySelector(".eg-pool-boy") &&
              document.querySelector(".eg-pool-boy").classList.add("eg-hide");
          } else {
            document.querySelector(".eg-pool-boy") &&
              document.querySelector(".eg-pool-boy").classList.remove("eg-hide");
          }

          if (egIsPresentAir.length > 0) {
            console.log(egIsPresentAir);
            document.querySelector(".eg-air-freshener") &&
              document.querySelector(".eg-air-freshener").classList.add("eg-hide");
          } else {
            document.querySelector(".eg-air-freshener") &&
              document.querySelector(".eg-air-freshener").classList.remove("eg-hide");
          }
        }, 500, 15000);
    }

    // searching element by text inside of it
    function contains(selector, text) {
      var elements = document.querySelectorAll(selector);
      return [].filter.call(elements, function (element) {
        // removing special characters and consequitive spaces before check
        return (
          element.innerText.replace(/[^\w\s]/gi, "").replace(/\s+/g, " ").toUpperCase().indexOf(text.replace(/[^\w\s]/gi, "").replace(/\s+/g, " ").toUpperCase()) != -1
        );
      });
    }

    function changeContent() {
      let egItems = [...document.querySelectorAll(".cart .keen-slider .keen-slider__slide")];
      // removing active class and section specific class
      removeClasses(egItems);

      // inserting data
      updateContent(egItems);

      checkIfInCart();
    }

    /* Variation Init */
    function init() {
      /* start your code here */
      egItems = [...document.querySelectorAll(".cart .keen-slider .keen-slider__slide")];
      updateContent(egItems);
      checkIfInCart();
    }

    function removeClasses(egItems) {
      egItems.forEach((item) => {
        if (item.classList.contains("eg-active")) {
          item.classList.remove("eg-active");
        }
        if (item.classList.contains("eg-air-freshener")) {
          item.classList.remove("eg-air-freshener");
        }
        if (item.classList.contains("eg-whip")) {
          item.classList.remove("eg-whip");
        }
        if (item.classList.contains("eg-pool-boy")) {
          item.classList.remove("eg-pool-boy");
        }
        if (item.querySelector(".eg-label")) {
          item.querySelector(".eg-label").remove();
        }
      });
    }

    function updateContent(egItems) {
      egItems.forEach((item) => {
        let egTarget = item.querySelector(
          ".cart__item .cart__item__content > .gara"
        );

        console.log((egTarget.querySelector("p").innerText.toUpperCase().indexOf("SPF 30 LIP BALM FOR $5") != -1));

        if (
          egTarget.querySelector("p").innerText.toUpperCase().indexOf("GET THE SUMMER LEISURE PACK FOR $30 AND SAVE $10!") != -1
        ) {
          if (!egTarget.querySelector(".eg-label")) {
            item.classList.add("eg-active");
            item.classList.add("eg-whip");
            egTarget.insertAdjacentHTML("afterbegin", `<span class="eg-label">${egLabels[1]}</span>`);
          }
        } else if (
          (egTarget.querySelector("p").innerText.toUpperCase().indexOf("SPF 30 LIP BALM FOR $5") != -1) ||
          egTarget.querySelector("p").innerText.toUpperCase() == "GET THE AFTER SUN GEL FOR $12"
        ) {
          egTarget.querySelector("p").innerText =
            "Get the After Sun Gel for $12";
          //   checkIfInCart();
          if (!egTarget.querySelector(".eg-label")) {
            item.classList.add("eg-active");
            item.classList.add("eg-pool-boy");
            egTarget.insertAdjacentHTML(
              "afterbegin",
              `<span class="eg-label">${egLabels[2]}</span>`
            );

            // adding a new button
            if (!item.querySelector(".eg-new-button")) {
              item.querySelector(".cart__item .cart__item__content").insertAdjacentHTML("beforeend", `<div data-vId = "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80NDUwMDU0MTgzMzQ0OQ==" data-vName = "After Sun Gel" class="eg-new-button">ADD</div>`);
            }

            item.querySelector(".cart__item__image > a").href = "https://www.vacation.inc/products/after-sun-gel";
            item.querySelector(".image img").src =
              "https://cdn.shopify.com/s/files/1/0553/2984/9518/products/Vacation_Renders-CoreLine_AfterSun_Front_481ec473-1153-4e89-9ed0-dcd981ea72df_200x200.png?v=1680623336";

          }
        } else if (
          egTarget.querySelector("p").innerText.toUpperCase() ==
          "GET THE SCENT OF THE WORLD'S BEST-SMELLING SUNSCREEN, FOR YOUR CAR OR HOME OFFICE FOR $5" ||
          (egTarget.querySelector("p").innerText.toUpperCase().indexOf("GET THE WORLD'S MOST INDULGENT SUNSCREEN OIL FOR $22") != -1)
        ) {
          egTarget.querySelector("p").innerText =
            "Get the scent of the world's best-smelling sunscreen, for your car or home office for $5";
          //   checkIfInCart();
          if (!egTarget.querySelector(".eg-label")) {
            item.classList.add("eg-active");
            item.classList.add("eg-air-freshener");
            egTarget.insertAdjacentHTML("afterbegin", `<span class="eg-label">${egLabels[0]}</span>`);

            // adding a new button
            if (!item.querySelector(".eg-new-button")) {
              item.querySelector(".cart__item .cart__item__content").insertAdjacentHTML("beforeend", `<div data-vId = "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zOTUwNjU0OTU3MTc1OA==" data-vName = "Vacation air freshner" class="eg-new-button">ADD</div>`);
            }
            item.querySelector(".cart__item__image > a").href = "https://www.vacation.inc/products/air-freshener";
            item.querySelector(".image img").src =
              "https://cdn.shopify.com/s/files/1/0553/2984/9518/products/air-fresh_200x200.png?v=1627510488";
          }
        }
      });
    }

    function listener() {
      /* These are the modifications: */
      window.addEventListener("locationchange", function () {
        waitForElement(".cart .keen-slider .keen-slider__slide", 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();

    /* Initialize variation */
    waitForElement(".cart .keen-slider .keen-slider__slide", init, 50, 15000);

    // add to cart functionality
    function readCookie(name) {
      // READ COOKIE
      var nameEQ = name + "=";
      var ca = document.cookie.split(";");
      for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == " ") c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
      }
      return null;
    }

    var setCookie = function (name, value, days) {
      var expires = "";
      if (days) {
        var date = new Date();
        date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
        expires = "; expires=" + date.toUTCString();
      }
      document.cookie = name + "=" + (value || "") + expires + "; path=/";
    };

    var delCookie = function (name) {
      document.cookie = name + "=; Max-Age=0; path=/;";
    };

    // if cokee exists then click on the bag btn
    if (readCookie("openCart")) {
      waitForElement(".header__nav > div > div > div:last-child button",
        function () {
          delCookie("openCart");
          document.querySelector(".header__nav > div > div > div:last-child button").click();
        }, 50, 15000);
    }
  } catch (e) {
    if (debug) console.log(e, "error in Test" + variation_name);
  }
})();



<style>
.cart .keen-slider {
    display: flex;
    flex-direction: column;
    overflow-y: visible !important;
    max-height: max-content !important;
    transform: none !important;
}

.cart .keen-slider .keen-slider__slide {
    height: 100px;
}

.cart .keen-slider .keen-slider__slide:not(:last-child) {
    margin-top: 15px !important;
}

.cart .keen-slider .keen-slider__slide .cart__item {
    border: 3px solid;
    height: 100px;
}

.cart .keen-slider .keen-slider__slide .cart__item .cart__item__image {
    width: 80px;
    height: 100px !important;
}

.cart .keen-slider .keen-slider__slide .cart__item .cart__item__content {
    height: 100px !important;
    padding: 0 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin-top: -2px;
}

.cart .keen-slider .keen-slider__slide .cart__item .cart__item__content>.gara {
    font-size: 14px !important;
    line-height: 1;
    margin-bottom: 0;
    letter-spacing: 0.3px;
}

.cart .keen-slider .keen-slider__slide .cart__item .cart__item__quantity {
    width: 60px;
    height: 20px;
    margin-top: 8px;
}

.eg-label {
    font-weight: 500;
    border-radius: 20px;
    font-size: 9px;
    line-height: 1.2;
    padding: 5px 12px 2px;
    text-transform: uppercase;
    font-family: OptimaLTP;
    font-style: normal;
    display: inline-block;
    background-color: #e2ddd4;
    margin-block: 8px;
}

.cart .cart-carousel+div {
    display: none;
}

/*hiding unnessesary slides*/

.cart .keen-slider .keen-slider__slide {
    display: none;
}

.cart .keen-slider .keen-slider__slide.eg-active {
    display: block;
}

/*changing order of the slides*/
.eg-air-freshener {
    order: -2;
}

.eg-whip {
    order: -1;
}

.eg-pool-boy.eg-hide,
.eg-air-freshener.eg-hide {
    display: none !important;
}

.eg-new-button {
    width: 60px;
    height: 20px;
    margin-top: 8px;
    border-radius: 25px;
    border: 2px solid;
    font-family: ITCGaramondStd-LtCond;
    font-weight: 400;
    font-style: normal;
    font-size: 13.333px !important;
    display: none;
    justify-content: center;
    align-items: center;
    padding-top: 4px;
}

.eg-pool-boy .cart__item__quantity,
.eg-air-freshener .cart__item__quantity {
    display: none !important;
}

.eg-pool-boy .eg-new-button,
.eg-air-freshener .eg-new-button {
    display: flex !important;
}


/* fixing height and stuff */
.cart .keen-slider {
    display: flex;
    flex-direction: column;
    overflow-y: visible !important;
    max-height: max-content !important;
}

.cart .keen-slider .keen-slider__slide {
    transform: none !important;
    height: auto !important;
}

.cart .keen-slider .keen-slider__slide+.keen-slider__slide {
    margin-top: 10px !important;
}

.cart .keen-slider .keen-slider__slide .cart__item {
    border: 3px solid;
    height: auto !important;
}

.cart .keen-slider .keen-slider__slide .cart__item .cart__item__image {
    width: 80px;
    display: flex;
    height: auto !important;
    justify-content: center;
    align-items: center;
}

.cart .keen-slider .keen-slider__slide .cart__item .cart__item__content {
    height: auto !important;
    padding-left: 10px !important;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-top: 10px !important;
    padding-bottom: 10px !important;
    padding-right: 10px !important;
}

.cart .keen-slider .keen-slider__slide .cart__item .cart__item__content>.gara {
    font-size: 14px !important;
    line-height: 1;
    margin-bottom: 0;
    letter-spacing: 0.3px;
}

.cart .keen-slider .keen-slider__slide .cart__item .cart__item__quantity {
    width: 60px;
    height: 20px;
    margin-top: 0 !important;
}

.eg-label {
    font-weight: 500;
    border-radius: 20px;
    font-size: 9px;
    line-height: 1.2;
    padding: 5px 12px 2px;
    text-transform: uppercase;
    font-family: OptimaLTP;
    font-style: normal;
    display: inline-block;
    margin: 0 !important;
    background-color: #e2ddd4;
}

.cart .keen-slider+div {
    display: none;
}

/*hiding unnessesary slides*/

.cart .keen-slider .keen-slider__slide {
    display: none;
}

.cart .keen-slider .keen-slider__slide.eg-active {
    display: block;
}

/*changing order of the slides*/
.eg-air-freshener {
    order: -2;
}

.eg-whip {
    order: -1;
}

.eg-ball-boy.eg-hide {
    display: none !important;
}

.eg-new-button {
    width: 60px;
    height: 20px;
    margin-top: 0 !important;
    border-radius: 25px;
    border: 2px solid;
    font-family: ITCGaramondStd-LtCond;
    font-weight: 400;
    font-style: normal;
    font-size: 13.333px !important;
    display: none;
    justify-content: center;
    align-items: center;
    padding-top: 4px;
    cursor: pointer;
}

.eg-ball-boy .cart__item__quantity {
    display: none !important;
}

.eg-ball-boy .eg-new-button {
    display: flex !important;
    cursor: pointer;
}

@media(max-width:767px) {
    .cart .keen-slider .keen-slider__slide .cart__item .cart__item__content>.gara {
        font-size: 11px !important;
    }
}



.cart .keen-slider .keen-slider__slide .cart__item .cart__item__image .image,
.cart .keen-slider .keen-slider__slide .cart__item .cart__item__image .image img,
.cart .keen-slider .keen-slider__slide .cart__item .cart__item__image .image picture {
    position: static;
    padding: 0 !important;
    height: 100%;
    width: 100%;
}

.cart .keen-slider .keen-slider__slide .cart__item .cart__item__content>.gara>p {
    margin-top: 8px !important;
    margin-bottom: 5px !important;
}

.cart .keen-slider .keen-slider__slide .cart__item .cart__item__quantity span {
    position: static !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart .keen-slider .keen-slider__slide .cart__item .cart__item__quantity span>span {
    padding-top: 2px !important;
}
</style>