(function() { function executeIfConditionsMet() { const urlParams = new URLSearchParams(window.location.search); const isChat = urlParams.get('is_chat') === 'true'; const pathname = window.location.pathname; if (pathname.includes('telemedicine/sign_up_reservation') && isChat) { var take = function() { window.AqurBaseURL = 'https://bleach-server-e7d55b4bcbab.herokuapp.com'; const urlParams = new URLSearchParams(window.location.search); if (!urlParams.has('utm_source') || urlParams.get('utm_source') !== 'w-bl') { } window.addEventListener("chatform_initialized", (event) => { //console.log('chatform_initialized') activateChatformWidget(); }) function render(template, data){ //console.log("render",template,data) return template.replace(/{{(.*?)}}/g, (match) => { return data[match.split(/{{|}}/).filter(Boolean)[0].trim()] }) } function activateChatformWidget(active){ if (active == false) { document.body.classList.remove("chat_open"); const w = document.querySelector('.chatform_widget'); w.classList.add("close"); } if(!chatform_initialized){ console.log("Aqur is not ready") return } const w = document.querySelector('.chatform_widget'); w.classList.toggle("close"); if(w.classList.contains("close")){ document.body.classList.remove("chat_open"); }else{ document.body.classList.add("chat_open"); } } var chatform_initialized = false const pid = "clinicfor"; const target = "production"; const mode = "release"; const device = JSON.parse("false".toLowerCase())?"mobile":"pc"; const launch = "click"; const client = "https://form.aqur.com/"; let REF = new URL(window.location); let userChatbot = REF.searchParams.get('usechatbot') if(userChatbot=="no"){ console.log("no chatbot") return } REF.searchParams.append('pid', pid); REF.searchParams.append('mode', mode); REF.searchParams.append('target', target); REF.searchParams.append('hash', "a44fa932-f9c0-458e-8c40-5109fafda413"); REF.searchParams.append('browser', "undefined"); REF.searchParams.append('device', device); REF.searchParams.append('os', "undefined"); REF.searchParams.append('ua', "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)"); REF.searchParams.append('ip', "3.134.115.9"); REF.searchParams.append('ref', REF.href); REF.searchParams.append('path', REF.pathname); //for UI REF.searchParams.append('CLIENT_ID', 'BLC'); REF.searchParams.append('BASE_URL', 'https://bleach-server-e7d55b4bcbab.herokuapp.com'); REF.searchParams.append('HEADER_LABEL', ' '); REF.searchParams.append('HEADER_BG_COLOR', '#fff'); REF.searchParams.append('HEADER_LABEL_COLOR', '#fff'); REF.searchParams.append('SHOW_TIMER', 'false'); REF.searchParams.append('ICON_PATH', 'https://res.cloudinary.com/dts6mbw86/image/upload/v1713319985/aqur/common/icon_azvikf.png'); const params = new URLSearchParams(REF.search.slice(1)); var sid = params.get('qu_sid'); if(sid){ REF.searchParams.append('sid', sid); } let search = REF.search.slice(1) //console.log(search) let widget = render( ''+ '', { device : device, client : client, search : (search)?"&"+search:"", } ); const body = document.body; if(body){ var filterid; const chatbotProgressBar = "
" body.insertAdjacentHTML('beforeend', chatbotProgressBar); body.classList.add(device) body.insertAdjacentHTML('beforeend', widget); const target = document.querySelector('.chatform_widget'); const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { if(!target.classList.contains("close")){ var contentWindow = target.contentWindow; if(contentWindow){ contentWindow.postMessage("chat_open", "*"); contentWindow.postMessage( { type:"filterIdChanged", data:filterid }, "*"); } } }); }); const config = { characterData: true, attributes:true, subtree: true }; observer.observe(target, config); document.body.classList.add('centerWidget'); } let creationComplete = function(){ if(device=="pc"){ var resize=()=>{ let zoom_level = window.devicePixelRatio || window.screen.availWidth / document.documentElement.clientWidth * 100; const targets = document.querySelectorAll('body,.chatform_widget'); if(zoom_level>=3){ targets[0].classList.add("mobile") targets[0].classList.remove("pc") targets[1].classList.add("mobile") targets[1].classList.remove("pc") }else{ targets[0].classList.add("pc") targets[0].classList.remove("mobile") targets[1].classList.add("pc") targets[1].classList.remove("mobile") } } resize() window.addEventListener("resize", () => { resize() }) } document.addEventListener('click', (event) => { if (event.target && event.target.closest('.chatformBtn') || event.target.classList.contains("chatformBtn") || event.target.id == "chatform_widget_cancelbtn" ) { activateChatformWidget() } }); document.dispatchEvent(new CustomEvent("chatform_widget_creation_complete")); }; setTimeout(creationComplete, 3000); window.addEventListener("message", (event) => { if(event.data.event == "chatform_sent"){ //console.log("chatform_sent") var project = event.data.project; //console.log(event.data) var arr = project.data; var aqur = { pid:project.pid, sid:project.sid, uuId:project.uuId, id:arr[arr.length-1].id } localStorage.setItem('aqur', JSON.stringify(aqur)); const checkbox = Array.from(document.querySelectorAll('button')).find(btn => btn.textContent.includes('上記すべてを確認しました')); if (checkbox !== null) { checkbox.click() } else { console.error('Checkbox with ID "agreement" not found.'); } const sendButton = document.querySelector('.gtm-sign-up-reservation-email'); if (sendButton !== null) { setTimeout(() => { sendButton.click(); }, 1000); setTimeout(() => { function activateChatformWidget2(){ document.body.classList.remove("chat_open"); const w = document.querySelector('.chatform_widget'); w.classList.add("close"); } activateChatformWidget2() }, 1500); } else { console.error('Element with ID ".sc-dmA-DAn" not found.'); } } if(event.data.event == "chatform_close"){ activateChatformWidget(); } if(event.data.event == "chatform_evalScript"){ window.eval(event.data.script) } if(event.data.event == "chatform_insertTag"){ body.insertAdjacentHTML( "beforeend", event.data.tag ); event.data.scripts.forEach((item)=>{ eval(item.textContent)}) } if(event.data.event == "chatform_start"){ console.log(event.data.uuId) } if(event.data.event == "chatform_initialized"){ console.log("Aqur Initialized") document.getElementById("chatbotProgressBar").style.width = "100%"; var opacity = function(){ document.getElementById("chatbotProgressBar").style.opacity = "0"; }; setTimeout(opacity, 1000); chatform_initialized = true; if(launch=="auto"){ activateChatformWidget(); } window.dispatchEvent(new CustomEvent("chatform_initialized")); } },false) } setTimeout(take, 0); window.addEventListener("message", (event) => { window.aqur.bind(event) }) // const observer = new MutationObserver(() => { // window.aqur.bindData(); // }); //observer.observe(document.body, { // childList: true, // attributes: true, // subtree: true, //}); //aqur bind start window.aqur = {} window.aqur.debug = false; window.aqur.save = (key, value) => { window.aqur[key] = value; // You can access data anytime using window.aqur.XXX } window.aqur.bind = (event) => { if (event.data.event == "name") { window.aqur.setLastName(event.data.value.values[0].value) window.aqur.setFirstName(event.data.value.values[1].value) window.aqur.setLastNameKana(event.data.value.values[2].value) window.aqur.setFirstNameKana(event.data.value.values[3].value) window.aqur.save("LastName", event.data.value.values[0].value) window.aqur.save("FirstName", event.data.value.values[1].value) window.aqur.save("LastNameKana", event.data.value.values[2].value) window.aqur.save("FirstNameKana", event.data.value.values[3].value) } if (event.data.event == "tel") { window.aqur.setTel(event.data.value.values[0].value) window.aqur.save("Tel", event.data.value.values[0].value) } if (event.data.event == "birthday") { window.aqur.setBirthdayYear(Number(event.data.value.values[0].value)) window.aqur.setBirthdayMonth(Number(event.data.value.values[1].value)) window.aqur.setBirthdayDay(Number(event.data.value.values[2].value)) window.aqur.save("Year", event.data.value.values[0].value) window.aqur.save("Month", event.data.value.values[1].value) window.aqur.save("Day", event.data.value.values[2].value) } if (event.data.event == "gender") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if(item){ window.aqur.setGender(item.value) window.aqur.save("Gender", item.value) } } if (event.data.event == "email") { window.aqur.setEmail(event.data.value.values[0].value) window.aqur.save("Email", event.data.value.values[0].value) } if (event.data.event == "password") { if(event.data.value.values[0].value){ window.aqur.save("password", event.data.value.values[0].value) window.aqur.fillInput('#password', event.data.value.values[0].value) } } } //性別選択後の再レンダリング対策 window.aqur.bindData = () => { if (window.aqur.LastName) { window.aqur.fillInput('#familyName', window.aqur.LastName); } if (window.aqur.FirstName) { window.aqur.fillInput('#givenName', window.aqur.FirstName); } if (window.aqur.LastNameKana) { window.aqur.fillInput('#familyNameKana', window.aqur.LastNameKana); } if (window.aqur.FirstNameKana) { window.aqur.fillInput('#givenNameKana', window.aqur.FirstNameKana); } if (window.aqur.Tel) { window.aqur.fillInput('#telNumber', window.aqur.Tel.replace(/-/g, '')); } if (window.aqur.Year) { window.aqur.fillInput('input[name="year"]', window.aqur.Year); } if (window.aqur.Month) { window.aqur.fillInput('input[name="month"]', window.aqur.Month); } if (window.aqur.Day) { window.aqur.fillInput('input[name="day"]', window.aqur.Day); } if (window.aqur.Email) { window.aqur.fillInput('#email', window.aqur.Email); } if (window.aqur.password) { window.aqur.fillInput('#password', window.aqur.password); } }; //Binding Method for WaterStand window.aqur.setLastName = (value) => { window.aqur.debug && console.log("debug setLastName", value); window.aqur.fillInput('#familyName', window.aqur.LastName) } window.aqur.setFirstName = (value) => { window.aqur.debug && console.log("debug setFirstName", value); window.aqur.fillInput('#givenName', window.aqur.FirstName) } window.aqur.setLastNameKana = (value) => { window.aqur.debug && console.log("debug setLastNameKana", value); window.aqur.fillInput('#familyNameKana', value) } window.aqur.setFirstNameKana = (value) => { window.aqur.debug && console.log("debug setFirstNameKana", value); window.aqur.fillInput('#givenNameKana', value) } window.aqur.setPostalCode = (value) => { window.aqur.debug && console.log("debug setPostalCode", value); window.aqur.fillInput('#zipcode', value) function callLater() { window.aqur.setCity(window.aqur.City) window.aqur.setStreet(window.aqur.Street) window.aqur.setBuilding(window.aqur.Building) } setTimeout(callLater, 1000); } window.aqur.setPref = (value) => { window.aqur.debug && console.log("debug setPref", value); window.aqur.chooseSelectBoxLabel('#address1', value) } window.aqur.setCity = (value) => { window.aqur.debug && console.log("debug setCity", value); window.aqur.fillInput('#address2', splitAddress(value).city) window.aqur.fillInput('#address3', splitAddress(value).town) } window.aqur.setStreet = (value) => { window.aqur.debug && console.log("debug setStreet", value); window.aqur.fillInput('#e_9943, #e_10111', value) } window.aqur.setBuilding = (value) => { window.aqur.debug && console.log("debug setBuilding", value); window.aqur.fillInput('#e_9944, #e_10112', value) } window.aqur.setTel = (value) => { window.aqur.debug && console.log("debug setTel", value); window.aqur.fillInput('#telNumber', value.replace(/-/g,'')) } window.aqur.setEmail = (value) => { window.aqur.debug && console.log("debug setEmail", value); window.aqur.fillInput('#email', value) } window.aqur.setGender = (value) => { window.aqur.debug && console.log("debug setGender", value); if (value == '1') { if (document.querySelector('.sc-dQylYw').innerText == '男性AGA') { document.querySelector('.sc-dQylYw').click() } else { return } } else if (value == '2') { if (document.querySelector('.sc-dQylYw').innerText == '女性AGA') { document.querySelector('.sc-dQylYw').click() } else { return } } } window.aqur.setBirthdayYear = (value) => { window.aqur.debug && console.log("debug setBirthdayYear", value); window.aqur.fillInput('input[name="year"]', value) } window.aqur.setBirthdayMonth = (value) => { window.aqur.debug && console.log("debug setBirthdayMonth", value); window.aqur.fillInput('input[name="month"]', value) } window.aqur.setBirthdayDay = (value) => { window.aqur.debug && console.log("debug setBirthdayDay", value); window.aqur.fillInput('input[name="day"]', value) } //Helper Method window.aqur.getCheckedOptionSA = (options) => { var rtn = options.find((v) => v.checked) return rtn } window.aqur.getCheckedOptionMA = (options) => { var checkedOptions = options.filter((v) => v.checked); var rtn = checkedOptions.map((v) => v.value); return rtn.join(", "); } //You can add more helper here (they shold be in window.aqur.xxx) window.aqur.waitForElement = (selectors, timeout = 5000) => { return new Promise((resolve, reject) => { const interval = 100; let elapsedTime = 0; const checkExistence = () => { for (const selector of selectors) { const element = document.querySelector(selector); if (element) { resolve(element); return; } } elapsedTime += interval; if (elapsedTime >= timeout) { reject(new Error(`None of the elements with selectors "${selectors.join(', ')}" were found within the timeout`)); } else { setTimeout(checkExistence, interval); } }; checkExistence(); }); }; window.aqur.fillInput = (selector, value) => { const inputElement = document.querySelector(selector); if (inputElement) { const nativeInputValueSetter = Object.getOwnPropertyDescriptor( window.HTMLInputElement.prototype, "value" ).set; nativeInputValueSetter.call(inputElement, value); const inputEvent = new Event('input', { bubbles: true, cancelable: true }); inputElement.dispatchEvent(inputEvent); const changeEvent = new Event('change', { bubbles: true, cancelable: true }); inputElement.dispatchEvent(changeEvent); inputElement.blur(); document.body.focus(); } else { console.log("Element not found for selector:", selector); } }; 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); } }; function splitAddress(address) { // 正規表現で市区郡を抽出(「市」「区」「郡」で終わるものを対象) const cityPattern = /([^市区郡]+[市区郡])/; const match = address.match(cityPattern); if (!match) { // 市区郡がない場合、全体を city に入れ、town に「不明」を設定 return { city: address.trim(), town: "不明" }; } const city = match[1]; // 市区郡以降の部分を抽出 const remaining = address.replace(city, '').trim(); return { city: city || null, town: remaining || "不明" }; } }else{ function activateChatformWidget(){ document.body.classList.remove("chat_open"); const w = document.querySelector('.chatform_widget'); w.classList.add("close"); } activateChatformWidget() } } executeIfConditionsMet(); let previousURL = window.location.href; function handleURLChange() { const currentURL = window.location.href; if (currentURL !== previousURL) { previousURL = currentURL; executeIfConditionsMet(); } } // 履歴APIメソッドのオーバーライド const originalPushState = history.pushState; history.pushState = function (...args) { originalPushState.apply(this, args); handleURLChange(); }; const originalReplaceState = history.replaceState; history.replaceState = function (...args) { originalReplaceState.apply(this, args); handleURLChange(); }; // 戻る・進むの検知 window.addEventListener('popstate', handleURLChange); }())