(function() { window.AqurBaseURL = 'https://pr.aqur.com'; var take = function() { document.addEventListener("DOMContentLoaded", () => { //console.log("DOMContentLoaded") const chatform = localStorage.getItem("chatform") }) window.addEventListener("chatform_initialized", (event) => { //for debug /* var launchBtn = document.createElement("img"); var btnUrl = "https://res.cloudinary.com/dts6mbw86/image/upload/f_auto/v1709101462/aqur/mtg/chatbot_btn_fgz5fl.png" launchBtn.src = btnUrl; launchBtn.classList.add("launchBtn"); launchBtn.classList.add("chatformBtn"); document.body.appendChild(launchBtn); launchBtn.style.position = "fixed"; launchBtn.style.bottom = "61px"; */ createAqurBinding() const href = window.location.href; var FixStLP = [ "mje-scob-fb-lp001-tp4980-0011210", "scob-gsnbr001325", "scob-gsndf001325", "scob-ysabr001325", "scob-ysadf001325", "scob-ydn001325", "scob-fb001325", "scob-sn001325", "scob-line001325", "scob-tw001325", "scob-gsnbr002401", "scob-fb002424", "scob-ysabr0021205", "kad-silkyc-fb-lp002-tp4980-0020205", "kad-scob-fb-lp002-tp4980-0011212" ]; const isMatch = FixStLP.some((keyword) => href.includes(keyword)); if (href.includes("apros") && isMatch) { let counter = 0; const maxExecutions = 20; const interval = 100; const intervalId = setInterval(() => { const chatElms1 = document.querySelectorAll('div[class="chatformBtn"]'); const chatElms2 = document.querySelectorAll('img[class*="chatformBtn"]'); if(chatElms1){ chatElms1.forEach((elm) => { const anchor1 = elm.querySelector("a"); if (anchor1 && anchor1.hasAttribute("href")) { console.log("working") anchor1.removeAttribute("href"); } }); } if(chatElms2){ chatElms2.forEach((elm) => { const anchor2 = elm.closest("a"); if (anchor2 && anchor2.hasAttribute("href")) { anchor2.removeAttribute("href"); } }); } const chatElm = document.querySelectorAll('img[alt="カートに入れる"]'); if(chatElm && href.includes("scob-gsnbr002401")){ chatElm.forEach((elm) => { const anchor = elm.closest("a"); if (anchor && !anchor.classList.contains('chatformBtn')) { if(anchor.hasAttribute("href")){ anchor.removeAttribute("href"); } anchor.classList.add('chatformBtn') } }); } counter++; if (counter >= maxExecutions) { clearInterval(intervalId); } }, interval); } }) 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 = "aprs"; const target = "production"; const mode = "release"; const device = JSON.parse("false".toLowerCase()) ? "mobile" : "pc"; const launch = "auto"; 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', "cddf2ef9-f562-464a-8633-2ebf41c31aca"); 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.228"); 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'); let search = REF.search.slice(1) //console.log(search) 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) => { if (event.target && event.target.closest('.chatformBtn ') || event.target.classList.contains("chatformBtn") || event.target.id == "chatform_widget_cancelbtn" ) { console.log("call click") activateChatformWidget() filterId = event.target.closest(".chatformBtn").dataset.filterid } }); document.dispatchEvent(new CustomEvent("chatform_widget_creation_complete")); }; setTimeout(creationComplete, 0); window.addEventListener("message", (event) => { if (event.data.event == "chatform_gotoCart") { var clickOnAddToCartContentAsset = document.querySelector("#formLPSection .clickOnAddToCartContentAsset"); activateChatformWidget(); clickOnAddToCartContentAsset.click() } if (event.data.event == "chatform_sent") { //activateChatformWidget(); var project = event.data.project; var arr = event.data.project.data var chatform = { pid: project.pid, sid: project.sid, uuId: project.uuId, customId:"conversion" } localStorage.setItem('chatform', JSON.stringify(chatform)); bindFormSubmit() } 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_start") { console.log(event.data.uuId) } 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(window.aqur){ window.aqur.bind(event) } }, false) } setTimeout(take, 0); function createAqurBinding(){ //console.log("AqurBindingCreated") //aqur bind start window.aqur = {} window.aqur.debug = false; 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 == "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 == "password") { window.aqur.setPassword(event.data.value.values[0].value) window.aqur.save("Password", event.data.value.values[0].value) } if (event.data.event == "birthday") { 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 == "gender") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if(item && item.value == "6004b77_1"){ window.aqur.setGender("1") window.aqur.save("Gender", "1") }else if(item && item.value == "6004b77_2"){ window.aqur.setGender("2") window.aqur.save("Gender", "2") } } 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 == "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("CardExpirationHolderName", event.data.value.values[4].value) } } //Binding Method for ECForce window.aqur.setLastName = (value) => { window.aqur.debug && console.log("debug setLastName", value); if(!document.querySelector('[name="order[billing_address_attributes][name02]"]')){ var concat = value +" "+window.aqur.FirstName window.aqur.fillInput('[name="order[billing_address_attributes][name01]"]', concat) }else{ window.aqur.fillInput('[name="order[billing_address_attributes][name01]"]', value) } } window.aqur.setFirstName = (value) => { window.aqur.debug && console.log("debug setFirstName", value); window.aqur.fillInput('[name="order[billing_address_attributes][name02]"]', value) } window.aqur.setLastNameKana = (value) => { window.aqur.debug && console.log("debug setLastNameKana", value); if(!document.querySelector('[name="order[billing_address_attributes][kana02]"]')){ var concat = value +" "+window.aqur.FirstNameKana window.aqur.fillInput('[name="order[billing_address_attributes][kana01]"]', concat) }else{ window.aqur.fillInput('[name="order[billing_address_attributes][kana01]"]', value) } } window.aqur.setFirstNameKana = (value) => { window.aqur.debug && console.log("debug setFirstNameKana", value); window.aqur.fillInput('[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.slice(0,3)) window.aqur.fillInput('[name="order[billing_address_attributes][zip02]"]', value.slice(3)) 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) } window.aqur.setEmail = (value) => { window.aqur.debug && console.log("debug setEmail", value); window.aqur.fillInput('input[name="order[email]"]', value) window.aqur.fillInput('input[name="order[email_confirmation]"]', value) } window.aqur.setPassword = (value) => { window.aqur.debug && console.log("debug setPassword", value); window.aqur.fillInput('input[name="order[customer_attributes][password]"]', value) window.aqur.fillInput('input#confirm_password', value) } window.aqur.setGender = (value) => { window.aqur.debug && console.log("debug setGender", value); window.aqur.chooseSelectBox('[name="order[customer_attributes][sex_id]"]', value) } 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.setPaymentMethodTypeKey = (value) => { window.aqur.debug && console.log("debug setPaymentMethodTypeKey", value); window.aqur.chooseSelectBox('[name="order[payment_attributes][payment_method_id]"]', value) } window.aqur.setCardNumber = (value) => { window.aqur.debug && console.log("debug setCardNumber", value); window.aqur.fillInput('[name="order[payment_attributes][source_attributes][number]"]', value) } window.aqur.setCardHolderName = (value) => { window.aqur.debug && console.log("debug setCardHolderName", value); window.aqur.fillInput('[name="order[payment_attributes][source_attributes][name]"]', value) } window.aqur.setCardCvc = (value) => { window.aqur.debug && console.log("debug setCardCvc", value); window.aqur.fillInput('[name="cvv"]', value) } window.aqur.setCardExpirationYear = (value) => { window.aqur.debug && console.log("debug setCardExpirationYear", value); window.aqur.chooseSelectBox('[name="order[payment_attributes][source_attributes][year]"]', value) } window.aqur.setCardExpirationMonth = (value) => { window.aqur.debug && console.log("debug setCardExpirationMonth", value); window.aqur.chooseSelectBox('[name="order[payment_attributes][source_attributes][month]"]', value.replace(/^0/, '')) } //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(", "); } //You can add more helper here (they shold be in window.aqur.xxx) 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) => { let inputEvent = new KeyboardEvent('keydown', { key: 'Enter', code: 'Enter', bubbles: true, cancelable: true }); const inputElement = document.querySelector(selector); if (inputElement) { inputElement.value = value; inputElement.dispatchEvent(inputEvent); } }; window.aqur.chooseRadioButton = (radioSelector, value) => { const radioButton = document.querySelector(`${radioSelector}[value='${value}']`); if (radioButton) { radioButton.checked = true; let event = new Event('change', { bubbles: true, composed: true }) radioButton.dispatchEvent(event); } }; 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.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); } }; //aqur bind finish } function bindFormSubmit(){ const Agreement = document.querySelector('input[name="agree"]').checked; if (!Agreement) { document.querySelector('input[name="agree"]').click() } //Submit if (document.querySelector('input.submit_button_complete_ec') !== null) { console.log("pc click") document.querySelector('input.submit_button_complete_ec').click() setTimeout(() => { document.querySelector('input.submit_button_complete_ec').click() }, 1000); } else { console.log("sp click") location.href = "#order_billing_address_attributes_name1" document.querySelector('input.submit_button_complete_sp_ec').click() setTimeout(() => { document.querySelector('input.submit_button_complete_sp_ec').click() }, 1000); } if(localStorage.getItem("chatform")){ setTimeout(() => { const target = document.querySelector('.chatform_widget'); var param={ event: "chatform_BeforeSubmit", } target.contentWindow.postMessage(param, "*"); 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"); } }, 3000); } } }())