Untitled
unknown
plain_text
a year ago
14 kB
1
Indexable
Never
(function () { try { var debug = 0; var variation_name = ""; var $; 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) } 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); } waitForjQuery(function () { $ = window.jQuery; addScript(); }); 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 (el && found) callback.call(el, e); }); } live(selector, event, callback, context); } function init() { // recommended section to slider if (window.innerWidth < 992) { rCToSlider(); } // wrapping full description elements // waitForElement("html body .product-full-description .wrapper >*:last-child", function () { // const accordionData = []; // if (!document.querySelector(".eg-full-des-description")) { // document.querySelectorAll('html body .product-full-description .wrapper > *').forEach(itm => { // if (itm.innerHTML.trim() === '<br>') itm.remove(); // if (isAllUpperCase(itm)) { // const accrObj = { // "ctaTxt": "", // "content": "" // }; // accrObj.ctaTxt = itm.innerText; // accrObj.content = itm.nextElementSibling.innerHTML; // accordionData.push(accrObj); // itm.nextElementSibling.remove(); // itm.remove(); // } // }); // // full des description // $('html body .product-full-description .wrapper > *').wrapAll("<div class='eg-full-des-description eg-des'></div>"); // // eg full des // const elTwo = document.createElement("div"); // elTwo.classList.add("eg-full-des"); // let accordionHTML = accordionData.reduce((t, crr) => { // if (crr) { // return t += `<div class="eg-accordion-cta">${crr.ctaTxt}</div><div>${crr.content}</div>`; // } // }, ""); // elTwo.innerHTML = accordionHTML; // document.querySelector('html body .product-full-description .wrapper').insertAdjacentElement("beforeend", elTwo); // const newpara = [...document.querySelectorAll(".eg-full-des-description>*:not(.eg-readmore)")].reduce((t, crr) => { // if (crr) { // return t += crr.innerHTML.trim(); // } // }, ""); // document.querySelector(".eg-full-des-description").innerHTML = `<p>${newpara}</p> <a class="eg-readmore" data-txt="Read more"></a>`; // } // }, 500, 15000); // product details main redesinging productDetails(); // readmoreClick live('html body .eg-readmore', 'click', function () { this.closest(".eg-des").classList.toggle("eg-show-more"); const txt = this.getAttribute("data-txt"); txt === "Read more" ? this.setAttribute("data-txt", "Read less") : this.setAttribute("data-txt", "Read more"); }); // accordion clicks live('.eg-accordion-cta', "click", function () { const previousAct = this.parentElement.querySelector(".eg-show-below"); if (previousAct && previousAct !== this) { previousAct.classList.remove("eg-show-below"); } this.classList.toggle("eg-show-below"); }); // expand on zoom in live(".eg-zoom-in-cta", 'click', function () { if (window.MagicZoom != undefined) { if (document.querySelector(".MagicZoom")) { MagicZoom.expand(document.querySelector(".MagicZoom")); } } }); // play youtube video live(".eg-video", 'click', function () { const ytIframe = document.querySelector("html body .product-details-secondary .video iframe[src]"); if (ytIframe) { const youtubeUrl = this.getAttribute("data-src"); if (youtubeUrl) { ytIframe.setAttribute("src", `${youtubeUrl}?autoplay=1`); ytIframe.scrollIntoView({ behavior: 'smooth', block: "start" }); } } }); // make right side sticky rightSideSticky(); } const rightSideSticky = () => { waitForElement('html body .product-details>div:last-child', function () { if (window.innerWidth > 1199) { var rightDiv = document.querySelector("html body .product-details>div:last-child"); rightDiv.style.top = 0; window.addEventListener('scroll', function () { if (scrollY > 128) { rightDiv.style.top = (scrollY - 128) + 'px'; } else { rightDiv.style.top = 0; } }) } }, 500, 15000); } const rCToSlider = () => { waitForElement('html body .recommended-products .products >div>div:last-child', function () { const sel = 'html body .recommended-products .products >div'; const settings = { slidesToScroll: 1, slidesToShow: 3, arrows: false, dots: true, speed: 300, draggable: true, swipeToSlide: true, responsive: [ { breakpoint: 768, settings: { slidesToShow: 2, slidesToScroll: 1, arrows: false, } } ] } makeSlider(sel, settings) }, 500, 15000); } const makeSlider = (sel, settings) => { waitForSlick(function () { $(sel).slick(settings); }); } const productDetails = () => { waitForElement("html body .product-details-main .details .description", function () { // description to accordion const desDiv = document.querySelector("html body .product-details-main .details .description"); if (!desDiv.parentElement.querySelector(".eg-accordion-cta")) { desDiv.insertAdjacentHTML("beforebegin", `<div class="eg-accordion-cta">Description</div>`); } // moving product badge list below form waitForElement("html body .product-details-main .details .product-badge-list", function () { document.querySelector("html body #orderform").insertAdjacentElement("afterend", document.querySelector("html body .product-details-main .details .product-badge-list")); }, 500, 15000); // featured and specs waitForElement("html body .details-specification>div .wrapper .collapse-toggle", function () { document.querySelectorAll("html body .details-specification>div .wrapper .collapse-toggle").forEach(cta => { cta.classList.add("eg-accordion-cta"); }); desDiv.insertAdjacentElement("afterend", document.querySelector("html body .details-specification")); }, 500, 15000); // making box of images slide(); // putting instok in desktop inStockCheck(); }, 500, 15000); } const inStockCheck = () => { waitForElement("html body .mobile-product-header .stock-status-line", function () { const stockHtml = `<div class="stock-status-line eg-des-stock"><span class="stock-in">In Stock</span></div>`; if (!document.querySelector(".eg-des-stock")) document.querySelector("html body .product-details-main .details .product-price-payments .product-price").insertAdjacentHTML("beforeend", stockHtml); }, 500, 15000); } function slide() { waitForElement(".MagicToolboxSelectorsContainer a", function () { const imgSrcs = []; document.querySelectorAll('.MagicToolboxSelectorsContainer a').forEach(function (val) { imgSrcs.push(val.getAttribute('data-image')); }); if (!document.querySelector(".eg-new-slides")) { const imgsHTML = imgSrcs.reduce((t, crr) => { return t += `<div class="eg-slide"><img src="${crr}"/></div>`; }, ""); const newSlideHTML = `<div class="eg-new-slides">${imgsHTML}</div><a class="eg-zoom-in-cta"><img src="https://svgshare.com/i/xb7.svg">Zoom In</a>`; document.querySelector("html body .product-details .image .image-box").insertAdjacentHTML("beforeend", newSlideHTML); document.querySelector("html body .product-details .image .image-box").classList.add('eg-thumbs'); // create extra slide if video exists const ytIframe = document.querySelector("html body .product-details-secondary .video iframe[src]"); if (ytIframe) { const youtubeUrl = ytIframe.getAttribute("src"); if (youtubeUrl) { const videoId = extractYouTubeVideoId(youtubeUrl); console.log('YouTube Video ID:', videoId); const youtubeThumb = `https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`; const imgHTML = `<div class="eg-slide eg-video" data-src="${youtubeUrl}"><img src="${youtubeThumb}"/></div>`; document.querySelector(".eg-new-slides").insertAdjacentHTML("beforeend", imgHTML); } } if (window.innerWidth < 992) { const sel = 'html body .eg-new-slides'; const settings = { slidesToScroll: 1, slidesToShow: 1, arrows: true, dots: true, speed: 300, draggable: true, swipeToSlide: true, } makeSlider(sel, settings); } } }, 500, 15000); } function extractYouTubeVideoId(url) { const regExp = /^(?:https?:\/\/)?(?:www\.)?youtube\.com\/(?:watch\?v=|embed\/|v\/|shorts\/)([a-zA-Z0-9_-]{11})/; const match = url.match(regExp); if (match && match[1]) { return match[1]; } else { return null; // Return null if no match found } } function isAllUpperCase(element) { if (!element || !element.textContent) { console.error('Invalid element or empty text content.'); return false; } const text = element.textContent.trim(); const uppercaseText = text.toUpperCase(); return text === uppercaseText; } waitForElement('html body', init, 50, 15000); } catch (e) { if (debug) console.log(e, "error in Test" + variation_name); } })();