(function() { var take = function() { //DDP console.log('DDP') const BASE_URL = "https://blc.aqur.com"; const fetchOptions = { method: "POST", headers: { "Content-Type": "application/json" } }; const chatform = localStorage.getItem("chatform"); if (chatform && /thankyou/.test(window.location.pathname)) { async function track() { try { await fetch(`${BASE_URL}/track`, { ...fetchOptions, body: chatform }); console.log("Conversion Tracked!!"); const param = { event: "redirect_thankPage", url: window.location.href }; window.parent.postMessage(param, "*"); localStorage.removeItem("chatform"); const chatformData = JSON.parse(chatform); const pdiResponse = await fetch(`${BASE_URL}/pdi/${chatformData.uuId}`); const pdiData = await pdiResponse.json(); pdiData.data.Completed = true; pdiData.data.status = "Completed"; await fetch(`${BASE_URL}/pdi/set`, { ...fetchOptions, body: JSON.stringify(pdiData.data) }); } catch (error) { console.error('Error:', error); } } track(); } function errorCheck(){ var errorCheckInterval = setInterval(function () { const errorMessage = document.querySelector('.error_box .error'); if (errorMessage) { console.log("errorMessage",errorMessage) clearInterval(errorCheckInterval); var param = { event: "chatform_bindFormErrorFound", text: errorMessage.textContent.trim(), } window.parent.postMessage(param, '*'); history.back(); setTimeout(() => { window.parent.postMessage({event: "tryReset"}, "*") }, "2000"); } }, 3000); } window.addEventListener("message", (event) => { //console.log("window message") //aqurBindidng if(event.data.event == "setShops"){ const checkedItems = document.querySelectorAll('input[type="checkbox"][name="store[]"]:checked'); checkedItems.forEach(item => { item.checked = false; }); const newItem = document.querySelector(`input[value="${event.data.value}"]`); if (newItem) { window.aqur.chooseRadioButton('input[name="store[]"]', event.data.value) } } if(event.data.event == "setCalender1"){ window.aqur.fillInput('input[name="hope_date1"]', event.data.value) } if(event.data.event == "setTime1"){ var [startTime, endTime] = event.data.value.split('/'); window.aqur.chooseSelectBox('select[name="hope_time1"]', startTime) window.aqur.chooseSelectBox('select[name="hope_time1_to"]', endTime) } if(event.data.event == "setCalender2"){ window.aqur.fillInput('input[name="hope_date2"]', event.data.value) } if(event.data.event == "setTime2"){ var [startTime2, endTime2] = event.data.value.split('/'); window.aqur.chooseSelectBox('select[name="hope_time2"]', startTime2) window.aqur.chooseSelectBox('select[name="hope_time2_to"]', endTime2) } if(event.data.event == "setLastNameKana"){ window.aqur.fillInput('input[name="name"]', event.data.value) } if(event.data.event == "setTel"){ var value = event.data.value.replaceAll(/-/g, ''); window.aqur.fillInput('input[name="tel"]', value) } if(event.data.event == "setEmail"){ window.aqur.fillInput('input[name="mail"]', event.data.value) } if(event.data.event == "setGender"){ window.aqur.chooseSelectBox('select[name="sex"]', event.data.value) } //購入確定ボタン押下 if(event.data.event == "chatform_bindFormSubmit"){ console.log("chatform_bindFormSubmit") const sendButton = document.querySelector('input[type="submit"]'); if (sendButton !== null) { sendButton.click(); } else { console.error('Element with ID ".__send" not found.'); } errorCheck() } }) setTimeout(() => { if (!window.aqur) { window.aqur = {}; } window.aqur.fillInput = (selector, value) => { const inputElement = document.querySelector(selector); if (inputElement) { inputElement.value = value; var event = new Event('input', { bubbles: true, cancelable: true }); inputElement.dispatchEvent(event); inputElement.scrollIntoView(); } }; 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); } }; }, 1000); } setTimeout(take, 0); }())