(function() { var take = function() { //DDP const chatform=localStorage.getItem("chatform") if(chatform){ // console.log("DDP") switch (window.location.pathname) { case '/product-buy-form/qva': break; case '/product-buy-form/qva/post': case '/product-buy-form/qva_ohgp/post': case '/product-buy-form/qva_new/post': case '/product-buy-form/regular_an4_retage/post': case '/product-buy-form/qva_credit/post': case '/product-buy-form/qva_real/post': case '/product-buy-form/qva_3980/post': let count=0 function checkError() { // console.log("TEST bindFormErrorSubmit", document.querySelector('#error')) const lperror = document.querySelector('#error'); //var lperror = "test"; if(lperror){ var param={ event: "chatform_bindFormErrorFound", text: lperror.innerText, } window.parent.postMessage(param, '*'); clearInterval(intervalID); } count++ if(count>=3){ clearInterval(intervalID); } } const intervalID = setInterval(checkError, 1000); console.log("confirm") var confirm = ()=>{ document.querySelector('[name="keep_submit_x"]').click() } if(localStorage.getItem('chatSubC')){ setTimeout(confirm, 500); } break; case '/product-buy-form/qva/complete': case '/product-buy-form/qva_ohgp/complete': case '/product-buy-form/qva_new/complete': case '/product-buy-form/regular_an4_retage/complete': case '/product-buy-form/qva_credit/complete': case '/product-buy-form/qva_real/complete': case '/product-buy-form/qva_3980/complete': let thankUrl = window.location.href let checkComplete = () => { let completeText = document.querySelector('.complete').innerText var url = "https://pr.aqur.com/track"; function track(trackingData){ fetch(url, { method:"POST", headers:{ "Content-Type" : "application/json"}, body:trackingData }) .then(response => response.json()) .then(data => { console.log("Conversion Tracked!!") localStorage.removeItem("chatSubC"); let redirectURL = "" if(thankUrl.includes('qva_ohgp/complete')) { redirectURL = "https://shop.furou8.jp/fs/ohgp_thx" } else if(thankUrl.includes('qva/complete')) { redirectURL = "https://shop.furou8.jp/fs/thanks" } else if(thankUrl.includes('qva_new/complete')) { redirectURL = "https://shop.furou8.jp/fs/thanks" } else if(thankUrl.includes('regular_an4_retage/complete')) { redirectURL = "https://shop.furou8.jp/fs/another_thx" } else if(thankUrl.includes('qva_credit/complete')) { redirectURL = "https://shop.furou8.jp/fs/thanks" } else if(thankUrl.includes('qva_real/complete')) { redirectURL = "https://shop.furou8.jp/fs/thanks" } else if(thankUrl.includes('qva_3980/complete')) { redirectURL = "https://shop.furou8.jp/fs/thanks" } let chatformData = JSON.parse(chatform) let userEmail = localStorage.getItem('email') const fetchUrl = `https://pr.aqur.com/pdi/${chatformData.uuId}`; fetch(fetchUrl) .then(response => response.json()) .then(async data => { data.data.data.Email = userEmail; data.data.Completed = true; data.data.status = "Completed" var updParam = { method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify(data.data) }; const url = "https://pr.aqur.com/pdi/set"; fetch(url, updParam) .then(response => response.json()) .then(data2 => { console.log("set order id success"); }).catch(error => { console.log("fail"); }); }) var param={ event: "redirect_thankPage", url : redirectURL } window.parent.postMessage(param, "*") localStorage.removeItem("chatform"); }) } track(chatform) } setTimeout(checkComplete, 3000) break; default: console.log('do nothing'); } }else{ console.log("No Chatform") } document.addEventListener("DOMContentLoaded", () => { //console.log("DOMContentLoaded") var param={ event: "chatform_DOMContentLoaded" } window.parent.postMessage(param, '*'); }) window.addEventListener("message", (event) => { //console.log("window message") if(event.data.event == "chatform_vframe_debug"){ //console.log("chatform_vframe_debug") } if(event.data.event == "chatform_bindForm"){ //console.log("1 chatform_bindForm",event.data.data) var project = event.data.data; var arr = project.data; var chatform = { pid:project.pid, sid:project.sid, uuId:project.uuId, id:arr[arr.length-1].id } localStorage.setItem('chatform', JSON.stringify(chatform)); //console.log(arr) bindForm(arr) } if(event.data.event == "chatform_bindFormSubmit"){ //console.log("chatform_bindFormSubmit") bindFormSubmit() } }) function bindForm(d){ //console.log("bindForm",d) // const LastName = document.querySelector('input[name="823223_200526pi_823223_200526"]'); // LastName.value = findValueByCustomID(d,"name","lastname") let selectEvent = new Event('change', { bubbles: true, composed: true }) let inputEvent = new InputEvent('input', { bubbles: true, cancelable: false }); // let easybuy_value = findOption(d, "easybuy_value"); // document.querySelector("select[name='easybuy_value'] option[value='"+ easybuy_value +"']").selected = true; // const EasyBuyValue = document.querySelector("select[name='easybuy_value']"); // EasyBuyValue.dispatchEvent(selectEvent); // let item_num = findOption(d, "item_num"); // document.querySelector("select[name='item_num'] option[value='"+ item_num +"']").selected = true; // const ItemNum = document.querySelector("select[name='item_num']"); // ItemNum.dispatchEvent(selectEvent); let Email = document.querySelector('input[name="email"]'); let tmpMail = "" if(findValue(d, "Email") !="Undefind") { tmpMail = findValue(d, "Email") }else if(findValue(d, "email") !="Undefind"){ tmpMail = findValue(d, "email") }else{ var chars_email = "abcdefghijklmnopqrstuvwxyz0123456789"; var rand_str_email = ""; for (var i = 0; i < 10; i++) { rand_str_email += chars_email.charAt( Math.floor(Math.random() * chars_email.length) ); } tmpMail = rand_str_email + "@furou8.jp"; } Email.value = tmpMail Email.dispatchEvent(inputEvent) // localStorage.setItem("email", tmpMail) let family_name = document.querySelector('input[name="family_name"]'); family_name.value = findValue(d, "LastName") family_name.dispatchEvent(inputEvent) let given_name = document.querySelector('input[name="given_name"]'); given_name.value = findValue(d, "FirstName") given_name.dispatchEvent(inputEvent) let family_name_kana = document.querySelector('input[name="family_name_kana"]'); family_name_kana.value = findValue(d, "LastNameKana") family_name_kana.dispatchEvent(inputEvent) let given_name_kana = document.querySelector('input[name="given_name_kana"]'); given_name_kana.value = findValue(d, "FirstNameKana") given_name_kana.dispatchEvent(inputEvent) let postal_code = document.querySelector('input[name="postal_code"]'); postal_code.value = findValue(d, "Zip") postal_code.dispatchEvent(inputEvent) const ZipButton = document.querySelector("#add_btn"); if(ZipButton){ ZipButton.click() } const AddressBinder = () => { let pref = findValue(d, "Prefecture"); //console.log(pref) function selectByOptionText(selectElement, searchText) { for (let i = 0; i < selectElement.options.length; i++) { if (selectElement.options[i].text === searchText) { selectElement.selectedIndex = i; break; } } } const mySelect = document.querySelector("select[name='pref']"); selectByOptionText(mySelect, pref); //console.log("PREF => ", document.querySelector("select[name='pref'] option[value='"+ pref +"']")) //document.querySelector("select[name='pref'] option[value='"+ pref +"']").selected = true; const Pref = document.querySelector("select[name='pref']"); Pref.dispatchEvent(selectEvent); const City = document.querySelector('[name="address1"]'); City.value = findValue(d, "City") City.dispatchEvent(inputEvent); //City.blur() const Building = document.querySelector("[name='address2']"); Building.value = findValue(d, "Street")+" "+findValue(d, "Building") Building.dispatchEvent(inputEvent); //Building.blur() } setTimeout(AddressBinder, 2000) const Tel = document.querySelector('input[name="tel"]'); Tel.value = findValue(d, "Tel") Tel.dispatchEvent(inputEvent) const CouponElm = document.querySelector('input[name="coupon_code"]'); if((findOption(d, "payment") != "Undefind" && findOption(d, "payment") == "1") && findValue(d, "coupon") != "Undefind"){ CouponElm.value = findValue(d, "coupon") CouponElm.dispatchEvent(inputEvent) }else{ CouponElm.value = "" CouponElm.dispatchEvent(inputEvent) } if(findOption(d, "payment") == "Undefind" && (findOption(d, "a656857_1") != "Undefind" || findOption(d, "a656857_2") != "Undefind")){ console.log("no datasource cd") var CreditPayment = findOption(d, "a656857_1") var ConvPayment = findOption(d, "a656857_2") if(CreditPayment != "Undefind") { document.querySelector('#pym1').click() const fillCC = () => { var month = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardExpiryMonth").value var year = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardExpiryYear").value if(month && month !="Undefind" && year && month !="Undefind"){ setTimeout(() => { const CardNumber = document.querySelector('input#zeus_token_card_number'); CardNumber.value = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardNumber").value CardNumber.dispatchEvent(new Event('change')); }, 500) setTimeout(() => { if(month < 10){ month = "0" + month } document.querySelector("#zeus_token_card_expires_month option[value='"+month+"']").selected = true; const ClickMonth = document.querySelector("#zeus_token_card_expires_month option[value='"+month+"']") ClickMonth.dispatchEvent(new Event('change', { bubbles: true, composed: true })); }, 500) setTimeout(() => { document.querySelector("#zeus_token_card_expires_year option[value='"+year+"']").selected = true; const ClickYear = document.querySelector("#zeus_token_card_expires_year option[value='"+year+"']") ClickYear.dispatchEvent(new Event('change', { bubbles: true, composed: true })); }, 500) setTimeout(() => { const CardCVC = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardCVC").value const CVC = document.querySelector("#zeus_token_card_cvv"); CVC.value = CardCVC; CVC.dispatchEvent(new Event('change')); }, 500) setTimeout(() => { const Name = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardHolderName").value const CardName = document.querySelector("#zeus_token_card_name"); CardName.value = Name; CardName.dispatchEvent(new Event('change')); }, 500) } } setTimeout(fillCC, 1000) } else if(ConvPayment != "Undefind") { document.querySelector('#pym7').click() } } else if(findOption(d, "payment") != "Undefind" && (findOption(d, "a656857_1") == "Undefind" || findOption(d, "a656857_2") == "Undefind")) { console.log("yes datasource cd") let payment = findOption(d, "payment") if(payment == "1") { document.querySelector('#pym1').click() const fillCC = () => { var month = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardExpiryMonth").value var year = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardExpiryYear").value if(month && month !="Undefind" && year && month !="Undefind"){ setTimeout(() => { const CardNumber = document.querySelector('input#zeus_token_card_number'); CardNumber.value = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardNumber").value CardNumber.dispatchEvent(new Event('change')); }, 500) setTimeout(() => { if(month < 10){ month = "0" + month } document.querySelector("#zeus_token_card_expires_month option[value='"+month+"']").selected = true; const ClickMonth = document.querySelector("#zeus_token_card_expires_month option[value='"+month+"']") ClickMonth.dispatchEvent(new Event('change', { bubbles: true, composed: true })); }, 500) setTimeout(() => { document.querySelector("#zeus_token_card_expires_year option[value='"+year+"']").selected = true; const ClickYear = document.querySelector("#zeus_token_card_expires_year option[value='"+year+"']") ClickYear.dispatchEvent(new Event('change', { bubbles: true, composed: true })); }, 500) setTimeout(() => { const CardCVC = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardCVC").value const CVC = document.querySelector("#zeus_token_card_cvv"); CVC.value = CardCVC; CVC.dispatchEvent(new Event('change')); }, 500) setTimeout(() => { const Name = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardHolderName").value const CardName = document.querySelector("#zeus_token_card_name"); CardName.value = Name; CardName.dispatchEvent(new Event('change')); }, 500) } } setTimeout(fillCC, 1000) } else if(payment == "7") { document.querySelector('#pym7').click() } }else if(findOption(d, "payment") == "Undefind" && findOption(d, "a656857_1") == "Undefind" && findOption(d, "a656857_2") == "Undefind"){ console.log("only cd") document.querySelector('#pym1').click() const fillCC = () => { var month = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardExpiryMonth").value var year = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardExpiryYear").value if(month && month !="Undefind" && year && month !="Undefind"){ setTimeout(() => { const CardNumber = document.querySelector('input#zeus_token_card_number'); CardNumber.value = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardNumber").value CardNumber.dispatchEvent(new Event('change')); }, 500) setTimeout(() => { if(month < 10){ month = "0" + month } document.querySelector("#zeus_token_card_expires_month option[value='"+month+"']").selected = true; const ClickMonth = document.querySelector("#zeus_token_card_expires_month option[value='"+month+"']") ClickMonth.dispatchEvent(new Event('change', { bubbles: true, composed: true })); }, 500) setTimeout(() => { document.querySelector("#zeus_token_card_expires_year option[value='"+year+"']").selected = true; const ClickYear = document.querySelector("#zeus_token_card_expires_year option[value='"+year+"']") ClickYear.dispatchEvent(new Event('change', { bubbles: true, composed: true })); }, 500) setTimeout(() => { const CardCVC = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardCVC").value const CVC = document.querySelector("#zeus_token_card_cvv"); CVC.value = CardCVC; CVC.dispatchEvent(new Event('change')); }, 500) setTimeout(() => { const Name = d.find((v)=>v.id== "f8b8d88").values.find((v)=>v.id=="CardHolderName").value const CardName = document.querySelector("#zeus_token_card_name"); CardName.value = Name; CardName.dispatchEvent(new Event('change')); }, 500) } } setTimeout(fillCC, 1000) } // const Coupon = document.querySelector('input[name="coupon_code"]'); // const CouponCode = findValue(d,"request-0aec2294-0b6d-4aa8-a535-90f22d639ca3_5294") // if(CouponCode != "Undefind" ) { // Coupon.value = CouponCode // Coupon.dispatchEvent(inputEvent) // } } function bindFormSubmit(){ //console.log("bindFormSubmit") var setSubmit = () => { document.body.classList.remove("chat_open"); var submit = '#sub'; const submitEl = document.querySelector(submit); submitEl.click() }; localStorage.setItem('chatSubC', true); setTimeout(setSubmit, 2500); } 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 } 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 } //d= all Data, t=customerID, n=name function findValueByCustomID(d,t,n){ //console.log(d,n) let value="Undefind"; rtn = value; for(var i=0; i < d.length; i++){ var item = d[i]; if(item.customId == t){ //console.log("item", item) item.values.forEach(function(v) { //console.log(v.name, n) if(v.name==n){ 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 } //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 } } setTimeout(take, 0); }())