(function() { var take = function() { //DDP var url = new URL(window.location.href); document.addEventListener("DOMContentLoaded", () => { //console.log("DOMContentLoaded") let userChatbot = url.searchParams.get('usechatbot') console.log("userChatbot",userChatbot) if(userChatbot=="no"){ const jsFltBnr = document.querySelector(".jsFltBnr"); if(jsFltBnr){ jsFltBnr.style.display="none" } const wvLoading = document.querySelector(".wvLoading"); if(wvLoading){ wvLoading.style.display="none" } } }) const baseUrl = "https://st.aqur.com/track"; const chatform=localStorage.getItem("chatform") console.log("chatform",chatform) if(chatform){ let path = window.location.pathname switch (true) { case /confirm.php/.test(path): console.log("ddp confirm") var confirmExe=()=>{ window.parent.postMessage( { event: "chatform_page_transition", message: "order confrm page", totalProcess: 4, pageIndex: 2 } , "*") var confirmInterval = setInterval(function () { if(document.querySelector('.omatomeBtnSplit li:nth-child(1) a')){ document.querySelector('.omatomeBtnSplit li:nth-child(1) a').click(); }else{ var cnf = document.querySelector(".fltngBnrOuterCNF") if(cnf){ cnf.remove() } var element = document.querySelector(".ordercomp_bt a"); if (element && window.getComputedStyle(element).display !== 'none') { console.log("btnFound") clearInterval(confirmInterval); element.click() console.log("click") } var element2 = document.querySelector(".nx_btn a"); if (element2 && window.getComputedStyle(element2).display !== 'none') { clearInterval(confirmInterval); element2.click() console.log("click2") } } }, 100); } confirmExe() break; case /complete.php/.test(path): console.log("ddp complete") var thanksExe=()=>{ track(baseUrl, chatform) window.parent.postMessage( { event: "chatform_page_transition", message: "order complete page", totalProcess: 4, pageIndex: 3 } , "*") var completeInterval = setInterval(function () { var element = document.querySelector("#completetext p, .shopping_inner p"); if (element && window.getComputedStyle(element).display !== 'none') { console.log("elementFound") clearInterval(completeInterval); completetext = element.innerHTML.trim(); const regex = /[^0-9]/g; const result = completetext.replace(regex, ""); const order_id = parseInt(result); window.parent.postMessage( { event: "chatform_bindFormConversion", order_id:order_id, } , '*'); }else{ const messageArea = document.querySelector('.messagearea'); const searchString = "お届け日を再度設定していただきますようお願い致します。"; if (messageArea && messageArea.innerHTML.includes(searchString)) { clearInterval(completeInterval); const link = messageArea ? messageArea.querySelector('a') : null; if (link) { var param={ event: "chatform_bindFormErrorFound", text:"ご指定の日時で注文を承ることが出来ません。お届け日を再度設定していただきますようお願い致します。
5秒後に自動でこのページは切り替わります。", } window.parent.postMessage(param, '*'); setTimeout(() => { const href = link.getAttribute('href'); var param={ event: "chatform_redirect_url", redirect_url:href, } window.parent.postMessage(param, '*'); }, "5000"); } } const searchString2 = "今回のご注文ではNP後払いをご利用いただけません"; const messageArea2 = document.querySelector('#compbox'); if (messageArea && messageArea.innerHTML.includes(searchString2) || messageArea2 && messageArea2.innerHTML.includes(searchString2)) { var param={ event: "chatform_bindFormErrorFound", text:"今回のご注文ではNP後払いをご利用いただけません", } window.parent.postMessage(param, '*'); clearInterval(completeInterval); } } }, 100); } thanksExe() break; case /notavailable/.test(path): console.log("ddp notavailable") var confirmError=()=>{ var param={ event: "chatform_bindFormErrorFound", text:"申し訳ございませんが、今回のご注文をお受けすることができませんでした。
恐れ入りますが、下記のフリーダイヤルよりご連絡くださいますようお願いいたします。フリーダイヤル:0120-303-958
受付時間 平日10:00~19:00(土日祝休み)", } window.parent.postMessage(param, '*'); } confirmError() break; default: console.log('do nothing'); } }else{ checkErrors() console.log("No Chatform") } window.addEventListener("message", (event) => { //console.log("window message") if(event.data.event == "chatform_vframe_debug"){ //console.log("chatform_vframe_debug") const lpshoppingcolumn = document.querySelector('#lpshoppingcolumn, #smp-lpshoppingcolumn'); lpshoppingcolumn.style.display= "block"; lpshoppingcolumn.scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" }); } if(event.data.event == "chatform_bindForm"){ //console.log("1 chatform_bindForm",event.data.project) var project = event.data.project; var arr = project.data; var chatform = { pid:project.pid, sid:project.sid, uuId:project.uuId, id:arr[arr.length-1].id, itemId:project.itemId } localStorage.setItem('chatform', JSON.stringify(chatform)); bindForm(arr) } if(event.data.event == "chatform_bindFormSubmit"){ //console.log("chatform_bindFormSubmit") bindFormSubmit() } if(event.data.event == "chatform_bindFormUpcell"){ //console.log("chatform_bindFormSubmit") document.getElementById("ups_button").click(); } if(event.data.event == "chatform_redirecURL"){ console.log("chatform_redirecURL") var url = event.data.url; window.location.href = url; } }) function clearChatformStorage(){ //console.log("clearChatformStorage") localStorage.removeItem("chatform"); localStorage.removeItem("chatformAmazonPay"); } function track(baseUrl,trackingData){ fetch(baseUrl, { method:"POST", headers:{ "Content-Type" : "application/json"}, body:trackingData }) .then(response => response.json()) .then(data => { console.log("Conversion Tracked") let param = { event: "chatform_page_transition", message: "order done", totalProcess: 4, pageIndex: 3 } window.parent.postMessage(param, "*") clearChatformStorage() }) } function bindForm(d){ console.log("bindForm__") const lpshoppingcolumn = document.querySelector('#lpshoppingcolumn, #smp-lpshoppingcolumn'); if(lpshoppingcolumn){ lpshoppingcolumn.style.display= "block"; } const wvLoading = document.querySelector('.wvLoading'); if(wvLoading){ wvLoading.style.display= "none"; } const chatform=JSON.parse(localStorage.getItem("chatform")) const pid=chatform.pid; const itemId = chatform.itemId; var bind = ()=>{ const ProductElem = document.getElementById('product_id'); if(itemId){ document.querySelector("#product_id option[value='"+ itemId +"']").selected = true; ProductElem.value = itemId; }else{ var options = ProductElem.querySelectorAll('option'); var nonEmptyOptions = Array.from(options).filter(function(option) { return option.value !== ""; }); if (nonEmptyOptions.length ) { ProductElem.value = nonEmptyOptions[0].value; } } ProductElem.dispatchEvent(new Event('change', { bubbles: true, composed: true })); var noCoupons=[734,322,302,465] if(!noCoupons.includes(itemId)){ //console.log("coupon適用") var couponAccoTtl = document.querySelector('.couponAccoTtl'); if (couponAccoTtl) { couponAccoTtl.click(); } var checkCouponButton = document.getElementById('check_coupon_code'); if (checkCouponButton) { checkCouponButton.click(); } }else{ //console.log("coupon非適用",itemId) var couponAccoTtl = document.querySelector('.couponAccoTtl'); if (couponAccoTtl) { couponAccoTtl.click(); } var coupon_code = document.getElementById('coupon_code'); if(coupon_code){ coupon_code.value="" } var checkCouponButton = document.getElementById('check_coupon_code'); if (checkCouponButton) { checkCouponButton.click(); } var remove_coupon_code = document.querySelector('#remove_coupon_code'); if(remove_coupon_code){ remove_coupon_code.click(); } } const LastName = document.querySelector("#order_name01"); LastName.value = findValue(d,"LastName") const FirstName = document.querySelector("#order_name02"); FirstName.value = findValue(d,"FirstName") const LastNameKana = document.querySelector("#order_kana01"); LastNameKana.value = findValue(d,"LastNameKana") const FirstNameKana = document.querySelector("#order_kana02"); FirstNameKana.value = findValue(d,"FirstNameKana") const Zip = document.querySelector("#order_zip"); Zip.value = findValue(d,"Zip") const inputEvent = new InputEvent('input', { bubbles: true, cancelable: false }); const Tel = document.querySelector("input[name='order_tel']"); Tel.value = findValue(d,"Tel") Tel.dispatchEvent(inputEvent); const sourceString = 'abcdefghijklmnopqrstuvwxyz0123456789'; const randomString = generateRandomString(sourceString, 10); const Email = document.querySelector("#order_email"); Email.value = findValue(d,"Email"); const PASSWORD = document.querySelector("#password"); var passwordValue = findValueByCustomId(d,"password") if(passwordValue !== "Undefind") { PASSWORD.value=passwordValue }else{ PASSWORD.value=randomString } var gender = findOption(d,"gender"); if(gender !== "Undefind") { document.querySelector("input[name='order_sex'][value='"+gender+"']").checked = true; }else{ document.querySelector("input[name='order_sex'][value='"+1+"']").checked = true; } var agreement = 'input[name="agree"]'; const agreementEl = document.querySelector(agreement); agreementEl.checked=true; var yearSelect = document.querySelector('select[name="year"]'); var monthSelect = document.querySelector('select[name="month"]'); var daySelect = document.querySelector('select[name="day"]'); // Function to select an option based on its value function selectOptionByValue(selectElement, value) { var optionToSelect = selectElement.querySelector(`option[value="${value}"]`); if (optionToSelect) { optionToSelect.selected = true; } } // Set the values for year, month, and day let birthday = (d.find((v)=>v.customId=="birthday"))? d.find((v)=>v.customId=="birthday").values : ""; //console.log(birthday) if(birthday && birthday[0].value && birthday[1].value && birthday[2].value ) { selectOptionByValue(yearSelect, birthday[0].value); selectOptionByValue(monthSelect, birthday[1].value); selectOptionByValue(daySelect, birthday[2].value); } else { selectOptionByValue(yearSelect, "1901"); selectOptionByValue(monthSelect, "1"); selectOptionByValue(daySelect, "1"); } waitForElementToDisplay('payment_id', function() { // Need settimeout, if settimeout is not set it will cause error // when user reach submit button and re-change product setTimeout(() => { Zip.dispatchEvent(inputEvent); const ZipButton = document.querySelector("#order_zip_button"); if(ZipButton){ ZipButton.click() } const Building = document.querySelector("#order_addr02"); Building.value = findValue(d,"Street")+" "+findValue(d,"Building") Building.dispatchEvent(inputEvent); Building.blur() var payment = findOptionByCustomId(d, "payment") var payment_value=getPaymentOptionValueByLabel(payment.value) document.querySelector("option[name='payment_id'][value='"+payment_value+"']").selected = true; const Payment = document.querySelector("#payment_id"); Payment.dispatchEvent(new Event('change', { bubbles: true, composed: true })); if(payment.value==0) { var month = findValue(d,"CardExpiryMonth"); var year = findValue(d,"CardExpiryYear"); if(month&&year){ bindText(d, "#gp_paygent_token_card_number", "CardNumber") document.querySelector("#gp_paygent_token_card_expires_month option[value='"+month+"']").selected = true; document.querySelector("#gp_paygent_token_card_expires_year option[value='"+year+"']").selected = true; const Name = findValue(d, "CardHolderName") const CardName = document.querySelector("#gp_paygent_token_card_name"); CardName.value = Name; } } const lpshoppingcolumn = document.querySelector('#lpshoppingcolumn, #smp-lpshoppingcolumn'); lpshoppingcolumn.style.display= "block"; var submit = '#confirm_submit_image'; const submitEl = document.querySelector(submit); //submitEl.scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" }); let param = { event: "chatform_btn_activated" } window.parent.postMessage(param, "*") }, 7000) }) } setTimeout(bind, 0); } function waitForElementToDisplay(elementId, callback) { var checkInterval = setInterval(function () { var element = document.getElementById(elementId); if (element && window.getComputedStyle(element).display !== 'none') { clearInterval(checkInterval); callback(); } }, 100); // Adjust the interval (in milliseconds) as needed } function bindFormSubmit(){ //console.log("bindFormSubmit") var setSubmit = () => { console.log("submitted!") let param = { event: "chatform_page_transition", message: "order start", totalProcess: 4, pageIndex: 1 } window.parent.postMessage(param, "*") const lpshoppingcolumn = document.querySelector('#lpshoppingcolumn, #smp-lpshoppingcolumn'); lpshoppingcolumn.style.display= "block"; document.body.classList.remove("chat_open"); var submit = '#confirm_submit_image'; const submitEl = document.querySelector(submit); submitEl.click() checkErrors() }; setTimeout(setSubmit, 2500); } function checkErrors(){ let count=0 function checkError(a, b) { const lperror = document.querySelector('.lp-error.lp-confirm, .smp-lp-error.smp-lp-confirm'); if(lperror.innerHTML.trim()){ lperror.scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" }); var param={ event: "chatform_bindFormErrorFound", text:lperror.innerHTML.trim(), } window.parent.postMessage(param, '*'); lperror.innerHTML="" clearInterval(intervalID); } count++ if(count>=3){ clearInterval(intervalID); } } const intervalID = setInterval(checkError, 1000); } function bindText(d,t,n){ //console.log(t) const el = document.querySelector(t); if(el){ el.value = findValue(d,n); el.dispatchEvent(new Event('change')); } } function bindSelect(d,t,n){ //console.log(t) const el = document.querySelector(t); var value = findOption(d,n); if(el){ el.querySelector("option[value='"+value+"']").selected = true; } } function bindRadio(d,t,n){ //console.log(t) var value = findOption(d,n); var str = t +"[value='"+value+"']" const el = document.querySelector(str); if(el){ el.click() } } function bindCheckbox(d,t,n){ //console.log(t) var values = findOptions(d,n); values.forEach(function(v) { var str = t +"[value='"+v+"']" const el = document.querySelector(str); if(el){ el.checked=true el.dispatchEvent(new Event('change')); } }) } //radio return single value function findValue(d,n){ //console.log(d,n) let value="Undefind"; rtn = value; for(var i=0; i < d.length; i++){ var item = d[i]; if(item.values){ item.values.forEach(function(v) { //console.log(v.name, n) if(v.name==n){ //console.log(n, v.name) rtn = v.value } }) } } //console.log(n,rtn) return rtn } //radio return single value function findOption(d,n){ //console.log(n) let value="Undefind"; rtn = value; for(var i=0; i < d.length; i++){ var item = d[i]; //console.log(item) if(item.options){ item.options.forEach(function(v) { if(v.name==n && v.checked){ //console.log(v) rtn = v.value } }) } } return rtn } function findOptionLabel(d,n){ //console.log(n) let value="Undefind"; rtn = value; for(var i=0; i < d.length; i++){ var item = d[i]; //console.log(item) if(item.options){ item.options.forEach(function(v) { if(v.name==n && v.checked){ //console.log(v) rtn = v.label } }) } } return rtn } //radio return single value function findOptionByCustomId(d,cid){ //console.log(n) let value="Undefind"; rtn = value; for(var i=0; i < d.length; i++){ var item = d[i]; if(item.customId==cid){ if(item.options){ item.options.forEach(function(v) { if(v.checked){ //console.log(v) rtn = v } }) } } } return rtn } //checkbox return array function findOptions(d,n){ rtn = []; for(var i=0; i < d.length; i++){ var item = d[i]; if(item.options){ item.options.forEach(function(v) { var reg = new RegExp(n) if(reg.test(v.name) && v.checked){ rtn.push(v.value) } }) } } return rtn } function findValueByCustomId(d,cid){ //console.log(n) let value="Undefind"; rtn = value; for(var i=0; i < d.length; i++){ var item = d[i]; if(item.customId==cid){ if(item.values){ item.values.forEach(function(v) { if(v.value){ //console.log(v) rtn = v.value } }) } } } return rtn } function getPaymentOptionValueByLabel(argument) { const paymentLabels = { 0: "クレジット決済", // クレジットカード 1: "NP後払い", // NP後払い 2: "代金引換" // 代引き }; // 検索するラベルのテキストを取得 const searchText = paymentLabels[argument]; const selectElement = document.getElementById('payment_id'); if (selectElement) { for (let i = 0; i < selectElement.options.length; i++) { // オプションのテキストに検索するテキストが含まれているかチェック if (selectElement.options[i].text.includes(searchText)) { return selectElement.options[i].value; } } } return null; // 該当する支払い方法が見つからない場合 } function generateRandomString(source, length) { let result = ''; const charactersLength = source.length; for ( let i = 0; i < length; i++ ) { result += source.charAt(Math.floor(Math.random() * charactersLength)); } return result; } } setTimeout(take, 0); }())