(function () { var take = function () { console.log("Aqur - chatform - KSS") window.AqurBaseURL = 'https://pr.aqur.com'; window.addEventListener("chatform_initialized", async (event) => { var ptag = document.createElement('p'); var launchLink = document.createElement("a"); var launchBtn = document.createElement("img"); // ボタン画像URL var btnUrl = "https://res.cloudinary.com/dts6mbw86/image/upload/v1757985035/aqur/kss/btn_bot_scalp_s_vvtpzz.png"; launchBtn.src = btnUrl; launchBtn.style.width = "100%"; launchBtn.style.display = "block"; ptag.classList.add("aqurBtn"); launchLink.appendChild(launchBtn); ptag.appendChild(launchLink); document.body.appendChild(ptag); // Add the p tag to body instead // 右下に固定配置 ptag.style.position = "fixed"; ptag.style.bottom = "20px"; // 1px → 20px にして見やすく ptag.style.right = "20px"; // 1px → 20px ptag.style.zIndex = "9999999"; ptag.style.display = "block"; ptag.style.margin = "0"; // Remove default p tag margin // レスポンシブ対応 if (window.innerWidth <= 768) { ptag.style.width = "95%"; ptag.style.transform = "translateX(-50%)"; ptag.style.right = "auto"; } else { ptag.style.width = "35%"; } // CSSアニメーションを追加(上下 shake) var style = document.createElement("style"); style.innerHTML = ` @keyframes shakeY { 0% { transform: translateY(0); } 25% { transform: translateY(-4px); } 50% { transform: translateY(4px); } 75% { transform: translateY(-4px); } 100% { transform: translateY(0); } } .aqurBtn { animation: shakeY 2.7s infinite; animation-timing-function: ease-in-out; } `; document.head.appendChild(style); localStorage.removeItem("chatform-kss"); localStorage.removeItem("redirected-cc-kss"); // aqurBtn*, そしてクラスに aqurBtn4 を含む要素内の を対象にする function replaceHref() { document.querySelectorAll('.aqurBtn a, .aqurBtn3 a').forEach(aTag => { const hrefValue = aTag.getAttribute("href"); if (hrefValue) { aTag.removeAttribute("href"); aTag.setAttribute("data-link", hrefValue); } }); } // 500msごとに処理を実行 const aqurTimer = setInterval(replaceHref, 500); // 3秒後に止める setTimeout(() => clearInterval(aqurTimer), 3000); const chatWidget = document.querySelector('.chatform_widget'); document.addEventListener('click', (e) => { const aTag = e.target.closest('a'); if (!aTag) return; // aタグの親または祖先に aqurBtn* を持つ要素を探す const container = aTag.closest('[class*="aqurBtn"]'); if (!container) return; console.log("Aqur - container", container) // classListから aqurBtn* を抽出 const aqurClass = Array.from(container.classList) .find(c => c.startsWith('aqurBtn')); if (aqurClass) { const param = { type: "chatform_shareParams", btnClass: aqurClass }; window.aqur.btnClass = aqurClass let cardLink = "" if (aqurClass === "aqurBtn") { console.log("Aqurbtn - Normal") cardLink = "https://www.kokorokarada.net/so/checkout/add_to_cart?item[60051][mode]=periodical&item[60051][qty]=1" } else if (aqurClass == "aqurBtn3") { console.log("Aqurbtn3 - Normal") cardLink = "https://www.kokorokarada.net/so/checkout/add_to_cart?item[80004][mode]=periodical&item[80004][qty]=1" } createVframe(cardLink, aqurClass); window.aqur.vframe = vframe; if (chatWidget && chatWidget.contentWindow) { chatWidget.contentWindow.postMessage(param, "*"); activateChatformWidget() } else { console.warn("chatform_widget が見つかりませんでした", param); } } }); createAqurBinding() }) async function removeOtherItemsFromCart(selectedAqurClass, vframe) { const chatWidget = document.querySelector('.chatform_widget'); var param = { event: "setLoading", loadingStatus: true } chatWidget.contentWindow.postMessage(param, "*"); setTimeout(async () => { try { const iframe = document.getElementById('vframe'); if (!iframe || !iframe.contentWindow) { console.log("Aqur - iframe not available for item removal"); return; } const iframeDoc = iframe.contentWindow.document; // Define the item IDs for each aqur class (normal and upsell) const normalItemIds = { "aqurBtn": "60051", "aqurBtn3": "80004", }; const upsellItemIds = { "aqurBtn": "60054", "aqurBtn3": "80024" }; // Check if this is an upsell scenario const isUpsell = window.aqur && window.aqur.upsell === "2"; const selectedItemId = isUpsell ? upsellItemIds[selectedAqurClass] : normalItemIds[selectedAqurClass]; if (!selectedItemId) { console.log("Aqur - Unknown aqur class:", selectedAqurClass); return; } // Find all item delete buttons except for the selected item const allItemBoxes = iframeDoc.querySelectorAll('.item_box'); let removedCount = 0; allItemBoxes.forEach((itemBox, index) => { const itemModeInput = itemBox.querySelector('input[name*="[mode]"]'); if (itemModeInput) { const itemId = itemModeInput.name.match(/item\[(\d+)\]/); if (itemId && itemId[1] !== selectedItemId) { const deleteButton = itemBox.querySelector('.item_delete'); if (deleteButton) { deleteButton.click(); removedCount++; } } else if (itemId && itemId[1] === selectedItemId) { console.log(`Aqur - ${isUpsell ? 'Upsell' : 'Normal'}: Keeping item ${itemId[1]} (matches selected item)`); } } }); if (removedCount > 0) { console.log(`Aqur - ${isUpsell ? 'Upsell' : 'Normal'}: Removed ${removedCount} other items from cart, keeping item ${selectedItemId}`); } else { console.log(`Aqur - ${isUpsell ? 'Upsell' : 'Normal'}: No other items found to remove from cart`); var param2 = { event: "setLoading", loadingStatus: false } chatWidget.contentWindow.postMessage(param2, "*"); } } catch (error) { console.error("Aqur - Error removing items from cart:", error); } }, 1000); // Wait 1 second for the page to load // Also try again after a longer delay in case the page takes longer to load setTimeout(() => { try { const iframe = document.getElementById('vframe'); if (!iframe || !iframe.contentWindow) { return; } const iframeDoc = iframe.contentWindow.document; // Use the same logic as the main function const normalItemIds = { "aqurBtn": "60051", "aqurBtn3": "80004" }; const upsellItemIds = { "aqurBtn": "60054", "aqurBtn3": "80024" }; // Check if this is an upsell scenario const isUpsell = window.aqur && window.aqur.upsell === "2"; const selectedItemId = isUpsell ? upsellItemIds[selectedAqurClass] : normalItemIds[selectedAqurClass]; if (!selectedItemId) { console.log("Aqur - Fallback: Unknown aqur class:", selectedAqurClass); return; } console.log(`Aqur - Fallback: ${isUpsell ? 'Upsell' : 'Normal'} mode, keeping item ${selectedItemId}`); // Try alternative selectors in case the structure is different const alternativeSelectors = [ '.item_delete' ]; let foundItems = false; alternativeSelectors.forEach(selector => { const deleteButtons = iframeDoc.querySelectorAll(selector); deleteButtons.forEach(button => { const itemBox = button.closest('.item_box') || button.closest('[class*="item"]'); if (itemBox) { const itemModeInput = itemBox.querySelector('input[name*="[mode]"]'); if (itemModeInput) { const itemId = itemModeInput.name.match(/item\[(\d+)\]/); if (itemId && itemId[1] !== selectedItemId) { console.log(`Aqur - Fallback: ${isUpsell ? 'Upsell' : 'Normal'}: Removing item ${itemId[1]} from cart, keeping ${selectedItemId}`); button.click(); foundItems = true; } else if (itemId && itemId[1] === selectedItemId) { console.log(`Aqur - Fallback: ${isUpsell ? 'Upsell' : 'Normal'}: Keeping item ${itemId[1]} (matches selected item)`); } } } }); }); if (foundItems) { console.log("Aqur - Fallback removal completed"); } } catch (error) { console.error("Aqur - Error in fallback item removal:", error); } }, 3000); // Try again after 3 seconds setTimeout(() => { if (window.aqur && window.aqur.reset) { console.log("Aqur - Calling reset after iframe load"); // if (/\/scalp2\/index_bot250801.html/.test(window.location.pathname)) { if(window.location.pathname.includes("scalp2")) { window.aqur.reset() } } }, 5000); } function createVframe(linkUrl, aqurClass) { // if (/\/scalp2\/index_bot250801.html/.test(window.location.pathname)) { console.log("Create Vframe called!", linkUrl, aqurClass) var param = { event: "setLoading", loadingStatus: true } const chatWidget = document.querySelector('.chatform_widget'); chatWidget.contentWindow.postMessage(param, "*"); var url = new URL(window.location.href); console.log(url) let userChatbot = url.searchParams.get('usechatbot') console.log(userChatbot) if (userChatbot) { return } // Create the URL with parameters var REF = new URL(linkUrl); REF.searchParams.append('chatbot', 1); REF.searchParams.append('usechatbot', "no"); REF.searchParams.append('chatbottype', "aqur"); // Remove existing vframe if it exists and has a different URL const existingVframe = document.getElementById('vframe'); if (existingVframe) { if (existingVframe.src !== REF.href) { existingVframe.remove(); } else { // If URL is the same, return early without creating a new iframe var param3 = { event: "setLoading", loadingStatus: false } chatWidget.contentWindow.postMessage(param3, "*"); return; } } // Create new iframe vframe = document.createElement("iframe"); vframe.id = "vframe"; vframe.sandbox.add('allow-storage-access-by-user-activation'); vframe.sandbox.add('allow-forms'); vframe.sandbox.add('allow-top-navigation'); vframe.sandbox.add('allow-scripts'); vframe.sandbox.add('allow-same-origin'); vframe.sandbox.add('allow-modals') vframe.width = "1px"; vframe.height = "1px"; vframe.src = REF; document.body.appendChild(vframe); let vfmode = url.searchParams.get('vfmode') vframe.addEventListener("load", (e) => { try { var url = new URL(vframe.contentWindow.location.href); console.log("vframe loaded:", url.href); // Remove quantity error message if it exists setTimeout(() => { try { const errorElement = vframe.contentWindow.document.querySelector('.alert-danger p'); if (errorElement && errorElement.innerText && errorElement.innerText.includes('指定の数量では購入できません')) { console.log("Aqur - Removing quantity error message"); errorElement.textContent = ''; } } catch (error) { console.log("Aqur - Could not access iframe content to remove error message:", error.message); } }, 1000); if (vfmode != "debug") { vframe.width = "1px"; vframe.height = "1px"; } var insertDDP = () => { // Check if DDP script already exists const existingScript = vframe.contentWindow.document.querySelector(`script[src*="/kss/client/ddp"]`); if (!existingScript) { var script = vframe.contentWindow.document.createElement('script'); script.src = `${window.AqurBaseURL}/kss/client/ddp`; console.log("Aqur -ddp inserted") vframe.contentWindow.document.head.appendChild(script); } else { console.log("Aqur -ddp script already exists") } } const target = document.querySelector('.chatform_widget'); if (target) { var param = { event: "chatform_vframeLoaded", url: url.href } target.contentWindow.postMessage(param, "*"); } switch (url.origin) { default: insertDDP() // Remove other items from cart after adding the selected item // For upsell, wait a bit longer for the upsell item to be added const isUpsell = window.aqur && window.aqur.upsell === "2"; const delay = isUpsell ? 3000 : 1000; // Wait longer for upsell setTimeout(() => { removeOtherItemsFromCart(aqurClass, vframe) }, delay); } } catch (error) { if (error instanceof DOMException && error.name === 'SecurityError' && location.href != "localhost:8080") { const target = document.querySelector('.chatform_widget'); var param = { event: "page_transition", totalProcess: 4, pageIndex: 2 } target.contentWindow.postMessage(param, "*"); console.log("Aqur -クロスオリジンアクセスエラーが発生しました:", error.message); setTimeout(() => { vframe.width = "100%"; vframe.height = "100%"; vframe.style.display = "block"; vframe.style.zIndex = 9999999999; vframe.style.position = "fixed"; vframe.style.backgroundColor = "white"; vframe.style.top = 0; vframe.style.left = 0; vframe.style.border = "none"; }, 3000); return; } throw error; } }) if (vfmode == "debug") { vframe.classList.add('debug'); vframe.scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" }); if (device == "mobile") { vframe.height = "50%" } const target = document.querySelector('.chatform_widget'); if (target) { target.style.height = "50%"; // 高さを50%に設定 } var param = { event: "chatform_vframe_debug" } vframe.contentWindow.postMessage(param, "*"); } } // } function render(template, data) { return template.replace(/{{(.*?)}}/g, (match) => { return data[match.split(/{{|}}/).filter(Boolean)[0].trim()] }) } function activateChatformWidget() { if (!chatform_initialized) { console.log("Aqur -Aqur is not ready") return } const w = document.querySelector('.chatform_widget'); w.classList.toggle("close"); if (w.classList.contains("close")) { document.body.classList.remove("chat_open"); } else { document.body.classList.add("chat_open"); } } var chatform_initialized = false const pid = "kss"; const target = "production"; const mode = "release"; const device = JSON.parse("false".toLowerCase()) ? "mobile" : "pc"; var launch = "click"; const client = "https://form.aqur.com/"; let REF = new URL(window.location); let userChatbot = REF.searchParams.get('usechatbot') if (userChatbot == "no") { console.log("Aqur -no chatbot") return } REF.searchParams.append('pid', pid); REF.searchParams.append('mode', mode); REF.searchParams.append('target', target); REF.searchParams.append('hash', "a3e90f46-1ba5-4f8d-a689-cc7a97edc865"); REF.searchParams.append('browser', "undefined"); REF.searchParams.append('device', device); REF.searchParams.append('os', "undefined"); REF.searchParams.append('ua', "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)"); REF.searchParams.append('ip', "216.73.216.107"); REF.searchParams.append('ref', REF.href); REF.searchParams.append('path', REF.pathname); //for UI REF.searchParams.append('CLIENT_ID', 'PR'); REF.searchParams.append('BASE_URL', 'https://pr.aqur.com'); REF.searchParams.append('HEADER_LABEL', ''); REF.searchParams.append('HEADER_BG_COLOR', '#fff'); REF.searchParams.append('HEADER_LABEL_COLOR', '#fff'); REF.searchParams.append('SHOW_TIMER', 'false'); REF.searchParams.append('ICON_PATH', 'https://res.cloudinary.com/dts6mbw86/image/upload/v1713319985/aqur/common/icon_azvikf.png'); const params = new URLSearchParams(REF.search.slice(1)); let search = REF.search.slice(1) //console.log(search) launch = params.get('launch'); let widget = render( '' + '', { device: device, client: client, search: (search) ? "&" + search : "", } ); let creationComplete = function () { const body = document.body; if (body) { var filterid; const chatbotProgressBar = "
" body.insertAdjacentHTML('beforeend', chatbotProgressBar); body.classList.add(device) body.insertAdjacentHTML('beforeend', widget); const target = document.querySelector('.chatform_widget'); const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { if (!target.classList.contains("close")) { var contentWindow = target.contentWindow; if (contentWindow) { contentWindow.postMessage("chat_open", "*"); contentWindow.postMessage( { type: "filterIdChanged", data: filterid }, "*"); } } }); }); const config = { characterData: true, attributes: true, subtree: true }; observer.observe(target, config); } if (device == "pc") { var resize = () => { let zoom_level = window.devicePixelRatio || window.screen.availWidth / document.documentElement.clientWidth * 100; const targets = document.querySelectorAll('body,.chatform_widget'); if (zoom_level >= 3) { targets[0].classList.add("mobile") targets[0].classList.remove("pc") targets[1].classList.add("mobile") targets[1].classList.remove("pc") } else { targets[0].classList.add("pc") targets[0].classList.remove("mobile") targets[1].classList.add("pc") targets[1].classList.remove("mobile") } } resize() window.addEventListener("resize", () => { resize() }) } document.addEventListener('click', (event) => { if (event.target && event.target.closest('.chatformBtn') || event.target.classList.contains("chatformBtn") || event.target.closest('.bot_open') || event.target.classList.contains("bot_open") || event.target.id == "chatform_widget_cancelbtn" ) { activateChatformWidget() } }); document.dispatchEvent(new CustomEvent("chatform_widget_creation_complete")); }; // 重複実行防止フラグ let creationCompleteExecuted = false; // 安全なcreationComplete実行関数 const safeCreationComplete = function() { if (creationCompleteExecuted) { return; // 既に実行済みの場合は何もしない } creationCompleteExecuted = true; creationComplete(); }; // DOMContentLoadedイベントでcreationCompleteを実行 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', safeCreationComplete); } else { safeCreationComplete(); } // 30秒後に実行されていない場合は強制実行 setTimeout(() => { if (!creationCompleteExecuted) { console.log('creationCompleteが30秒以内に実行されませんでした。強制実行します。'); safeCreationComplete(); } }, 30000); window.addEventListener("message", async (event) => { if (event.data.event == "chatform_close") { activateChatformWidget(); } if (event.data.event == "chatform_evalScript") { window.eval(event.data.script) } if (event.data.event == "chatform_insertTag") { body.insertAdjacentHTML("beforeend", event.data.tag); event.data.scripts.forEach((item) => { eval(item.textContent) }) } if (event.data.event == "chatform_initialized") { console.log("Aqur - Initialized") document.getElementById("chatbotProgressBar").style.width = "100%"; var opacity = function () { document.getElementById("chatbotProgressBar").style.opacity = "0"; }; setTimeout(opacity, 1000); chatform_initialized = true; if (launch == "auto") { activateChatformWidget(); } window.dispatchEvent(new CustomEvent("chatform_initialized")); } if (event.data.event == "chatform_bindFormErrorFound") { console.log("chatform_bindFormErrorFound", event.data.text) setTimeout(() => { window.aqur.reset() }, 1000) const target = document.querySelector('.chatform_widget'); var param = { event: "chatform_bindFormErrorFound", text: event.data.text } target.contentWindow.postMessage(param, "*"); } if (event.data.event == "redirect_thankPage") { //console.log("redirect_chatform", event.data.event) const target = document.querySelector('.chatform_widget'); var param = { event: "chatform_clear", text: event.data.text } target.contentWindow.postMessage(param, "*"); let redirect = function () { window.location.href = "https://www.kokorokarada.net/orderthanks.html" } setTimeout(redirect, 1000); } if (event.data.event == "amazonButton") { document.querySelector('#AmazonPayCv2Button').click() var setAmzaonSubmit = () => { document.querySelector('#AmazonPayCv2Button').click() } setTimeout(setAmzaonSubmit, 1000); activateChatformWidget() } if (window.aqur) { window.aqur.bind(event) } }, false) function createAqurBinding() { console.log("Aqur -AqurBindingCreated") //aqur bind start if (!window.aqur) { window.aqur = {} } window.aqur.debug = false; // false -> to change, true for debug mode window.aqur.save = (key, value) => { window.aqur[key] = value; // You can access data anytime using window.aqur.XXX } window.aqur.reset = () => { if (!window.aqur.vframe.contentWindow) { window.aqur.vframe = document.querySelector('#vframe') } window.aqur.setLastName(window.aqur.LastName) window.aqur.setFirstName(window.aqur.FirstName) window.aqur.setLastNameKana(window.aqur.LastNameKana) window.aqur.setFirstNameKana(window.aqur.FirstNameKana) window.aqur.setTel(window.aqur.Tel) window.aqur.setPostalCode(window.aqur.PostalCode) window.aqur.setPref(window.aqur.Pref) window.aqur.setCity(window.aqur.City) window.aqur.setStreet(window.aqur.Street) window.aqur.setBuilding(window.aqur.Building) window.aqur.setGender(window.aqur.Gender) window.aqur.setBirthdayYear(window.aqur.Year) setTimeout(() => { window.aqur.setBirthdayMonth(window.aqur.Month) }, 500) setTimeout(() => { window.aqur.setBirthdayDay(window.aqur.Day) }, 500) window.aqur.setEmail(window.aqur.Email) window.aqur.setPassword(window.aqur.Password) window.aqur.setPaymentMethod(window.aqur.Payment) setTimeout(() => { window.aqur.setCardNumber(window.aqur.CardNumber) window.aqur.setCardExpirationYear(window.aqur.CardExpirationYear) window.aqur.setCardExpirationMonth(window.aqur.CardExpirationMonth) window.aqur.setCardCvc(window.aqur.CardExpirationCvc) window.aqur.setCardHolderName(window.aqur.CardHolderName) }, 3500) if (window.aqur.upsell) { let cardLink = "" if (window.aqur.upsell == "2") { if (window.aqur.btnClass === "aqurBtn") { console.log("Aqurbtn - Upsell") cardLink = "https://www.kokorokarada.net/so/checkout/add_to_cart?item[60054][mode]=periodical&item[60054][qty]=1" } else if (window.aqur.btnClass == "aqurBtn3") { console.log("Aqurbtn3 - Upsell") cardLink = "https://www.kokorokarada.net/so/checkout/add_to_cart?item[80024][mode]=periodical&item[80024][qty]=1" } } else { if (window.aqur.btnClass === "aqurBtn") { console.log("Aqurbtn - Normal") cardLink = "https://www.kokorokarada.net/so/checkout/add_to_cart?item[60051][mode]=periodical&item[60051][qty]=1" } else if (window.aqur.btnClass == "aqurBtn3") { console.log("Aqurbtn3 - Normal") cardLink = "https://www.kokorokarada.net/so/checkout/add_to_cart?item[80004][mode]=periodical&item[80004][qty]=1" } } createVframe(cardLink, window.aqur.btnClass); } setTimeout(() => { var param2 = { event: "setLoading", loadingStatus: false } const chatWidget = document.querySelector('.chatform_widget'); chatWidget.contentWindow.postMessage(param2, "*"); }, 3000) } window.aqur.bind = (event) => { // console.log("BIND => ", event.data.event) if (event.data.track) { var track = { pid: event.data.track.pid, sid: event.data.track.sid, uuId: event.data.track.uuId, customId: "conversion" } window.aqur.setTrack(track); window.aqur.save("Track", track); } if (event.data.event == "name") { var FullName = event.data.value.values[0].value + event.data.value.values[1].value + event.data.value.values[2].value + event.data.value.values[3].value if (FullName != window.aqur.FullName) { window.aqur.setLastName(event.data.value.values[0].value) window.aqur.setFirstName(event.data.value.values[1].value) window.aqur.setLastNameKana(event.data.value.values[2].value) window.aqur.setFirstNameKana(event.data.value.values[3].value) window.aqur.save("LastName", event.data.value.values[0].value) window.aqur.save("FirstName", event.data.value.values[1].value) window.aqur.save("LastNameKana", event.data.value.values[2].value) window.aqur.save("FirstNameKana", event.data.value.values[3].value) window.aqur.save("FullName", event.data.value.values[0].value + event.data.value.values[1].value + event.data.value.values[2].value + event.data.value.values[3].value ) } } if (event.data.event == "address") { var FullAddress = event.data.value.values[0].value + event.data.value.values[1].value + event.data.value.values[2].value + event.data.value.values[3].value + event.data.value.values[4].value; if (FullAddress != window.aqur.FullAddress) { window.aqur.setPostalCode(event.data.value.values[0].value) window.aqur.setPref(event.data.value.values[1].value) window.aqur.setCity(event.data.value.values[2].value) window.aqur.setStreet(event.data.value.values[3].value) window.aqur.setBuilding(event.data.value.values[4].value) window.aqur.save("PostalCode", event.data.value.values[0].value) window.aqur.save("Pref", event.data.value.values[1].value) window.aqur.save("City", event.data.value.values[2].value) window.aqur.save("Street", event.data.value.values[3].value.replace(/[−ー―‐-〜]/g, '-')) window.aqur.save("Building", event.data.value.values[4].value.replace(/[−ー―‐-〜]/g, '-')) window.aqur.save("FullAddress", event.data.value.values[0].value + event.data.value.values[1].value + event.data.value.values[2].value + event.data.value.values[3].value + event.data.value.values[4].value ) } } if (event.data.event == "tel") { window.aqur.setTel(event.data.value.values[0].value) window.aqur.save("Tel", event.data.value.values[0].value) } if (event.data.event == "email") { window.aqur.setEmail(event.data.value.values[0].value) window.aqur.save("Email", event.data.value.values[0].value) } if (event.data.event == "gender") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if (item) { window.aqur.setGender(item.value) window.aqur.save("Gender", item.value) } } if (event.data.event == "birthday") { if (event.data.value.values[0].value && event.data.value.values[1].value && event.data.value.values[2].value) { window.aqur.setBirthdayYear(Number(event.data.value.values[0].value)) window.aqur.setBirthdayMonth(Number(event.data.value.values[1].value)) window.aqur.setBirthdayDay(Number(event.data.value.values[2].value)) window.aqur.save("Year", Number(event.data.value.values[0].value)) window.aqur.save("Month", Number(event.data.value.values[1].value)) window.aqur.save("Day", Number(event.data.value.values[2].value)) } } if (event.data.event == "SelOtherDeli") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if (item) { window.aqur.setSelOtherDeli(item.value) window.aqur.save("SelOtherDeli", item.value) } } if (event.data.event == "otherDeli") { var FullAddress = event.data.value.values[0].value + event.data.value.values[1].value + event.data.value.values[2].value + event.data.value.values[3].value + event.data.value.values[4].value; if (FullAddress != window.aqur.OtherFullAddress) { window.aqur.setOtherPostalCode(event.data.value.values[0].value) window.aqur.setOtherPref(event.data.value.values[1].value) window.aqur.setOtherCity(event.data.value.values[2].value) window.aqur.setOtherStreet(event.data.value.values[3].value) window.aqur.setOtherBuilding(event.data.value.values[4].value) window.aqur.save("OtherPostalCode", event.data.value.values[0].value) window.aqur.save("OtherPref", event.data.value.values[1].value) window.aqur.save("OtherCity", event.data.value.values[2].value) window.aqur.save("OtherStreet", event.data.value.values[3].value.replace(/[−ー―‐-〜]/g, '-')) window.aqur.save("OtherBuilding", event.data.value.values[4].value.replace(/[−ー―‐-〜]/g, '-')) window.aqur.save("OtherFullAddress", event.data.value.values[0].value + event.data.value.values[1].value + event.data.value.values[2].value + event.data.value.values[3].value + event.data.value.values[4].value ) } } if (event.data.event == "password") { window.aqur.setPassword(event.data.value.values[0].value) window.aqur.save("Password", event.data.value.values[0].value) } if (event.data.event == "payment") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if (item) { window.aqur.setPaymentMethod(item.value) window.aqur.save("Payment", item.value) } } if (event.data.event == "cc") { window.aqur.setCardNumber(event.data.value.values[0].value) window.aqur.setCardExpirationYear(event.data.value.values[1].value) window.aqur.setCardExpirationMonth(event.data.value.values[2].value) window.aqur.setCardCvc(event.data.value.values[3].value) window.aqur.setCardHolderName(event.data.value.values[4].value) window.aqur.save("CardNumber", event.data.value.values[0].value) window.aqur.save("CardExpirationYear", event.data.value.values[1].value) window.aqur.save("CardExpirationMonth", event.data.value.values[2].value) window.aqur.save("CardExpirationCvc", event.data.value.values[3].value) window.aqur.save("CardHolderName", event.data.value.values[4].value) } if (event.data.event == "upsell2" || event.data.event == "upsell" || event.data.event == "upsell3" || event.data.event == "upsell4") { var param2 = { event: "setLoading", loadingStatus: true } const chatWidget = document.querySelector('.chatform_widget'); chatWidget.contentWindow.postMessage(param2, "*"); var item = window.aqur.getCheckedOptionSA(event.data.value.options) if (item) { let cardLink = "" if (item.value == "2") { if (window.aqur.btnClass === "aqurBtn") { console.log("Aqurbtn - Upsell") cardLink = "https://www.kokorokarada.net/so/checkout/add_to_cart?item[60054][mode]=periodical&item[60054][qty]=1" } else if (window.aqur.btnClass == "aqurBtn3") { console.log("Aqurbtn3 - Upsell") cardLink = "https://www.kokorokarada.net/so/checkout/add_to_cart?item[80024][mode]=periodical&item[80024][qty]=1" } } else { if (window.aqur.btnClass === "aqurBtn") { console.log("Aqurbtn - Normal") cardLink = "https://www.kokorokarada.net/so/checkout/add_to_cart?item[60051][mode]=periodical&item[60051][qty]=1" } else if (window.aqur.btnClass == "aqurBtn3") { console.log("Aqurbtn3 - Normal") cardLink = "https://www.kokorokarada.net/so/checkout/add_to_cart?item[80004][mode]=periodical&item[80004][qty]=1" } } window.aqur.save("upsell", item.value) createVframe(cardLink, window.aqur.btnClass); } } if (event.data.event == "chatform_sent") { var data = event.data.project; // Check if vframe exists and is ready if (!vframe || !vframe.contentWindow) { console.error("Aqur - vframe not available for submit"); return; } // Validate form data before submission with timeout for credit card fields setTimeout(() => { if (!window.aqur.validateFormData()) { console.log("Aqur - Form validation failed, calling reset and retrying"); window.aqur.reset(); const chatWidget = document.querySelector('.chatform_widget'); var param = { event: "setLoading", loadingStatus: true } chatWidget.contentWindow.postMessage(param, "*"); // Wait for reset to complete, then try to submit again setTimeout(() => { var param = { event: "chatform_bindFormSubmit_kss", isCredit: window.aqur.Payment == "21" } vframe.contentWindow.postMessage(param, "*"); console.log("Aqur - Submit button clicked in iframe after reset"); }, 2500); // Wait 2.5 seconds for reset to complete return; } // Validation passed, proceed with submission console.log("Aqur - Form validation passed, submitting"); var param = { event: "chatform_bindFormSubmit_kss", isCredit: window.aqur.Payment == "21" } vframe.contentWindow.postMessage(param, "*"); console.log("Aqur - Submit button clicked in iframe"); }, 500); // Give fields time to populate } } window.aqur.setTrack = (value) => { window.aqur.debug && console.log("Aqur - debug setTrack"); localStorage.setItem('chatform-kss', JSON.stringify(value)); } window.aqur.setLastName = (value) => { window.aqur.debug && console.log("Aqur -debug setLastName", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setLastName", value: value }, "*"); } } window.aqur.setFirstName = (value) => { window.aqur.debug && console.log("Aqur -debug setFirstName", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setFirstName", value: value }, "*"); } } window.aqur.setLastNameKana = (value) => { window.aqur.debug && console.log("Aqur -debug setLastNameKana", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setLastNameKana", value: value }, "*"); } } window.aqur.setFirstNameKana = (value) => { window.aqur.debug && console.log("Aqur -debug setFirstNameKana", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setFirstNameKana", value: value }, "*"); } } window.aqur.setTel = (value) => { window.aqur.debug && console.log("Aqur -debug setTel", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setTel", value: value }, "*"); } } window.aqur.setGender = (value) => { window.aqur.debug && console.log("Aqur -debug setGender", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setGender", value: value }, "*"); } } window.aqur.setBirthdayYear = (value) => { window.aqur.debug && console.log("debug setBirthdayYear", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setBirthdayYear", value: value }, "*"); } } window.aqur.setBirthdayMonth = (value) => { window.aqur.debug && console.log("debug setBirthdayMonth", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setBirthdayMonth", value: value + "" }, "*"); } } window.aqur.setBirthdayDay = (value) => { window.aqur.debug && console.log("debug setBirthdayDay", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setBirthdayDay", value: value }, "*"); } } window.aqur.setEmail = (value) => { window.aqur.debug && console.log("debug setEmail", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setEmail", value: value }, "*"); } } window.aqur.setPassword = (value) => { window.aqur.debug && console.log("debug setPassword", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setPassword", value: value }, "*"); } } window.aqur.setPostalCode = (value) => { window.aqur.debug && console.log("debug setPostalCode", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setPostalCode", value: value }, "*"); } } window.aqur.setPref = (value) => { window.aqur.debug && console.log("debug setPref", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setPref", value: value }, "*"); } } window.aqur.setCity = (value) => { window.aqur.debug && console.log("debug setCity", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setCity", value: value }, "*"); } } window.aqur.setStreet = (value) => { window.aqur.debug && console.log("debug setStreet", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setStreet", value: value }, "*"); } } window.aqur.setBuilding = (value) => { window.aqur.debug && console.log("debug setBuilding", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setBuilding", value: value }, "*"); } } window.aqur.setPaymentMethod = (value) => { window.aqur.debug && console.log("debug setPaymentMethod", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setPaymentMethod", value: value }, "*"); } } window.aqur.setCardNumber = (value) => { window.aqur.debug && console.log("debug setCardNumber", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setCardNumber", value: value }, "*"); } } window.aqur.setCardHolderName = (value) => { window.aqur.debug && console.log("debug setCardHolderName", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setCardHolderName", value: value }, "*"); } } window.aqur.setCardCvc = (value) => { window.aqur.debug && console.log("debug setCardCvc", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setCardCvc", value: value }, "*"); } } window.aqur.setCardExpirationYear = (value) => { window.aqur.debug && console.log("debug setCardExpirationYear", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setCardExpirationYear", value: value }, "*"); } } window.aqur.setCardExpirationMonth = (value) => { window.aqur.debug && console.log("debug setCardExpirationMonth", value); if (value && window.aqur.vframe) { window.aqur.vframe.contentWindow.postMessage({ event: "setCardExpirationMonth", value: value }, "*"); } } //Helper Method window.aqur.getCheckedOptionSA = (options) => { var rtn = options.find((v) => v.checked) return rtn } window.aqur.getCheckedOptionMA = (options) => { var checkedOptions = options.filter((v) => v.checked); var rtn = checkedOptions.map((v) => v.value); return rtn.join(", "); } // Form validation method - checks actual form elements in iframe window.aqur.validateFormData = () => { window.aqur.debug && console.log("Aqur - Validating form data from actual form elements"); // Check if vframe exists and is accessible if (!window.aqur.vframe || !window.aqur.vframe.contentWindow) { console.error("Aqur - vframe not available for validation"); return false; } try { const iframeDoc = window.aqur.vframe.contentWindow.document; var missingFields = []; // Define form field selectors based on actual DDP selectors const formFields = [ { selector: 'input[name="shipping_address[family_name]"]', label: '姓', required: true }, { selector: 'input[name="shipping_address[first_name]"]', label: '名', required: true }, { selector: 'input[name="shipping_address[family_name_kana]"]', label: '姓(カナ)', required: true }, { selector: 'input[name="shipping_address[first_name_kana]"]', label: '名(カナ)', required: true }, { selector: 'input[name="shipping_address[tel]"]', label: '電話番号', required: true }, { selector: 'input[name="user[email]"]', label: 'メールアドレス', required: true }, { selector: 'input[name="user[email_confirmation]"]', label: 'メールアドレス確認', required: true }, { selector: 'input[name="shipping_address[zip]"]', label: '郵便番号', required: true }, { selector: 'select[name="shipping_address[pref]"]', label: '都道府県', required: true }, { selector: 'input[name="shipping_address[city]"]', label: '市区町村', required: true }, { selector: 'input[name="shipping_address[address]"]', label: '番地', required: true }, { selector: 'input[name="shipping_address[building]"]', label: '建物名', required: false }, { selector: 'input[name="user[sex]"]:checked', label: '性別', required: true }, { selector: 'select[name="user[birthday(1i)]"]', label: '生年', required: true }, { selector: 'select[name="user[birthday(2i)]"]', label: '生月', required: true }, { selector: 'select[name="user[birthday(3i)]"]', label: '生日', required: true }, { selector: 'input[name="user[password]"]', label: 'パスワード', required: true }, { selector: 'input[name="user[password_confirmation]"]', label: 'パスワード確認', required: true }, { selector: 'input[id="payment_method_id2"]:checked, input[id="payment_method_id3"]:checked', label: '支払い方法', required: true } ]; // Check each form field formFields.forEach(field => { try { const element = iframeDoc.querySelector(field.selector); let isEmpty = true; if (element) { if (element.type === 'radio' || element.type === 'checkbox') { // For radio/checkbox, check if any in the group is checked const checkedElement = iframeDoc.querySelector(field.selector); isEmpty = !checkedElement; } else if (element.tagName === 'SELECT') { // For select elements, check if a valid option is selected isEmpty = !element.value || element.value === '' || element.value === '0'; } else { // For text inputs, check if value exists and is not empty isEmpty = !element.value || element.value.trim() === ''; } } if (field.required && isEmpty) { missingFields.push(field.label); window.aqur.debug && console.log(`Aqur - Missing field: ${field.label}`); } } catch (fieldError) { window.aqur.debug && console.log(`Aqur - Error checking field ${field.label}:`, fieldError.message); } }); // Check credit card fields if payment method is credit card try { const paymentElement = iframeDoc.querySelector('input[id="payment_method_id2"]:checked'); if (paymentElement && paymentElement.value == '2') { const ccFields = [ { selector: 'input[name="create_card_service[card_number]"]', label: 'カード番号' }, { selector: 'select[name="create_card_service[card_expire_yy]"]', label: 'カード有効期限(年)' }, { selector: 'select[name="create_card_service[card_expire_mm]"]', label: 'カード有効期限(月)' }, { selector: 'input[name="create_card_service[security_code]"]', label: 'CVC' }, { selector: 'input[name="create_card_service[card_name]"]', label: 'カード名義人' } ]; ccFields.forEach(ccField => { try { const ccElement = iframeDoc.querySelector(ccField.selector); let isEmpty = true; if (ccElement) { if (ccElement.tagName === 'SELECT') { isEmpty = !ccElement.value || ccElement.value === '' || ccElement.value === '0'; } else { isEmpty = !ccElement.value || ccElement.value.trim() === ''; } } if (isEmpty) { missingFields.push(ccField.label); window.aqur.debug && console.log(`Aqur - Missing CC field: ${ccField.label}`); } } catch (ccFieldError) { window.aqur.debug && console.log(`Aqur - Error checking CC field ${ccField.label}:`, ccFieldError.message); } }); } } catch (paymentError) { window.aqur.debug && console.log("Aqur - Error checking payment method:", paymentError.message); } if (missingFields.length > 0) { window.aqur.debug && console.log("Aqur - Form validation failed. Missing fields:", missingFields); return false; } window.aqur.debug && console.log("Aqur - Form validation passed - all fields are bound"); return true; } catch (error) { console.error("Aqur - Error during form validation:", error.message); // If we can't access the iframe, assume validation failed return false; } } //aqur bind finish } } setTimeout(take, 0); }()) function ChatFormWidgetHide() { console.log("ChatFormWidgetHide"); if (localStorage.getItem("chatform-kss")) { // Trigger a general click (if needed) document.body.click(); const widget = document.querySelector('.chatform_widget'); if (!widget || !widget.contentWindow) { console.warn("Chat widget not available."); return; } const param = { event: "chatform_BeforeSubmit" }; widget.contentWindow.postMessage(param, "*"); widget.classList.toggle("close"); if (widget.classList.contains("close")) { document.body.classList.remove("chat_open"); } } } function ScrollFormtoSubmit() { const viewForm = document.querySelector('#ownerName1'); if (!viewForm) { console.warn("#ownerName1 not found on the page."); return; } const isAndroid = /Android/i.test(navigator.userAgent); if (isAndroid) { // Direct hash jump for Android window.location.hash = "#ownerName1"; const viewFormPosition = viewForm.getBoundingClientRect().top + window.pageYOffset - 100; window.scrollTo({ top: viewFormPosition, behavior: 'smooth' }); } else { // Smooth scroll for non-Android devices requestAnimationFrame(() => { viewForm.scrollIntoView({ behavior: 'smooth', block: 'start' }); }); } }