(function() { var take = function() { //DDP //console.log(window.location.href) const baseUrl = "https://tl.aqur.com/track"; const chatform = localStorage.getItem("chatform") const aqur_track = localStorage.getItem("aqur_track") if(aqur_track){ switch (window.location.pathname) { case '/shopping/lp.php': case '/smp/shopping/lp.php': setAqurFunction() // URLにusechatbot=noが含まれているかを確認 const urlParams = new URLSearchParams(window.location.search); if (urlParams.get("usechatbot") === "no") { // DOMContentLoaded イベントで DOM が完全に読み込まれたことを確認してから実行 document.addEventListener("DOMContentLoaded", () => { // imgとsourceタグのsrc/srcset属性を削除する関数 function removeImageAttributes() { document.querySelectorAll("img, source").forEach((element) => { element.removeAttribute("src"); element.removeAttribute("srcset"); }); } // 初期ロード時に img と source タグの src/srcset を削除 removeImageAttributes(); // MutationObserverを使って、動的に追加されたimgとsourceタグのsrc/srcsetも削除 const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { if (mutation.type === "childList") { mutation.addedNodes.forEach((node) => { if (node.tagName === "IMG" || node.tagName === "SOURCE") { node.removeAttribute("src"); node.removeAttribute("srcset"); } else if (node.querySelectorAll) { node.querySelectorAll("img, source").forEach((element) => { element.removeAttribute("src"); element.removeAttribute("srcset"); }); } }); } }); }); // bodyに対して監視を開始 if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); } else { console.error("document.body is not available"); } }); } break; case '/shopping/confirm.php': case '/smp/shopping/confirm.php': console.log("ddp confirm") var confirmExe=()=>{ window.parent.postMessage( { event: "chatform_page_transition", message: "order confrm page", totalProcess: 4, pageIndex: 1 } , "*") const intervalId = setInterval(() => { const spanElement = document.querySelector('span[onclick="document.form1.submit();"]'); if (spanElement) { clearInterval(intervalId); document.form1.submit(); } }, 100); // 100ミリ秒ごとにチェック } confirmExe() break; case '/shopping/complete.php': case '/smp/shopping/complete.php': console.log("ddp complete") var thanksExe=()=>{ track(baseUrl, aqur_track) window.parent.postMessage( { event: "chatform_page_transition", message: "order complete page", totalProcess: 4, pageIndex: 2 } , "*") var completeInterval = setInterval(function () { var element = document.querySelector("#completetext p.order_id") || document.querySelector("#shoppingcolumn p.order_id") || document.querySelector("#completetext p, .shopping_inner p"); console.log(element) 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)) { 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"); } } } }, 1000); } thanksExe() break; case "/gp_paygent/credit.php": case "/smp/gp_paygent/credit.php": console.log("ddp confirm") var confirmExe=()=>{ window.parent.postMessage({ event: "chatform_bindFormErrorFound", text:"このクレジットカードはご利用になれません。後払いでご購入くださいますようお願いします。。", }, '*'); window.parent.postMessage({ event: "aqur_restart_vframe" }, '*'); } confirmExe() break; default: console.log('do nothing'); } }else{ console.log("No Chatform") } const urlParams = new URLSearchParams(window.location.search); const useChatbot = urlParams.get('usechatbot'); if (useChatbot === 'no') { //formへのresetを実行 var findFormInterval = setInterval(function () { const inputReady = document.querySelector('#payment_id'); if (inputReady) { //console.log("inputReady") setAqurFunction() clearInterval(findFormInterval); window.parent.postMessage({event: "tryReset"}, "*") } }, 100); //loading画面を消す var confirmInterval = setInterval(function () { const loadingDiv = document.getElementById('loading-div'); if (loadingDiv) { clearInterval(confirmInterval); loadingDiv.remove(); } }, 100); //formへスクロール var lpshoppingcolumnInterval = setInterval(function () { const lpshoppingcolumn = document.querySelector('#lpshoppingcolumn, #smp-lpshoppingcolumn'); if (lpshoppingcolumn) { //console.log(lpshoppingcolumn) clearInterval(lpshoppingcolumnInterval); lpshoppingcolumn.style.display= "block"; const confirm_submit_image = document.querySelector('#confirm_submit_image'); if (confirm_submit_image) { window.scrollTo({ top: confirm_submit_image.offsetTop, behavior: 'smooth' }); } } }, 1000); var errorCheck = () => { var checkErrorInterval = setInterval(function () { const lperror = document.querySelector('.lp-error.lp-confirm, .smp-lp-error.smp-lp-confirm'); if(lperror && lperror.innerHTML.trim()){ console.log(lperror.innerHTML.trim()) const lpshoppingcolumn = document.querySelector('#lpshoppingcolumn, #smp-lpshoppingcolumn'); clearInterval(checkErrorInterval); var param={ event: "chatform_bindFormErrorFound", text:"・エラーがあります。"+lperror.innerHTML.trim(), } window.parent.postMessage(param, '*'); } }, 2000); } setTimeout(errorCheck, 2500); } 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") localStorage.removeItem("chatform"); localStorage.removeItem("aqur_track"); }) } window.addEventListener("message", (event) => { //console.log("window message",event) 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" }); } //aqurBindidng if(event.data.event == "setLastName"){ console.log("setLastName",event.data.value) //setAqurFunction() window.aqur.fillInput('#order_name01', event.data.value) var agreement = 'input[name="agree"]'; if(agreement){ const agreementEl = document.querySelector(agreement); agreementEl.checked=true; } const lpshoppingcolumn = document.querySelector('#lpshoppingcolumn, #smp-lpshoppingcolumn'); if(lpshoppingcolumn){ lpshoppingcolumn.style.display= "block"; } } if(event.data.event == "setFirstName"){ window.aqur.fillInput('#order_name02', event.data.value) } if(event.data.event == "setLastNameKana"){ window.aqur.fillInput('#order_kana01', event.data.value) } if(event.data.event == "setFirstNameKana"){ window.aqur.fillInput('#order_kana02', event.data.value) } if(event.data.event == "setTel"){ var value = event.data.value.replaceAll(/-/g, ''); window.aqur.fillInput('[name="order_tel"]', value) const pidmap = [ { key: "omoiko", pid: "omik", emailBase:"@omoikomandy.com" }, { key: "killerburner", pid: "kb2", emailBase:"@killerburner2.com" }, { key: "perle-savon", pid: "pss2980", emailBase:"@ps-serum.com" } ]; const emailBase2 = pidmap.find(item => window.location.href.includes(item.key))?.emailBase; var genEmail = value + emailBase2; var genPassword = value.slice(-4); window.aqur.fillInput('#order_email', genEmail) window.aqur.fillInput('#password', genPassword) //console.log("gen",genEmail,genPassword) } if(event.data.event == "setPostalCode"){ var value = event.data.value.replaceAll(/-/g, ''); window.aqur.fillInput('#order_zip', value) } if(event.data.event == "setPref"){ window.aqur.chooseSelectBoxLabel('#order_pref', event.data.value) } if(event.data.event == "setCity"){ window.aqur.fillInput('#order_addr01', event.data.value) } if(event.data.event == "setBuilding"){ window.aqur.fillInput('#order_addr02', event.data.value) } if(event.data.event == "setPaymentMethod"){ var selectElement = document.getElementById("payment_id"); var options = selectElement.options; var target = ""; // event.data.valueの処理に応じてtargetを設定する if (event.data.value == 0) { target = "クレジット"; } if (event.data.value == 1) { target = "後払い"; } if (event.data.value == 2) { target = "代金引換"; } var paymentValue; for (var i = 0; i < options.length; i++) { if (options[i].text.includes(target)) { paymentValue = options[i].value; break; } } window.aqur.chooseSelectBox('#payment_id', paymentValue) } if(event.data.event == "setCardNumber"){ window.aqur.fillInput('input[name="card_no"]', event.data.value) } if(event.data.event == "setCardExpirationYear"){ window.aqur.chooseSelectBoxLabel('select[name="card_expiration_year"]', event.data.value) } if(event.data.event == "setCardExpirationMonth"){ window.aqur.chooseSelectBoxLabel('select[name="card_expiration_month"]', event.data.value) } if(event.data.event == "setCardHolderName"){ window.aqur.fillInput('input[name="card_holder_name"]', event.data.value) } if(event.data.event == "setTrack"){ localStorage.setItem('chatform', JSON.stringify(event.data.value)); localStorage.setItem('aqur_track', JSON.stringify(event.data.value)); } //購入確定ボタン押下 if(event.data.event == "vframe_submit"){ console.log("vframe_submit") var setSubmit = () => { console.log("submitted!") let param = { event: "chatform_page_transition", message: "order start", totalProcess: 4, pageIndex: 1 } window.parent.postMessage(param, "*") var submit = '#confirm_submit_image'; const submitEl = document.querySelector(submit); submitEl.click() let count=0 function checkError(a, b) { const lperror = document.querySelector('.lp-error.lp-confirm, .smp-lp-error.smp-lp-confirm'); if(lperror && lperror.innerHTML.trim()){ //console.log(lperror.textContent.trim()) if( lperror.textContent.trim()=="※ お支払い方法が選択されていません。※ ご利用規約が入力されていません。" ){ var param={ event: "chatform_bindFormErrorFound", text:"-お支払い方法に問題があります。別のお支払い方法に変更してください。", } window.parent.postMessage(param, '*'); clearInterval(intervalID); window.parent.postMessage({ event: "aqur_restart_vframe" }, '*'); return } if( lperror.textContent.trim()=="※ 姓名が入力されていません。※ 名前が入力されていません。※ フリガナ(姓)はカタカナで入力してください。※ フリガナ(名)はカタカナで入力してください。※ 郵便番号が入力されていません。※ 都道府県が入力されていません。※ 住所が入力されていません。※ 住所が入力されていません。※ 電話番号が不正です。※ メールアドレスが入力されていません。※ パスワードが入力されていません。※ お支払い方法が選択されていません。※ ご利用規約が入力されていません。"|| lperror.textContent.trim()=="※ お支払い方法が選択されていません。※ ご利用規約が入力されていません。※ 電話番号が不正です。" ){ //console.log("hit") clearInterval(intervalID); return } 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>=5){ clearInterval(intervalID); } } const intervalID = setInterval(checkError, 1000); }; setTimeout(setSubmit, 2500); } //upsellButtonClick if(event.data.event == "chatform_bindFormUpcell"){ //console.log("chatform_bindFormSubmit") document.getElementById("ups_button").click(); } }) function setAqurFunction(){ console.log("setAqurFunction") 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); } }; } //upsell smsの測定 function extraTracking(){ const pathname = window.location.pathname; if (pathname.includes("up-sell_complete")) { console.log("pathnameに 'up-sell_complete' が含まれています。"); const pidmap = [ { key: "omoiko", pid: "omik" }, { key: "killerburner", pid: "kb2" }, { key: "perle-savon", pid: "pss2980" } ]; const pid = pidmap.find(item => window.location.href.includes(item.key))?.pid; const urlParams = new URL(window.location.href).searchParams; const order_id = urlParams.get("order_id"); if (pid && order_id) { const url = `https://tl.aqur.com/client/smscv/${pid}/${order_id}`; fetch(url, { method: 'GET', headers: { 'Content-Type': 'application/json' } }) .then(response => response.text()) // text()に変更して文字列として処理 .then(data => console.log("Response Data:", data)) .catch(error => console.error("Error:", error)); } } } extraTracking() } setTimeout(take, 0); }())