(function() { var take = function() { window.AqurBaseURL = 'https://pr.aqur.com'; window.addEventListener("chatform_initialized", async (event) => { createAqurBinding() }) 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 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 = "gyoku"; 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("no chatbot") return } REF.searchParams.append('pid', pid); REF.searchParams.append('mode', mode); REF.searchParams.append('target', target); REF.searchParams.append('hash', "c9f72d42-65ad-4b2d-8d80-5e7663ae116c"); 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.15"); 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 : "", } ); 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); } let creationComplete = function () { 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) => { const target = event.target; // Handle chat widget activation if ( target.closest('.chatformBtn') || target.classList.contains("chatformBtn") || target.closest('.bot_open') || target.classList.contains("bot_open") || target.id === "chatform_widget_cancelbtn" ) { activateChatformWidget(); } // // Define product button mappings // const buttonMappings = [ // { // alts: ["3袋+2袋無料(送料も無料)で試してみるボタン"], // src: "fixedbanner.png", // btnClass: "aqurBtn1", // label: "product [5袋セット]", // hasBtn: true, // Product: 3 // }, // { // alts: ["2袋+1袋無料で試してみるボタン"], // btnClass: "aqurBtn2", // label: "product [3袋セット]", // hasBtn: true, // Product: 2 // }, // { // alts: ["1袋で試してみるボタン"], // btnClass: "aqurBtn3", // label: "product [単品]", // hasBtn: true, // Product: 1 // } // ]; // // Extract attributes for matching // const altAttr = target.getAttribute("alt") || ""; // const srcAttr = target.getAttribute("src") || ""; // // Try alt-based matching // let matchedMapping = buttonMappings.find(mapping => // mapping.alts.some(alt => altAttr.includes(alt)) // ); // // If no alt match, try src match (only for mappings that define `src`) // if (!matchedMapping && srcAttr) { // matchedMapping = buttonMappings.find(mapping => // mapping.src && srcAttr.includes(mapping.src) // ); // } // if (matchedMapping) { // console.log("chatform_shareLabel", matchedMapping.label); // console.log("chatform_shareParams", matchedMapping.btnClass); // if (matchedMapping.hasBtn) { // const param = { // type: "chatform_shareParams", // btnClass: matchedMapping.btnClass // }; // if (window.aqur?.setProduct) { // window.aqur.setProduct(matchedMapping.Product); // } // const chatWidget = document.querySelector('.chatform_widget'); // if (chatWidget?.contentWindow) { // chatWidget.contentWindow.postMessage(param, "*"); // } else { // console.warn("chatform_widget not found or not loaded."); // } // } // } else { // console.log("No matching alt or src attribute found for product button."); // } }); document.dispatchEvent(new CustomEvent("chatform_widget_creation_complete")); }; setTimeout(creationComplete, 250); 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_sent") { //console.log("chatform_sent") var project = event.data.project; var arr = project.data; var chatform = { pid: project.pid, sid: project.sid, uuId: project.uuId, customId:"conversion" } localStorage.setItem('chatform', JSON.stringify(chatform)); bindandSubmit(arr) } if(window.aqur){ window.aqur.bind(event) } }, false) } setTimeout(take, 0); }()) function createAqurBinding() { console.log("AqurBindingCreated") //aqur bind start 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.bind = (event) => { // console.log("waq",event.data.event) if (event.data.event == "upsell") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if(item){ window.aqur.setProduct(item.value) window.aqur.save("Product", item.value) } } if (event.data.event == "upsell2") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if(item){ window.aqur.setProduct(item.value) window.aqur.save("Product", item.value) } } if (event.data.event == "product") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if(item){ window.aqur.setProduct(item.value) window.aqur.save("Product", item.value) } } if (event.data.event == "name") { 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) } 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", event.data.value.values[0].value) window.aqur.save("Month", event.data.value.values[1].value) window.aqur.save("Day", event.data.value.values[2].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(window.aqur.City){ // window.aqur.setCity(window.aqur.City) // } // } if (event.data.event == "payment") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if (item) { window.aqur.setPaymentMethodTypeKey(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) } } //Binding Method for ECForce window.aqur.setProduct = (value) => { window.aqur.debug && console.log("debug setProduct", value); window.aqur.chooseSelectBox('select#variant_id', value) } //お名前(姓) window.aqur.setLastName = (value) => { window.aqur.debug && console.log("debug setLastName", value); window.aqur.fillInput('input[name="order[billing_address_attributes][name01]"]', value) } //お名前(名) window.aqur.setFirstName = (value) => { window.aqur.debug && console.log("debug setFirstName", value); window.aqur.fillInput('input[name="order[billing_address_attributes][name02]"]', value) } //お名前(姓 kana) window.aqur.setLastNameKana = (value) => { window.aqur.debug && console.log("debug setLastNameKana", value); window.aqur.fillInput('input[name="order[billing_address_attributes][kana01]"]', value) } //お名前(名 kana) window.aqur.setFirstNameKana = (value) => { window.aqur.debug && console.log("debug setFirstNameKana", value); window.aqur.fillInput('input[name="order[billing_address_attributes][kana02]"]', value) } window.aqur.setPostalCode = (value) => { window.aqur.debug && console.log("debug setPostalCode", value); window.aqur.fillInput('[name="order[billing_address_attributes][zip01]"]', value) function callLater() { window.aqur.setCity(window.aqur.City) window.aqur.setStreet(window.aqur.Street) window.aqur.setBuilding(window.aqur.Building) } setTimeout(callLater, 1000); } window.aqur.setPref = (value) => { window.aqur.debug && console.log("debug setPref", value); window.aqur.chooseSelectBoxLabel('select[name="order[billing_address_attributes][prefecture_id]"]', value) } window.aqur.setCity = (value) => { window.aqur.debug && console.log("debug setCity", value); window.aqur.fillInput('input[name="order[billing_address_attributes][addr01]"]', value) } window.aqur.setStreet = (value) => { window.aqur.debug && console.log("debug setStreet", value); if(!document.querySelector('input#order_billing_address_attributes_addr03')){ var concat = value +" "+window.aqur.Building window.aqur.fillInput('input#order_billing_address_attributes_addr02', concat) }else{ window.aqur.fillInput('input#order_billing_address_attributes_addr02', value) } } window.aqur.setBuilding = (value) => { window.aqur.debug && console.log("debug setBuilding", value); window.aqur.fillInput('input#order_billing_address_attributes_addr03', value) } window.aqur.setTel = (value) => { window.aqur.debug && console.log("debug setTel", value); window.aqur.fillInput('input[name="order[billing_address_attributes][tel01]"]', value.replace(/-/g,'')) } window.aqur.setEmail = (value) => { window.aqur.debug && console.log("debug setEmail", value); window.aqur.fillInput('input[name="order[email]"]', value) } window.aqur.setGender = (value) => { window.aqur.debug && console.log("debug setGender", value); const gender = document.querySelector('[name="sex"][value="'+value+'"]') if(gender){ gender.click() } } window.aqur.setBirthdayYear = (value) => { window.aqur.debug && console.log("debug setBirthdayYear", value); window.aqur.chooseSelectBox('select[name="order[customer_attributes][birth(1i)]"]', value) } window.aqur.setBirthdayMonth = (value) => { window.aqur.debug && console.log("debug setBirthdayMonth", value); window.aqur.chooseSelectBox('select[name="order[customer_attributes][birth(2i)]"]', value) } window.aqur.setBirthdayDay = (value) => { window.aqur.debug && console.log("debug setBirthdayDay", value); window.aqur.chooseSelectBox('select[name="order[customer_attributes][birth(3i)]"]', value) } window.aqur.setGender = (value) => { window.aqur.debug && console.log("debug setGender", value); window.aqur.chooseSelectBox('select[name="order[customer_attributes][sex_id]"]', value) } //パスワード // window.aqur.setPassword = (value) => { window.aqur.debug && console.log("debug setPassword", value); // window.aqur.fillInput('input[name="password"]', value) // window.aqur.fillInput('input[name="confirmPassword"]', value) // } //お支払い方法選択 window.aqur.setPaymentMethodTypeKey = (value) => { window.aqur.debug && console.log("debug setPaymentMethodTypeKey", value); window.aqur.chooseSelectBox('select[name="order[payment_attributes][payment_method_id]"]', value) } //クレジットカード番号 window.aqur.setCardNumber = (value) => { window.aqur.debug && console.log("debug setCardNumber", value); window.aqur.fillInput('input[name="order[payment_attributes][source_attributes][number]"]', value) } //クレジットカード名 window.aqur.setCardHolderName = (value) => { window.aqur.debug && console.log("debug setCardHolderName", value); window.aqur.fillInput('input[name="order[payment_attributes][source_attributes][name]"]', value) } //カードの有効期限(年) window.aqur.setCardExpirationYear = (value) => { window.aqur.debug && console.log("debug setCardExpirationYear", value); window.aqur.chooseSelectBox('select[name="order[payment_attributes][source_attributes][year]"]', value) } //カードの有効期限(月) window.aqur.setCardExpirationMonth = (value) => { const cleanedValue = parseInt(value, 10); if (window.aqur.debug) { console.log("debug setCardExpirationMonth", cleanedValue); } window.aqur.chooseSelectBox( 'select[name="order[payment_attributes][source_attributes][month]"]', cleanedValue ); }; window.aqur.setCardCvc = (value) => { window.aqur.debug && console.log("debug setCardCvc", value); window.aqur.fillInput('input[name="cvv"]', value) } //Helper Method window.aqur.convertToHalfWidth = (input) => { if(input){ return input.replace(/[0-9−ー―‐]/g, (match) => { if (/[0-9]/.test(match)) { // 全角数字を半角数字に変換 return String.fromCharCode(match.charCodeAt(0) - 0xFEE0); } else { return '-'; } }); }else{ return ''; } } 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(", "); } window.aqur.waitForElement = (selectors, timeout = 5000) => { return new Promise((resolve, reject) => { const interval = 100; let elapsedTime = 0; const checkExistence = () => { for (const selector of selectors) { const element = document.querySelector(selector); if (element) { resolve(element); return; } } elapsedTime += interval; if (elapsedTime >= timeout) { reject(new Error(`None of the elements with selectors "${selectors.join(', ')}" were found within the timeout`)); } else { setTimeout(checkExistence, interval); } }; checkExistence(); }); }; window.aqur.fillInput = (selector, value) => { const inputElement = document.querySelector(selector); if (inputElement) { let nativeValueSetter = Object.getOwnPropertyDescriptor( window.HTMLInputElement.prototype, "value" ).set; nativeValueSetter.call(inputElement, value); let inputEvent = new Event("input", { bubbles: true }); inputElement.dispatchEvent(inputEvent); } }; window.aqur.chooseSelectBox = (selectBoxSelector, value, useOptionVal = true) => { let option = "" if(useOptionVal) { option = document.querySelector(`${selectBoxSelector} option[value='${value}']`); } else { option = document.querySelector(`${selectBoxSelector} option[label='${value}']`); } const selectElement = document.querySelector(`${selectBoxSelector}`); if (option && selectElement) { option.selected = true; const event = new Event('change', { bubbles: true, composed: true }) selectElement.dispatchEvent(event); } }; window.aqur.chooseSelectVueBox = (selectBoxSelector, value, useOptionVal = true) => { const selectElement = document.querySelector(selectBoxSelector); if (!selectElement) return; let option; if (useOptionVal) { option = selectElement.querySelector(`option[value='${value}']`); } else { option = Array.from(selectElement.options).find(opt => opt.text.trim() === value); } if (option) { // Directly update the select element's value selectElement.value = option.value; // Manually trigger Vue's reactivity update using native property setter let nativeSetter = Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, "value").set; nativeSetter.call(selectElement, option.value); // Dispatch both 'input' and 'change' events to notify Vue selectElement.dispatchEvent(new Event("input", { bubbles: true })); selectElement.dispatchEvent(new Event("change", { bubbles: true })); } }; window.aqur.chooseSelectBoxLabel = (selectBoxSelector, label) => { const selectElement = document.querySelector(selectBoxSelector); var option; if (selectElement) { option = Array.from(selectElement.options).find( opt => opt.textContent.trim() === label ); } if (option) { option.selected = true; const event = new Event('change', { bubbles: true, composed: true }); selectElement.dispatchEvent(event); // selectElement.focus() } }; //aqur bind finish } function bindandSubmit(data) { try { const agreementCheckbox = document.querySelector("input#agree"); if (agreementCheckbox && !agreementCheckbox.checked) { agreementCheckbox.click(); console.log("Agreement checkbox clicked."); } let submitButton = null; if (document.querySelector("input.submit_button_complete_ec")) { submitButton = document.querySelector("input.submit_button_complete_ec"); } else if (document.querySelector("input.submit_button_complete_sp_ec")) { submitButton = document.querySelector("input.submit_button_complete_sp_ec"); } else if (document.querySelector("input.submit_bottom_ec")) { submitButton = document.querySelector("input.submit_bottom_ec"); } else if (document.querySelector("input.submit_bottom_sp_ec")) { submitButton = document.querySelector("input.submit_bottom_sp_ec"); } if (!submitButton) { console.warn("No submit button found."); return; } submitButton.click(); setTimeout(() => { try { submitButton.click(); } catch (err) { console.error("Error during second click:", err); } }, 1000); } catch (error) { console.error("Error in bindandSubmit:", error); } } function ChatFormWidgetHide() { console.log("ChatFormWidgetHide"); if (localStorage.getItem("chatform")) { // 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('#new-view'); if (!viewForm) { console.warn("#new-view not found on the page."); return; } const isAndroid = /Android/i.test(navigator.userAgent); if (isAndroid) { // Direct hash jump for Android window.location.hash = "#new-view"; 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' }); }); } }