index
Free Shipping On All Orders Now
' ); iframeDoc.close(); } catch (error) { } }; window.codkReinitSvelteIframe = function() { var f = document.getElementById('codk-full-modal-svelte'); if (!f || !f.contentWindow) return; window.codkSvelteAppMounted = false; var cacheBust = '_ri=' + Date.now(); try { var doc = f.contentWindow.document; doc.open(); var bodyStyle = isMobile() ? 'margin:0;padding:0;background:transparent;height:100vh;' : 'margin:0;padding:0;background:transparent;height:auto;min-height:100%;'; var htmlStyle = isMobile() ? 'background:transparent;height:100%;' : 'background:transparent;height:auto;min-height:100%;'; var SVELTE_JS_URL = "https://cdn.shopify.com/s/files/1/0743/3119/3628/files/svellte_production_js.js?v=1788185380"; var SVELTE_CSS_URL = "https://cdn.shopify.com/s/files/1/0743/3119/3628/files/svelte_production_css.css?v=1788185369"; var jsSep = SVELTE_JS_URL.indexOf('?') === -1 ? '?' : '&'; var cssSep = SVELTE_CSS_URL.indexOf('?') === -1 ? '?' : '&'; doc.write('COD King OTP<\/head>
<\/div><\/scr' + 'ipt><\/body><\/html>'); doc.close(); } catch (e) { } }; initializeSvelteApp(); } window.addEventListener('codking-svelte-ready', () => { }); if (!window.__codkPageshowListenerAdded) { window.__codkPageshowListenerAdded = true; window.addEventListener('pageshow', function(event) { if (!event.persisted) return; document.body.style.overflow = ''; document.body.style.position = ''; document.body.style.width = ''; document.body.style.top = ''; var currentIframe = document.getElementById('codk-full-modal-svelte'); var svelteWorking = false; try { svelteWorking = currentIframe && currentIframe.contentWindow && currentIframe.contentWindow.appStore && window.codkingSvelteReady; } catch (e) {} if (svelteWorking) { hideIframe(currentIframe); return; } if (currentIframe && currentIframe.parentNode) { currentIframe.parentNode.removeChild(currentIframe); } iframe = null; window.codkSvelteInitialized = false; window.codkingSvelteReady = false; window.codkSvelteAppMounted = false; window.codkModalShowingSpinner = false; window.codkOtpModalOpen = false; iframe = ensureIframe(); try { var iframeDoc = iframe.contentWindow.document; var cacheBust = '_bfc=' + Date.now(); var bodyStyle = isMobile() ? 'margin:0;padding:0;background:transparent;height:100vh;' : 'margin:0;padding:0;background:transparent;height:auto;min-height:100%;'; var htmlStyle = isMobile() ? 'background:transparent;height:100%;' : 'background:transparent;height:auto;min-height:100%;'; window.codkSvelteAppMounted = false; iframeDoc.open(); iframeDoc.write( '' + '' + 'COD King OTP' + '' + '
' + '<\/scr' + 'ipt>' + '' ); iframeDoc.close(); window.codkSvelteInitialized = true; } catch (e) { } }); } let resizeTimeout; window.addEventListener('resize', () => { clearTimeout(resizeTimeout); resizeTimeout = setTimeout(() => { const iframe = document.getElementById('codk-full-modal-svelte'); if (iframe && iframe.getAttribute('data-visible') === 'true') { const mobile = isMobile(); if (mobile) { try { if (iframe.contentWindow && iframe.contentWindow.document) { iframe.contentWindow.document.documentElement.style.height = '100%'; iframe.contentWindow.document.body.style.height = '100vh'; } } catch (e) { } } else { try { if (iframe.contentWindow && iframe.contentWindow.document) { iframe.contentWindow.document.documentElement.style.height = 'auto'; iframe.contentWindow.document.documentElement.style.minHeight = '100%'; iframe.contentWindow.document.body.style.height = 'auto'; iframe.contentWindow.document.body.style.minHeight = '100%'; } } catch (e) { } } } }, 150); }); const showSpinner = function() { iframe = iframe || document.getElementById('codk-full-modal-svelte'); if (!iframe) { window.codkSvelteInitialized = false; if (typeof window.codkInitSvelteApp === "function") { window.codkInitSvelteApp(); } return; } if (!iframe.contentWindow || !iframe.contentWindow.document) { window.codkSvelteInitialized = false; if (typeof window.codkInitSvelteApp === "function") { window.codkInitSvelteApp(); } return; } window.codkModalShowingSpinner = true; window.codkSvelteAppMounted = false; const iframeDoc = iframe.contentWindow.document; const appDiv = iframeDoc.getElementById('app'); if (appDiv) { appDiv.innerHTML = '' + '
' + '' + '
' + '
Loading...
' + '
'; } else { } window.codkScrollY = window.scrollY || 0; document.body.style.overflow = 'hidden'; document.body.style.position = 'fixed'; document.body.style.width = '100%'; document.body.style.top = '-' + window.codkScrollY + 'px'; const mobile = isMobile(); if (mobile) { try { if (iframe.contentWindow && iframe.contentWindow.document) { iframe.contentWindow.document.documentElement.style.height = '100%'; iframe.contentWindow.document.body.style.height = '100vh'; } } catch (e) { } } else { try { if (iframe.contentWindow && iframe.contentWindow.document) { iframe.contentWindow.document.documentElement.style.height = 'auto'; iframe.contentWindow.document.documentElement.style.minHeight = '100%'; iframe.contentWindow.document.body.style.height = 'auto'; iframe.contentWindow.document.body.style.minHeight = '100%'; } } catch (e) { } } showIframe(iframe); }; const updateMessage = function(message) { if (!iframe || !iframe.contentWindow) { return; } const iframeDoc = iframe.contentWindow.document; const messageEl = iframeDoc.querySelector('.message'); if (messageEl) { messageEl.innerHTML = message; } else { } }; const checkSvelteStatus = function() { if (window.codkingSvelteReady) { updateMessage(""); } else { } }; const clearSpinner = function() { window.codkModalShowingSpinner = false; try { if (!iframe || !iframe.contentWindow) { return; } const iframeDoc = iframe.contentWindow.document; const appDiv = iframeDoc.getElementById('app'); if (appDiv) { const spinnerContainer = appDiv.querySelector('.container'); const spinnerStyle = iframeDoc.querySelector('style'); const svelteMounted = iframe.contentWindow && iframe.contentWindow.appStore; if (spinnerContainer) { if (!svelteMounted) { appDiv.innerHTML = ''; } else { spinnerContainer.remove(); } } if (spinnerStyle && spinnerStyle.textContent.includes('.container')) { spinnerStyle.remove(); } const computedStyle = iframeDoc.defaultView.getComputedStyle(appDiv); if (computedStyle.position === 'fixed' && computedStyle.zIndex === '999999') { appDiv.style.cssText = ''; } if (!spinnerContainer && !spinnerStyle) { } } else { } } catch (error) { } }; window.addEventListener('codking-svelte-ready', function() { requestAnimationFrame(function() { clearSpinner(); setTimeout(function() { clearSpinner(); }, 50); }); }); const closeModal = function(isManualClose = true) { window.codkModalShowingSpinner = false; if (window.codkSvelteReadyPollId) { clearInterval(window.codkSvelteReadyPollId); window.codkSvelteReadyPollId = null; } const iframeElement = document.getElementById('codk-full-modal-svelte'); if (!iframeElement) { return; } if (iframeElement !== iframe) { } const scrollY = window.codkScrollY || 0; hideIframe(iframe); document.body.style.removeProperty('overflow'); document.body.style.removeProperty('position'); document.body.style.removeProperty('width'); document.body.style.removeProperty('top'); document.body.style.removeProperty('height'); if (document.documentElement) { document.documentElement.style.removeProperty('overflow'); document.documentElement.style.removeProperty('position'); document.documentElement.style.removeProperty('width'); document.documentElement.style.removeProperty('height'); } window.codkEssentialCartGuard = false; if (window.codkEssentialCartGuardTimer) { clearInterval(window.codkEssentialCartGuardTimer); window.codkEssentialCartGuardTimer = null; } if (scrollY > 0) { window.scrollTo(0, scrollY); } else { window.scrollTo(0, 0); } try { if (iframe && iframe.contentWindow && iframe.contentWindow.appStore) { setTimeout(function() { iframe.contentWindow.appStore.update(function(state) { return { ...state, isOpen: false }; }); }, 0); } } catch (error) { } if (typeof window.codkIsProcessing !== 'undefined') { window.codkIsProcessing = false; } window.codkScrollY = 0; }; window.addEventListener('message', function(event) { var closeModalMessage = event.data === 'codk-close-modal' || (Array.isArray(event.data) && event.data[0] === 'codk-close-modal'); if (closeModalMessage) { if (window.codkModalShowingSpinner === true) { return; } closeModal(true); return; } if (event.data && typeof event.data === 'object' && event.data.type === 'codking:reattachButtonBlock') { if (buttonBlocking && typeof buttonBlocking.observeButtons === 'function') { buttonBlocking.observeButtons(); } return; } if (event.data && typeof event.data === 'object' && !Array.isArray(event.data) && event.data.type === 'codk-iframe-height') { const iframe = document.getElementById('codk-full-modal-svelte'); if (iframe && iframe.getAttribute('data-visible') === 'true' && !event.data.isMobile) { const height = event.data.height; const maxHeight = Math.min(height, window.innerHeight * 0.9); iframe.style.height = maxHeight + 'px'; } return; } if (Array.isArray(event.data) && event.data.length >= 1 && (event.data[0] === 'null' || event.data[0] == null)) { return; } }); if (!window.__codkScrollYDefined) { let _codkScrollY = 0; Object.defineProperty(window, 'codkScrollY', { get: function() { return _codkScrollY; }, set: function(value) { _codkScrollY = value; }, configurable: true }); window.__codkScrollYDefined = true; } function isShopifyBuyNowButton(buttonElement) { if (!buttonElement) { return false; } const productButtonSelectors = COD_BUTTON_SELECTORS.BUY_NOW; const isBuyNowButton = productButtonSelectors.some(function(selector) { return buttonElement.matches(selector); }); const isBuyNowClass = buttonElement.classList.contains("shopify-payment-button__button") && buttonElement.classList.contains( "shopify-payment-button__button--unbranded" ); const parentElement = buttonElement.closest("shopify-buy-it-now-button"); const hasBuyNowAttributes = parentElement && parentElement.hasAttribute("access-token") && parentElement.hasAttribute("buyer-country") && parentElement.hasAttribute("buyer-currency"); return isBuyNowButton || isBuyNowClass || hasBuyNowAttributes; } function resolveShopifyBuyNowButtonFromClick(clickedButton) { if (!clickedButton || typeof clickedButton.closest !== "function") { return null; } var host = clickedButton.closest("shopify-buy-it-now-button"); if (host) { var innerBtn = host.querySelector("button.shopify-payment-button__button") || host.querySelector("button[class*='shopify-payment-button__button']"); if (innerBtn && isShopifyBuyNowButton(innerBtn)) { return innerBtn; } } if ( clickedButton.classList && clickedButton.classList.contains("tpo-buy-it-now-btn") ) { var paymentRoot = clickedButton.closest("[data-shopify='payment-button']") || clickedButton.closest(".shopify-payment-button"); if (paymentRoot) { var resolved = paymentRoot.querySelector("button.shopify-payment-button__button") || paymentRoot.querySelector( "button[class*='shopify-payment-button__button']" ); if (resolved && isShopifyBuyNowButton(resolved)) { return resolved; } } } return null; } function checkShopifyBuyNowButtons(clickedButton) { if (isShopifyBuyNowButton(clickedButton)) { return true; } var resolvedFromOverlay = resolveShopifyBuyNowButtonFromClick(clickedButton); if (resolvedFromOverlay) { return true; } const buttonSelectors = COD_BUTTON_SELECTORS.BUY_NOW; const buttonElement = buttonSelectors .map(function(selector) { return clickedButton.querySelector(selector); }) .find(function(button) { return button && isShopifyBuyNowButton(button); }); if (buttonElement) { return true; } return false; } const checkDefaultCountrySvelte = async function() { const settingsStr = sessionStorage.getItem("settingSession"); if (!settingsStr) { return true; } let parsedSettings; try { parsedSettings = JSON.parse(settingsStr); } catch (e) { return true; } const geoCountriesRaw = parsedSettings?.preGeoCountries; const geoCountries = (geoCountriesRaw || "") .split(",") .map(function(c) { return c.trim().toLowerCase(); }) .filter(Boolean); if (!geoCountriesRaw || geoCountriesRaw.trim() === "") { return true; } let defaultCountry = localStorage.getItem("defaultCountry"); if (!defaultCountry) { try { const response = await fetch("https://api.country.is/"); const data = await response.json(); defaultCountry = (data?.country || "").toLowerCase(); localStorage.setItem("defaultCountry", JSON.stringify(defaultCountry)); } catch (err) { return true; } } else { try { defaultCountry = JSON.parse(defaultCountry); } catch (e) { defaultCountry = defaultCountry.toLowerCase(); } if (defaultCountry === "") { return true; } } const isAllowed = geoCountries.includes(defaultCountry); return isAllowed; }; const _codkblockListener = async function(e) { e.preventDefault(); e.stopPropagation(); let codkSettings = {}; try { codkSettings = JSON.parse(sessionStorage.getItem("settingSession") || "{}"); } catch (_e) {} const shouldShowOTP = await checkDefaultCountrySvelte(); if (!shouldShowOTP) { if (buttonBlocking) { buttonBlocking.removeButtonListeners(); } e.target.click(); return; } const isBuyNowButton = checkShopifyBuyNowButtons(e.target); if (isBuyNowButton) { sessionStorage.setItem('cod_king_buyNow', JSON.stringify({ enabled: true, variantId: null, quantity: 1 })); sessionStorage.setItem('cod_king_isBuyNow', 'true'); } else { if (Number(codkSettings?.preV2OverwritePopupCondition) === 10) { document.dispatchEvent(new CustomEvent("essential-cart:close")); window.codkEssentialCartGuard = true; if (!window.codkEssentialCartGuardTimer) { window.codkEssentialCartGuardTimer = setInterval(function () { if (!window.codkEssentialCartGuard) return; if (document.documentElement.classList.contains("essential-cart__open")) { document.dispatchEvent(new CustomEvent("essential-cart:close")); } }, 100); } } sessionStorage.setItem('cod_king_buyNow', JSON.stringify({ enabled: false, variantId: null, quantity: 1 })); sessionStorage.removeItem('cod_king_isBuyNow'); sessionStorage.removeItem('cod_king_buy_now_variantId'); sessionStorage.removeItem('cod_king_buy_now_quantity'); } if (window.codkingSvelteReady) { try { const iframe = document.getElementById('codk-full-modal-svelte'); if (iframe && iframe.contentWindow && iframe.contentWindow.appStore) { if ( iframe.contentWindow.appActions && typeof iframe.contentWindow.appActions.openModal === "function" ) { iframe.contentWindow.appActions.openModal(); } else { iframe.contentWindow.appStore.update(function(state) { return { ...state, isOpen: true }; }); } window.codkScrollY = window.scrollY || 0; document.body.style.overflow = 'hidden'; document.body.style.position = 'fixed'; document.body.style.width = '100%'; document.body.style.top = '-' + window.codkScrollY + 'px'; const mobile = isMobile(); if (mobile) { try { if (iframe.contentWindow && iframe.contentWindow.document) { iframe.contentWindow.document.documentElement.style.height = '100%'; iframe.contentWindow.document.body.style.height = '100vh'; } } catch (e) { } } else { try { if (iframe.contentWindow && iframe.contentWindow.document) { iframe.contentWindow.document.documentElement.style.height = 'auto'; iframe.contentWindow.document.documentElement.style.minHeight = '100%'; iframe.contentWindow.document.body.style.height = 'auto'; iframe.contentWindow.document.body.style.minHeight = '100%'; } } catch (e) { } } showIframe(iframe); } else { showSpinner(); checkSvelteStatus(); } } catch (error) { console.error("Full error:", error); showSpinner(); checkSvelteStatus(); } } else { if (typeof window.codkReinitSvelteIframe === 'function') { window.codkReinitSvelteIframe(); } showSpinner(); checkSvelteStatus(); let svelteReadyPollId = null; let svelteReadyPollAttempts = 0; const openModalWhenReady = function() { if (svelteReadyPollId) { clearInterval(svelteReadyPollId); svelteReadyPollId = null; } window.codkSvelteReadyPollId = null; window.removeEventListener('codking-svelte-ready', openModalWhenReady); try { const iframe = document.getElementById('codk-full-modal-svelte'); if (iframe && iframe.contentWindow && iframe.contentWindow.appStore) { setTimeout(function() { iframe.contentWindow.appStore.update(function(state) { return { ...state, isOpen: true }; }); const mobile = isMobile(); if (mobile) { try { if (iframe.contentWindow && iframe.contentWindow.document) { iframe.contentWindow.document.documentElement.style.height = '100%'; iframe.contentWindow.document.body.style.height = '100vh'; } } catch (e) { } } else { try { if (iframe.contentWindow && iframe.contentWindow.document) { iframe.contentWindow.document.documentElement.style.height = 'auto'; iframe.contentWindow.document.documentElement.style.minHeight = '100%'; iframe.contentWindow.document.body.style.height = 'auto'; iframe.contentWindow.document.body.style.minHeight = '100%'; } } catch (e) { } } showIframe(iframe); }, 50); } } catch (error) { } }; window.addEventListener('codking-svelte-ready', openModalWhenReady); svelteReadyPollId = setInterval(function() { if (window.codkingSvelteReady === true) { if (svelteReadyPollId) { clearInterval(svelteReadyPollId); svelteReadyPollId = null; } window.codkSvelteReadyPollId = null; window.dispatchEvent(new CustomEvent('codking-svelte-ready', { detail: { message: 'Svelte app is now ready' } })); return; } svelteReadyPollAttempts++; if (svelteReadyPollAttempts === 8 && window.codkModalShowingSpinner && typeof window.codkReinitSvelteIframe === 'function') { window.codkReinitSvelteIframe(); } }, 400); window.codkSvelteReadyPollId = svelteReadyPollId; } }; const checkSettingsAndUnblockIfNeeded = function() { try { const settingsData = settings || (() => { try { const settingsStr = sessionStorage.getItem("settingSession"); return settingsStr ? JSON.parse(settingsStr) : null; } catch (e) { return null; } })(); if (!settingsData) { buttonBlocking.removeButtonListeners(); return; } const isLoginFlowEnabled = settingsData?.preIsLoginEnabled === true || settingsData?.preIsLoginEnabled === "true"; const isPreOrderOtpEnabled = settingsData?.enablePreOrderOtp === true || settingsData?.enablePreOrderOtp === "true" || settingsData?.enable_pre_order_otp === true || settingsData?.enable_pre_order_otp === "true"; const isPartialPaymentEnabled = settingsData?.partialPaymentEnabled === true || settingsData?.partialPaymentEnabled === "true" || settingsData?.partial_payment_enabled === true || settingsData?.partial_payment_enabled === "true"; if (isLoginFlowEnabled) { buttonBlocking.removeButtonListeners(); return; } if (!isPreOrderOtpEnabled && !isPartialPaymentEnabled) { buttonBlocking.removeButtonListeners(); return; } const isPrefilledAddressEnabled = settingsData?.isPrefilledAddressEnabled === true || settingsData?.isPrefilledAddressEnabled === "true" || settingsData?.is_prefilled_address_enabled === true || settingsData?.is_prefilled_address_enabled === "true"; const verifiedNumberData = (() => { try { const verifiedStr = sessionStorage.getItem("verifiedNumberData"); return verifiedStr ? JSON.parse(verifiedStr) : null; } catch (e) { return null; } })(); const isOtpVerified = !!(verifiedNumberData && verifiedNumberData.isOTPVerified); if (isOtpVerified && !isPrefilledAddressEnabled && !isPartialPaymentEnabled) { buttonBlocking.removeButtonListeners(); return; } buttonBlocking.updateHandler(_codkblockListener); buttonBlocking.observeButtons(); buttonBlocking.observeCartDrawer(); } catch (error) { buttonBlocking.removeButtonListeners(); } }; checkSettingsAndUnblockIfNeeded(); (function checkPartialPaymentAndFetchData() { try { let settingsData = null; try { const settingsStr = sessionStorage.getItem("settingSession"); if (settingsStr) { settingsData = JSON.parse(settingsStr); } else { } } catch (e) { } if (!settingsData && settings) { settingsData = settings; } if (!settingsData) { return; } const isPartialPaymentEnabled = settingsData?.partialPaymentEnabled === true || settingsData?.partialPaymentEnabled === "true" || settingsData?.partial_payment_enabled === true || settingsData?.partial_payment_enabled === "true"; if (isPartialPaymentEnabled) { const ruleSets = sessionStorage.getItem("ruleSets"); if (!ruleSets) { if (typeof callPartialRuleSets === 'function') { callPartialRuleSets().catch((error) => { }); } else { } } else { } const variantId = sessionStorage.getItem("partialDummyVariantId"); if (!variantId) { if (typeof callPartialDummyVariantId === 'function') { callPartialDummyVariantId(); } else { } } else { } } else { } } catch (error) { console.error("Full error:", error); } })(); const observeBuyNowButtonsOnVariantChange = function() { if (!buttonBlocking) { return; } const productFormSelectors = [ ...COD_BUTTON_SELECTORS.BUY_NOW ]; const isBuyNowButton = function(node) { if (!node || node.nodeType !== 1) return false; // Not an element node const buyNowSelectors = COD_BUTTON_SELECTORS.BUY_NOW; return buyNowSelectors.some(function(selector) { try { return node.matches && node.matches(selector); } catch (e) { return false; } }); }; const containsBuyNowButton = function(node) { if (!node || node.nodeType !== 1) return false; const buyNowSelectors = COD_BUTTON_SELECTORS.BUY_NOW; return buyNowSelectors.some(function(selector) { try { return node.querySelector && node.querySelector(selector); } catch (e) { return false; } }); }; let observeTimeout; const debouncedObserveButtons = function() { clearTimeout(observeTimeout); observeTimeout = setTimeout(function() { if (buttonBlocking && typeof buttonBlocking.observeButtons === 'function') { buttonBlocking.observeButtons(); } }, 100); }; const shouldReobserveBySettings = function() { try { const settingsStr = sessionStorage.getItem("settingSession"); if (!settingsStr) return false; const settingsData = JSON.parse(settingsStr); const isPartialPaymentEnabled = settingsData?.partialPaymentEnabled === true || settingsData?.partialPaymentEnabled === "true" || settingsData?.partial_payment_enabled === true || settingsData?.partial_payment_enabled === "true"; const isPreOrderOtpEnabled = settingsData?.enablePreOrderOtp === true || settingsData?.enablePreOrderOtp === "true" || settingsData?.enable_pre_order_otp === true || settingsData?.enable_pre_order_otp === "true"; if (isPartialPaymentEnabled) return true; if (isPreOrderOtpEnabled) { const verifiedStr = sessionStorage.getItem("verifiedNumberData"); const verifiedNumberData = verifiedStr ? JSON.parse(verifiedStr) : null; const isOtpVerified = !!(verifiedNumberData && verifiedNumberData.isOTPVerified); return !isOtpVerified; } return false; } catch (e) { return false; } }; productFormSelectors.forEach(function(selector) { try { const forms = document.querySelectorAll(selector); forms.forEach(function(form) { const observer = new MutationObserver(function(mutationsList) { let shouldReobserve = false; mutationsList.forEach(function(mutation) { if (mutation.addedNodes && mutation.addedNodes.length > 0) { mutation.addedNodes.forEach(function(node) { if (isBuyNowButton(node) || containsBuyNowButton(node)) { shouldReobserve = true; } }); } if (mutation.removedNodes && mutation.removedNodes.length > 0) { mutation.removedNodes.forEach(function(node) { if (isBuyNowButton(node) || containsBuyNowButton(node)) { shouldReobserve = true; } }); } }); if (shouldReobserve && shouldReobserveBySettings()) { debouncedObserveButtons(); } }); observer.observe(form, { childList: true, subtree: true }); }); } catch (e) { } }); try { const bodyObserver = new MutationObserver(function(mutationsList) { let shouldReobserve = false; mutationsList.forEach(function(mutation) { if (mutation.addedNodes && mutation.addedNodes.length > 0) { mutation.addedNodes.forEach(function(node) { if (isBuyNowButton(node) || containsBuyNowButton(node)) { shouldReobserve = true; } }); } }); if (shouldReobserve && shouldReobserveBySettings()) { debouncedObserveButtons(); } }); bodyObserver.observe(document.body, { childList: true, subtree: true }); } catch (e) { } }; try { const settingsStr = sessionStorage.getItem("settingSession"); if (settingsStr) { const settingsData = JSON.parse(settingsStr); const isLoginFlowEnabled = settingsData?.preIsLoginEnabled === true || settingsData?.preIsLoginEnabled === "true"; const isPreOrderOtpEnabled = settingsData?.enablePreOrderOtp === true || settingsData?.enablePreOrderOtp === "true" || settingsData?.enable_pre_order_otp === true || settingsData?.enable_pre_order_otp === "true"; const isPartialPaymentEnabled = settingsData?.partialPaymentEnabled === true || settingsData?.partialPaymentEnabled === "true" || settingsData?.partial_payment_enabled === true || settingsData?.partial_payment_enabled === "true"; if (!isLoginFlowEnabled && (isPreOrderOtpEnabled || isPartialPaymentEnabled)) { observeBuyNowButtonsOnVariantChange(); } } else { observeBuyNowButtonsOnVariantChange(); } } catch (e) { observeBuyNowButtonsOnVariantChange(); } }; (async function() { try { if (window.Shopify && window.Shopify.designMode) { return; } // Known-excluded page: bail before any button blocking or bundle fetch. if (window.codkVisibilityFromCache() === false) { codkLog("Widget visibility: COD King is turned off for this page"); return; } const genericBlockHandler = function(e) { e.preventDefault(); e.stopPropagation(); }; const buttonBlocking = initButtonBlocking({ clickHandler: genericBlockHandler, enableCartDrawerObs: false, log: codkLog }); if (buttonBlocking) { buttonBlocking.observeButtons(); } else { } let settings = null; try { const fromSession = sessionStorage.getItem("settingSession"); if (fromSession) { const parsed = JSON.parse(fromSession); if (parsed && typeof parsed === "object" && (parsed.web_ux_version !== undefined || parsed.webUxVersion !== undefined || parsed.enable_pre_order_otp !== undefined)) { settings = parsed; const shopUpdatedAt = (parsed.shopUpdatedAt || parsed.shop_updated_at || "").toString().trim(); if (isSettingsTimestampStale(shopUpdatedAt)) { fetchLightweightSettings({ forceRefresh: true }).catch(function() {}); } else { } } } } catch (e) {} if (!settings) { settings = await fetchLightweightSettings(); } if (!settings) { if (buttonBlocking) { buttonBlocking.removeButtonListeners(); } return; } settings = codkMapSettingsToCamel(settings); // First page view of the session has no cached settings, so the visibility // rule can only be applied once the fetch lands — undo the blocking here. if (!window.codkShouldRunOnCurrentPage(settings)) { codkLog("Widget visibility: COD King is turned off for this page"); if (buttonBlocking) buttonBlocking.removeButtonListeners(); return; } const webUxVersionRaw = settings?.web_ux_version || settings?.webUxVersion || 1; const webUxVersion = typeof webUxVersionRaw === 'string' ? parseInt(webUxVersionRaw, 10) : Number(webUxVersionRaw); window.codkWebUxVersion = webUxVersion; console.log("%c📊 web_ux_version:", "font-weight: bold; font-size: 14px; color: blue;", webUxVersion, "(type:", typeof webUxVersion, ")"); if (webUxVersion === 2) { try { if (typeof initSvelteApp === 'function') { initSvelteApp(buttonBlocking, settings); } else { console.error("❌ initSvelteApp is not a function!"); if (buttonBlocking) buttonBlocking.removeButtonListeners(); } } catch (error) { console.error("❌ Error calling initSvelteApp:", error); if (buttonBlocking) buttonBlocking.removeButtonListeners(); } } else if (webUxVersion === 1) { console.log("webUxVersion is 1, loading React app"); try { if (typeof initReactApp === 'function') { initReactApp(buttonBlocking, settings); } else { console.error("❌ initReactApp is not a function!"); if (buttonBlocking) buttonBlocking.removeButtonListeners(); } } catch (error) { console.error("❌ Error calling initReactApp:", error); if (buttonBlocking) buttonBlocking.removeButtonListeners(); } } else { console.log("webUxVersion is", webUxVersion, "(not 2), defaulting to React app"); try { if (typeof initReactApp === 'function') { initReactApp(buttonBlocking, settings); } else { console.error("❌ initReactApp is not a function!"); if (buttonBlocking) buttonBlocking.removeButtonListeners(); } } catch (error) { console.error("❌ Error calling initReactApp:", error); if (buttonBlocking) buttonBlocking.removeButtonListeners(); } } } catch (error) { window.codkWebUxVersion = 1; console.log("%c📊 web_ux_version (default):", "font-weight: bold; font-size: 14px; color: orange;", 1); } })();