Untitled
unknown
plain_text
2 years ago
17 kB
4
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-ball-boy .eg-new-button", "click", function () { // add to cart functionality let varientId = "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80Mzc2NDgyODMwNzY4OQ=="; let varientName = "Ball Boy Scented Candle"; 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(".keen-slider.cart__upsells > .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(".keen-slider.cart__upsells > .keen-slider__slide"),]; removeClasses(egItems); waitForElement(".keen-slider.cart__upsells > .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 egIsPresent = contains("#__next .cart .cart__item .cart__item__content >div >div >div >div .cart__content:nth-of-type(1)", "PRINCE X VACATION BALL BOY SCENTED CANDLE"); if (egIsPresent.length > 0) { console.log(egIsPresent); document.querySelector(".eg-ball-boy") && document.querySelector(".eg-ball-boy").classList.add("eg-hide"); } else { document.querySelector(".eg-ball-boy") && document.querySelector(".eg-ball-boy").classList.remove("eg-hide"); } }, 50, 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(".keen-slider.cart__upsells > .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(".keen-slider.cart__upsells > .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-ball-boy")) { item.classList.remove("eg-ball-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"); if ( egTarget.querySelector("p").innerText.toUpperCase() == "GET THE SCENT OF THE WORLD'S BEST-SMELLING SUNSCREEN, FOR YOUR CAR OR HOME OFFICE FOR $5" ) { 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>`); } } else 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() == "GET THE POOL BOY SCENTED CANDLE FOR $34" || egTarget.querySelector("p").innerText.toUpperCase() == "GET THE BALL BOY SCENTED CANDLE FOR $42" ) { egTarget.querySelector("p").innerText = "Get the ball boy scented candle for $42"; // checkIfInCart(); if (!egTarget.querySelector(".eg-label")) { item.classList.add("eg-active"); item.classList.add("eg-ball-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 class="eg-new-button">ADD</div>`); } item.querySelector(".image img").src = "https://cdn.sanity.io/images/kie4hq77/development/732f1da20fad1e74ff5f56e9ab52357909e65dfb-1000x1000.png?auto=format&q=80&w=400&h=400"; } } }); } function listener() { /* These are the modifications: */ window.addEventListener("locationchange", function () { waitForElement(".keen-slider.cart__upsells > .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(".keen-slider.cart__upsells > .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> .keen-slider.cart__upsells { display: flex; flex-direction: column; overflow-y: visible !important; max-height: max-content !important; gap: 10px; } .keen-slider.cart__upsells > .keen-slider__slide { transform: none !important; height: 100px; } .keen-slider.cart__upsells > .keen-slider__slide .cart__item {border: 3px solid;height: 100px;} .keen-slider.cart__upsells > .keen-slider__slide .cart__item .cart__item__image { width: 80px; height: 100px !important; } .keen-slider.cart__upsells > .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; } .keen-slider.cart__upsells > .keen-slider__slide .cart__item .cart__item__content > .gara { font-size: 14px !important; line-height: 1; margin-bottom: 0; letter-spacing: .3px; } .keen-slider.cart__upsells > .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; display: none !important; } .keen-slider.cart__upsells + div { display: none; } /*hiding unnessesary slides*/ .keen-slider.cart__upsells > .keen-slider__slide { display: none; } .keen-slider.cart__upsells > .keen-slider__slide.eg-active{ display: block !important; } /*changing order of the slides*/ .eg-air-freshener { order: -2; } .eg-whip { order: -1; } </style>
Editor is loading...