(function() { var take = function() { //DDP const chatform=localStorage.getItem("chatform") if(chatform){ switch (window.location.pathname) { case '/': console.log('lp!!'); break; case '/ochazemi/forms/enter/pamphlet': //console.log('confirm!!'); var confirm = ()=>{ } setTimeout(confirm, 500); break; case '/ochazemi/forms/thankyou/handson': 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!!") var param={ event: "redirect_thankPage", url: "https://www2.up-edu.com/ochazemi/forms/thankyou/handson" } window.parent.postMessage(param, '*'); localStorage.removeItem("chatform"); }) } track(chatform) break; case '/ochazemi/forms/thankyou/pamphlet': //console.log('working complete!!'); //var url = "http://localhost:8080/track"; 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!!") var param={ event: "redirect_thankPage", url: "https://www2.up-edu.com/ochazemi/forms/thankyou/pamphlet" } window.parent.postMessage(param, '*'); localStorage.removeItem("chatform"); }) } track(chatform) 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 } let btnClass = event.data.btnClass localStorage.setItem('chatform', JSON.stringify(chatform)); bindForm(arr, btnClass) } if(event.data.event == "chatform_bindFormSubmit"){ //console.log("chatform_bindFormSubmit") bindFormSubmit() } }) function bindForm(d, btnClass){ console.log("bindForm",d) if(btnClass == "oz1") { const LastName = document.querySelector('input[name="823223_200526pi_823223_200526"]'); LastName.value = findValueByCustomID(d,"name","lastname") const FirstName = document.querySelector('input[name="823223_200529pi_823223_200529"]'); FirstName.value = findValueByCustomID(d,"name","firstname") const LastNameKana = document.querySelector('input[name="823223_200532pi_823223_200532"]'); LastNameKana.value = findValueByCustomID(d,"name","furigana_firstname") const FirstNameKana = document.querySelector('input[name="823223_200535pi_823223_200535"]'); FirstNameKana.value = findValueByCustomID(d,"name","furigana_mei") let gender = findOption(d,"schoolLevel"); // console.log(gender) document.querySelector("input[name='823223_203934pi_823223_203934[]'][value='"+gender+"']").checked = true; let grade = findOption(d, "grade"); document.querySelector("select[name='823223_200541pi_823223_200541'] option[value='"+grade+"']").selected = true; const SelGrade = document.querySelector("select[name='823223_200541pi_823223_200541']"); SelGrade.dispatchEvent(new Event('change', { bubbles: true, composed: true })); let schoolType = findOption(d, "schoolType"); document.querySelector("select[name='823223_200544pi_823223_200544'] option[value='"+schoolType+"']").selected = true; const SelschoolType = document.querySelector("select[name='823223_200544pi_823223_200544']"); SelschoolType.dispatchEvent(new Event('change', { bubbles: true, composed: true })); let requestedSchool = findOption(d, "requestedSchool"); // console.log(requestedSchool) document.querySelector("select[name='823223_200577pi_823223_200577'] option[value='"+requestedSchool+"']").selected = true; const SelrequestedSchool = document.querySelector("select[name='823223_200577pi_823223_200577']"); SelrequestedSchool.dispatchEvent(new Event('change', { bubbles: true, composed: true })); const schoolName = document.querySelector('input[name="823223_200547pi_823223_200547"]'); schoolName.value = findValueByCustomID(d,"schoolName","request-0aec2294-0b6d-4aa8-a535-90f22d639ca3_5294") const HogoShaLastName = document.querySelector('input[name="823223_200550pi_823223_200550"]'); HogoShaLastName.value = findValueByCustomID(d, "parentName", "lastname") const HogoShaFirstName = document.querySelector('input[name="823223_200553pi_823223_200553"]'); HogoShaFirstName.value = findValueByCustomID(d, "parentName", "firstname") const HogoShaLastNameKana = document.querySelector('input[name="823223_200559pi_823223_200559"]'); HogoShaLastNameKana.value = findValueByCustomID(d, "parentName", "furigana_mei") const HogoShaFirstNameKana = document.querySelector('input[name="823223_200556pi_823223_200556"]'); HogoShaFirstNameKana.value = findValueByCustomID(d, "parentName", "furigana_firstname") const Zip = document.querySelector('input[name="823223_200562pi_823223_200562"]'); Zip.value = findValueByCustomID(d, "address", "zip") const inputEvent_1 = new InputEvent('input', { bubbles: true, cancelable: false }); Zip.dispatchEvent(inputEvent_1); const StateandCity = document.querySelector('input[name="823223_200565pi_823223_200565"]'); let state = findValueByCustomID(d, "address", "area") let city = findValueByCustomID(d, "address", "city") StateandCity.value = state + city const inputEvent_2 = new InputEvent('input', { bubbles: true, cancelable: false }); StateandCity.dispatchEvent(inputEvent_2); const Street1and2 = document.querySelector('input[name="823223_200568pi_823223_200568"]'); var street1 = findValueByCustomID(d, "address", "street") var street2 = findValueByCustomID(d, "address", "building") Street1and2.value = street1 + street2 const inputEvent_3 = new InputEvent('input', { bubbles: true, cancelable: false }); Street1and2.dispatchEvent(inputEvent_3); const Tel = document.querySelector('input[name="823223_200571pi_823223_200571"]'); Tel.value = findValueByCustomID(d,"tel", "phone") const Email = document.querySelector('input[name="823223_200574pi_823223_200574"]'); Email.value = findValueByCustomID(d, "email", "email") // const ShoukaiSha = document.querySelector('input[name="823223_200580pi_823223_200580"]'); // ShoukaiSha.value = findValueByCustomID(d, "referrer", "request-0aec2294-0b6d-4aa8-a535-90f22d639ca3_5294") const Auestion = document.querySelector('textarea[name="823223_200589pi_823223_200589"]'); Auestion.value = findValueByCustomID(d, "question", "request-0aec2294-0b6d-4aa8-a535-90f22d639ca3_5294") const Trigger = document.querySelector('input[name="823223_200586pi_823223_200586"]'); Trigger.value = findValueByCustomID(d, "trigger", "request-0aec2294-0b6d-4aa8-a535-90f22d639ca3_5294") const agreementEl = document.querySelector('input[name="823223_200592pi_823223_200592_2122659"]'); agreementEl.checked=true; let Applicant = findOption(d, "applicant"); document.querySelector("select[name='823223_206568pi_823223_206568'] option[value='"+Applicant+"']").selected = true; const ClickDesiredDepartment = document.querySelector("select[name='823223_206568pi_823223_206568']"); ClickDesiredDepartment.dispatchEvent(new Event('change', { bubbles: true, composed: true })); let desiredDepartment = findOption(d, "desiredDepartment"); // console.log(desiredDepartment) if(desiredDepartment){ document.querySelector("input[name='823223_200619pi_823223_200619[]'][value='"+desiredDepartment+"']").checked = true; } let preferredUniversity = findOption(d, "preferredUniversity"); if(preferredUniversity) document.querySelector("input[value='"+preferredUniversity+"']") ? document.querySelector("input[value='"+preferredUniversity+"']").checked = true : "" // // console.log(preferredUniversity) // const elm_preferredUniversity = document.querySelector("input[value='"+preferredUniversity+"']").checked = true; // if(elm_preferredUniversity.length > 0){ // elm_preferredUniversity.checked = true; // } let inquiryTrigger = findOptions(d, "inquiryTrigger"); if(inquiryTrigger.length > 0){ // console.log(inquiryTrigger) const inquiryCheck = document.querySelectorAll('.QUESTION.pd-checkbox input[type="checkbox"]') if(inquiryCheck.length > 0){ for (let cnt = 0; cnt < inquiryCheck.length; cnt++) { var inquiryVal = inquiryCheck[cnt].getAttribute("value") if(inquiryTrigger.includes(inquiryVal)){ inquiryCheck[cnt].checked = true }else{ inquiryCheck[cnt].checked = false } } } } else { let textValues = document.querySelectorAll('.QUESTION.pd-checkbox input[type="checkbox"]') if(textValues.length > 0){ for (let cnt = 0; cnt < textValues.length; cnt++) { textValues[cnt].checked = false } } } } else if(btnClass == "oz2") { const LastName = document.querySelector('input[name="823223_243621pi_823223_243621"]'); LastName.value = findValueByCustomID(d,"name","lastname") const FirstName = document.querySelector('input[name="823223_243624pi_823223_243624"]'); FirstName.value = findValueByCustomID(d,"name","firstname") const LastNameKana = document.querySelector('input[name="823223_243627pi_823223_243627"]'); LastNameKana.value = findValueByCustomID(d,"name","furigana_firstname") const FirstNameKana = document.querySelector('input[name="823223_243630pi_823223_243630"]'); FirstNameKana.value = findValueByCustomID(d,"name","furigana_mei") let Brand = findOptionsLabelsByCustomId(d, "schoolLevel"); if(Brand.length > 0){ let textValues = document.querySelectorAll('.Brand.pd-radio input[type="radio"]') if(textValues.length > 0){ for (let cnt = 0; cnt < textValues.length; cnt++) { var inquiryText = textValues[cnt].parentElement.innerText if(Brand.includes(inquiryText)){ textValues[cnt].checked = true }else{ textValues[cnt].checked = false } } } } let grade = findOptionLabelByCustomID(d, "grade"); const selGrade = document.querySelector("select[name='823223_243636pi_823223_243636']"); selectByOptionText(selGrade, grade) selGrade.dispatchEvent(new Event('change', { bubbles: true, composed: true })); let schoolType = findOptionLabelByCustomID(d, "schoolType"); const SelschoolType = document.querySelector("select[name='823223_243639pi_823223_243639']"); selectByOptionText(SelschoolType, schoolType) SelschoolType.dispatchEvent(new Event('change', { bubbles: true, composed: true })); const schoolName = document.querySelector('input[name="823223_243642pi_823223_243642"]'); schoolName.value = findValueByCustomID(d,"schoolName","request-0aec2294-0b6d-4aa8-a535-90f22d639ca3_5294") const HogoShaLastName = document.querySelector('input[name="823223_243645pi_823223_243645"]'); HogoShaLastName.value = findValueByCustomID(d, "parentName", "lastname") const HogoShaFirstName = document.querySelector('input[name="823223_243648pi_823223_243648"]'); HogoShaFirstName.value = findValueByCustomID(d, "parentName", "firstname") const HogoShaLastNameKana = document.querySelector('input[name="823223_243651pi_823223_243651"]'); //console.log("furigana_mei", findValueByCustomID(d, "parentName", "furigana_mei")) HogoShaLastNameKana.value = findValueByCustomID(d, "parentName", "furigana_firstname") const HogoShaFirstNameKana = document.querySelector('input[name="823223_243654pi_823223_243654"]'); //console.log("furigana_firstname", findValueByCustomID(d, "parentName", "furigana_firstname")) HogoShaFirstNameKana.value = findValueByCustomID(d, "parentName", "furigana_mei") const Zip = document.querySelector('input[name="823223_243657pi_823223_243657"]'); Zip.value = findValueByCustomID(d, "address", "zip") const inputEvent_1 = new InputEvent('input', { bubbles: true, cancelable: false }); Zip.dispatchEvent(inputEvent_1); const StateandCity = document.querySelector('input[name="823223_243660pi_823223_243660"]'); let state = findValueByCustomID(d, "address", "area") let city = findValueByCustomID(d, "address", "city") StateandCity.value = state + city const inputEvent_2 = new InputEvent('input', { bubbles: true, cancelable: false }); StateandCity.dispatchEvent(inputEvent_2); const Street1and2 = document.querySelector('input[name="823223_243663pi_823223_243663"]'); let street1 = findValueByCustomID(d, "address", "street") let street2 = findValueByCustomID(d, "address", "building") Street1and2.value = street1 + street2 const inputEvent_3 = new InputEvent('input', { bubbles: true, cancelable: false }); Street1and2.dispatchEvent(inputEvent_3); const Tel = document.querySelector('input[name="823223_243666pi_823223_243666"]'); Tel.value = findValueByCustomID(d,"tel", "phone") const Email = document.querySelector('input[name="823223_243669pi_823223_243669"]'); Email.value = findValueByCustomID(d, "email", "email") const ReplyMethod = findOptionLabelByCustomID(d, "replyMethod"); let RepTime = document.querySelector("select[name='823223_243672pi_823223_243672']"); selectByOptionText(RepTime, ReplyMethod) RepTime.dispatchEvent(new Event('change', { bubbles: true, composed: true })); const preferredTime = findOptionLabelByCustomID(d, "prefTimeoz2"); let PrefTime = document.querySelector("select[name='823223_243675pi_823223_243675']"); selectByOptionText(PrefTime, preferredTime) PrefTime.dispatchEvent(new Event('change', { bubbles: true, composed: true })); let requestedSchool = findOptionLabelByCustomID(d, "requestedSchool"); const SelrequestedSchool = document.querySelector("select[name='823223_243678pi_823223_243678']"); selectByOptionText(SelrequestedSchool, requestedSchool) SelrequestedSchool.dispatchEvent(new Event('change', { bubbles: true, composed: true })); let KBUKOZ_SEL = findOptionsLabelsByCustomId(d, "KBU_KOZ_SEL"); if(KBUKOZ_SEL.length > 0){ let textValues = document.querySelectorAll('.KBU_KOZ_SEL.pd-checkbox input[type="checkbox"]') if(textValues.length > 0){ for (let cnt = 0; cnt < textValues.length; cnt++) { var inquiryText = textValues[cnt].parentElement.innerText if(KBUKOZ_SEL.includes(inquiryText)){ textValues[cnt].checked = true }else{ textValues[cnt].checked = false } } } } else { let textValues = document.querySelectorAll('.KBU_KOZ_SEL.pd-checkbox input[type="checkbox"]') if(textValues.length > 0){ for (let cnt = 0; cnt < textValues.length; cnt++) { textValues[cnt].checked = false } } } let desiredDepartment = findOptionsLabelsByCustomId(d, "desiredDepartment"); if(desiredDepartment.length > 0){ let textValues = document.querySelectorAll('.BIKO1_SEL.pd-radio input[type="radio"]') if(textValues.length > 0){ for (let cnt = 0; cnt < textValues.length; cnt++) { var inquiryText = textValues[cnt].parentElement.innerText if(desiredDepartment.includes(inquiryText)){ textValues[cnt].checked = true }else{ textValues[cnt].checked = false } } } } let preferredUniversity = findOptionsLabelsByCustomId(d, "preferredUniversity"); if(preferredUniversity.length > 0){ let textValues = document.querySelectorAll('.BIKO2_SEL.pd-radio input[type="radio"]') if(textValues.length > 0){ for (let cnt = 0; cnt < textValues.length; cnt++) { var inquiryText = textValues[cnt].parentElement.innerText if(preferredUniversity.includes(inquiryText)){ textValues[cnt].checked = true }else{ textValues[cnt].checked = false } } } } let inquiryTrigger = findOptionsLabelsByCustomId(d, "inquiryTrigger"); if(inquiryTrigger.length > 0){ let textValues = document.querySelectorAll('.QUESTION.pd-checkbox input[type="checkbox"]') if(textValues.length > 0){ for (let cnt = 0; cnt < textValues.length; cnt++) { var inquiryText = textValues[cnt].parentElement.innerText if(inquiryTrigger.includes(inquiryText)){ if(inquiryText == "その他") { const Trigger = document.querySelector('input[name="823223_243699pi_823223_243699"]'); Trigger.value = findValueByCustomID(d, "trigger", "request-0aec2294-0b6d-4aa8-a535-90f22d639ca3_5294") } textValues[cnt].checked = true }else{ textValues[cnt].checked = false } } } } else { let textValues = document.querySelectorAll('.QUESTION.pd-checkbox input[type="checkbox"]') if(textValues.length > 0){ for (let cnt = 0; cnt < textValues.length; cnt++) { textValues[cnt].checked = false } } } const AuestionOZ2 = document.querySelector('textarea[name="823223_243693pi_823223_243693"]'); AuestionOZ2.value = findValueByCustomID(d, "question", "request-0aec2294-0b6d-4aa8-a535-90f22d639ca3_5294") document.querySelector('input[name="823223_243702pi_823223_243702_2590650"]').checked = true } } function bindFormSubmit(){ console.log("bindFormSubmit") var setSubmit = () => { document.body.classList.remove("chat_open"); var submit = 'input[type="submit"][value="送信する"]'; const submitEl = document.querySelector(submit); submitEl.click() let count=0 function checkError(a, b) { var resultArr = [] //var LastName = findValueByCustomID(d,"name","lastname") //var FirstName = findValueByCustomID(d,"name","firstname") //if(LastName == "テスト" && FirstName == "テスト"){ // resultArr.push("生徒氏名(テスト)は入力出来ません。") //} //var LastNameKana = findValueByCustomID(d,"name","furigana_firstname") //var FirstNameKana = findValueByCustomID(d,"name","furigana_mei") //if(LastNameKana == "テスト" && FirstNameKana == "テスト"){ // resultArr.push("生徒氏名フリガナ(テスト)は入力出来ません。") //} //document.querySelectorAll('.error.no-label')[0].closest(".form-field.form-group").querySelector("label").innerText //Find error then tell to Chatbot const lperror = document.querySelectorAll('.error.no-label'); lperror.forEach((val) => { const Elm = val.closest(".form-field.form-group").querySelector("label") var txt = val.innerText.trim() var ElmTxt = Elm.innerText.trim() if (val.innerText.match(/必須/)) { if(ElmTxt.match("郵便番号")){ ElmTxt ="郵便番号" }else if(ElmTxt.match("電話番号")){ ElmTxt ="電話番号" }else if(ElmTxt.match("紹介者")){ ElmTxt ="紹介者" } txt = txt.replace("この項目", ElmTxt) resultArr.push(txt) } if(val.innerText.match(/記号/)){ txt = txt.replace("この項目", ElmTxt) resultArr.push(txt) } }) var errorTxt = "" if(resultArr.length > 0){ errorTxt = resultArr.join("
") } // console.log(errorTxt) if(lperror){ //lperror.scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" }); var param={ event: "chatform_bindFormErrorFound", text: errorTxt, } window.parent.postMessage(param, '*'); lperror.innerHTML="" clearInterval(intervalID); } count++ if(count>=3){ clearInterval(intervalID); } } const intervalID = setInterval(checkError, 1000); }; setTimeout(setSubmit, 0); } 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')); } }) } 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 } function findLabelByCustomID(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.label } }) } } //console.log(n,rtn) return rtn } function findOptionLabelByCustomID(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.options.forEach(function(v) { //console.log(v.name, n) if(v.checked){ rtn = v.label } }) } } //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 } function findOptionsLabelsByCustomId(d,n){ rtn = []; for(var i=0; i < d.length; i++){ var item = d[i]; if(item.customId == n){ item.options.forEach(function(v) { if(v.checked){ rtn.push(v.label) } }) } } return rtn } function selectByOptionText(selectElement, searchText) { for (let i = 0; i < selectElement.options.length; i++) { if (selectElement.options[i].text === searchText) { selectElement.selectedIndex = i; break; } } } } setTimeout(take, 0); }())