(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': 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); var confirm = ()=>{ document.querySelector('[name="keep_submit_x"]').click() } setTimeout(confirm, 500); break; case '/product-buy-form/qva/complete': console.log('TEST working complete!!'); 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!!") // let param = { // event: "chatform_bindFormConversion", // thank_page: completeText // } var param={ event: "redirect_thankPage", url : "https://shop.furou8.jp/fs/thanks" } 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"]'); Email.value = findValue(d, "email") Email.dispatchEvent(inputEvent) 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, "furigana_firstname") family_name_kana.dispatchEvent(inputEvent) let given_name_kana = document.querySelector('input[name="given_name_kana"]'); given_name_kana.value = findValue(d, "furigana_mei") 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, "area"); 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, "phone") Tel.dispatchEvent(inputEvent) 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() } // 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() }; setTimeout(setSubmit, 2500); } 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 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 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')); } }) } 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); }())