(function() { const urlParams = new URLSearchParams(window.location.search); const isChat = urlParams.get('is_chat') === 'true'; if (isChat) { var take = function() { console.log("chatform clinicfor2") window.AqurBaseURL = 'https://bleach-server-e7d55b4bcbab.herokuapp.com'; var vframe; let latestTelemedicineSlot = null; // 親フレームのURLからSTG環境かどうかを判定 const isStg = window.location.hostname.includes('stg') || window.location.href.includes('stg'); const TELEMEDICINE_BASE_URL = isStg ? 'https://stg-miniapp.clinicfor.life/telemedicine/sign_up_reservation/' : 'https://miniapp.clinicfor.life/telemedicine/sign_up_reservation/'; const TELEMEDICINE_DEPARTMENT = 'telemedicine_aga'; const normalizeSlotPayload = (slot) => { if (!slot) { return null; } if (typeof slot === 'string') { try { return JSON.parse(slot); } catch (error) { return { label: slot }; } } return slot; }; const computeIsoWithOffset = (payload) => { if (!payload) { return null; } if (payload.isoWithOffset) { return payload.isoWithOffset; } if (payload.dateKey && payload.slot) { return `${payload.dateKey}T${payload.slot}:00+09:00`; } return null; }; const buildTelemedicineUrl = (slot, fallback) => { const payload = normalizeSlotPayload(slot) || normalizeSlotPayload(fallback); const url = new URL(TELEMEDICINE_BASE_URL); url.searchParams.set('department', TELEMEDICINE_DEPARTMENT); url.searchParams.set('is_chat', 'true'); const iso = computeIsoWithOffset(payload); if (iso) { url.searchParams.set('date', iso); } return { url: url.toString(), payload }; }; const applySelectedSlotToUrl = (urlObj, payload) => { const iso = computeIsoWithOffset(payload); if (iso) { urlObj.searchParams.set('date', iso); } }; window.addEventListener("chatform_initialized", (event) => { createAqurBinding() }) window.addEventListener("createVframe", (event) => { //console.log("createVframe") const incomingSlot = event?.detail?.slot || event?.detail; const normalizedIncomingSlot = normalizeSlotPayload(incomingSlot); if (normalizedIncomingSlot) { latestTelemedicineSlot = normalizedIncomingSlot; } const { url: baseUrl, payload } = buildTelemedicineUrl(normalizedIncomingSlot, latestTelemedicineSlot); let activePayload = payload || latestTelemedicineSlot; let urlToUse = baseUrl; // Get parameters from location.href and add to urlToUse const currentUrl = new URL(window.location.href); const urlToUseObj = new URL(urlToUse); // Copy all search parameters from current URL to urlToUse currentUrl.searchParams.forEach((value, key) => { if (['department', 'is_chat', 'date'].includes(key)) { return; } urlToUseObj.searchParams.set(key, value); }); applySelectedSlotToUrl(urlToUseObj, activePayload); if (!activePayload) { activePayload = normalizeSlotPayload(latestTelemedicineSlot); applySelectedSlotToUrl(urlToUseObj, activePayload); } urlToUse = urlToUseObj.toString(); if (activePayload && window.aqur && typeof window.aqur.save === "function") { window.aqur.save('TelemedicineSlot', activePayload); } window.aqur.vframe=vframe; createVframe(urlToUse); }) function createVframe(linkURL){ const currentLocation = new URL(window.location.href); const userChatbot = currentLocation.searchParams.get('usechatbot') if(userChatbot){ return } const refUrl = new URL(linkURL); refUrl.searchParams.append('chatbot', 1); refUrl.searchParams.append('usechatbot', "no"); refUrl.searchParams.append('chatbottype', "aqur"); const finalSrc = refUrl.toString(); if (vframe && document.body.contains(vframe)) { if (vframe.src !== finalSrc) { vframe.src = finalSrc; } if (window.aqur && typeof window.aqur === 'object') { window.aqur.vframe = vframe; } return; } vframe = document.createElement("iframe"); vframe.id="vframe"; vframe.sandbox.add('allow-storage-access-by-user-activation'); vframe.sandbox.add('allow-forms'); vframe.sandbox.add('allow-top-navigation'); vframe.sandbox.add('allow-scripts'); vframe.sandbox.add('allow-same-origin'); vframe.sandbox.add('allow-modals') vframe.width="1px"; vframe.height="1px"; vframe.src = finalSrc; document.body.appendChild(vframe); if (window.aqur && typeof window.aqur === 'object') { window.aqur.vframe = vframe; } let vfmode = currentLocation.searchParams.get('vfmode') vframe.addEventListener("load", (e) => { try { var url = new URL(vframe.contentWindow.location.href); console.log("vframe loaded:", url.href); if (vfmode!="debug") { vframe.width="1px"; vframe.height="1px"; } var insertDDP =()=>{ const existingScript = vframe.contentWindow.document.querySelector(`script[src*="/yhj/client/ddp"]`); if (!existingScript) { var script = vframe.contentWindow.document.createElement('script'); script.src = `${window.AqurBaseURL}/clinicfor2/client/ddp`; vframe.contentWindow.document.head.appendChild(script); console.log("ddp inserted") setTimeout(() => { window.aqur.reset(); console.log("reset") }, 3000); } else { console.log("ddp script already exists") } } switch (url.origin) { default: insertDDP() } var reset = () => { //console.log("reset") const target = document.querySelector('.chatform_widget'); if(target){ var param={ event: "chatform_vframeLoaded", url:url.href } target.contentWindow.postMessage(param, "*"); } }; setTimeout(reset, 1500); const interval = setInterval(() => { let authenticatedcode = vframe.contentWindow.document.querySelector('input[name="code"]'); if (authenticatedcode) { activateChatformWidget() vframe.width="100%"; vframe.height="100%"; vframe.style.display= "block"; vframe.style.zIndex= 9999999999; vframe.style.position= "fixed"; vframe.style.backgroundColor= "white"; vframe.style.top=0; vframe.style.left=0; vframe.style.border="none"; clearInterval(interval); } }, 1000); const interval2 = setInterval(() => { let accountMessage = vframe.contentWindow.document.body && vframe.contentWindow.document.body.innerText && vframe.contentWindow.document.body.innerText.includes('すでにアカウントをお持ちのため'); if (accountMessage) { const target = document.querySelector('.chatform_widget'); var param={ event: "chatform_bindFormErrorFound", text: "すでにアカウントをお持ちのため、ログインを行い予約を完了してください" } target.contentWindow.postMessage(param, "*"); setTimeout(() => { activateChatformWidget() vframe.width="100%"; vframe.height="100%"; vframe.style.display= "block"; vframe.style.zIndex= 9999999999; vframe.style.position= "fixed"; vframe.style.backgroundColor= "white"; vframe.style.top=0; vframe.style.left=0; vframe.style.border="none"; }, 3000); clearInterval(interval2); } }, 1000); } catch (error) { if (error instanceof DOMException && error.name === 'SecurityError' && location.href != "localhost:8080") { console.log("クロスオリジンアクセスエラーが発生しました:", error.message); if (!location.href.includes("blc.aqur.com") && !location.href.includes("localhost:8080")) { setTimeout(() => { vframe.width="100%"; vframe.height="100%"; vframe.style.display= "block"; vframe.style.zIndex= 9999999999; vframe.style.position= "fixed"; vframe.style.backgroundColor= "white"; vframe.style.top=0; vframe.style.left=0; vframe.style.border="none"; }, 3000); } return; } throw error; } }) if(vfmode=="debug"){ vframe.classList.add('debug'); vframe.scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" }); if(device=="mobile"){ vframe.height="50%" } const target = document.querySelector('.chatform_widget'); if (target) { target.style.height = "50%"; // 高さを50%に設定 } var param={ event: "chatform_vframe_debug" } vframe.contentWindow.postMessage(param, "*"); } } //Inserted End //Default function render(template, data){ //console.log("render",template,data) return template.replace(/{{(.*?)}}/g, (match) => { return data[match.split(/{{|}}/).filter(Boolean)[0].trim()] }) } function activateChatformWidget(){ 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 = "clinicfor2"; const target = "production"; const mode = "release"; const device = JSON.parse("false".toLowerCase())?"mobile":"pc"; var 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', "e53041e0-9e88-4074-8b3d-b40ec140ac1d"); 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', "216.73.216.163"); 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)); let search = REF.search.slice(1) //console.log(search) launch = params.get('launch'); let widget = render( ''+ '', { device : device, client : client, search : (search)?"&"+search:"" } ); let creationComplete = function(){ 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'); } 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.closest('.bot_open ') || event.target.classList.contains("bot_open") || event.target.closest('.rc_openBtn ') || event.target.classList.contains("rc_openBtn") || event.target.closest('form[action*="wakan.shop"]') || event.target.id == "chatform_widget_cancelbtn" ) { activateChatformWidget() filterid = event.target.closest(".chatformBtn").dataset.filterid } }); document.dispatchEvent(new CustomEvent("chatform_widget_creation_complete")); }; // 重複実行防止フラグ let creationCompleteExecuted = false; // 安全なcreationComplete実行関数 const safeCreationComplete = function() { if (creationCompleteExecuted) { return; // 既に実行済みの場合は何もしない } creationCompleteExecuted = true; creationComplete(); }; // DOMContentLoadedイベントでcreationCompleteを実行 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', safeCreationComplete); } else { safeCreationComplete(); } // 30秒後に実行されていない場合は強制実行 setTimeout(() => { if (!creationCompleteExecuted) { console.log('creationCompleteが30秒以内に実行されませんでした。強制実行します。'); safeCreationComplete(); } }, 30000); window.addEventListener("message", (event) => { //console.log("event.data.event", event) if(event.data.event == "chatform_start"){ console.log(event.data.uuId) } 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_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; activateChatformWidget(); window.dispatchEvent(new CustomEvent("chatform_initialized")); } if(event.data.event == "chatform_sent_line"){ //console.log("chatform_sent_line") 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-line'); if (sendButton !== null) { setTimeout(() => { sendButton.click(); }, 1000); } else { console.error('Element with ID ".gtm-sign-up-reservation-line" not found.'); } } if(event.data.event == "chatform_sent_google"){ //console.log("chatform_sent_google") 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.querySelectorAll("button")].find( el => el.textContent.includes("Googleアカウントを使う") ); if (sendButton !== null) { setTimeout(() => { sendButton.click(); }, 1000); } else { console.error('Element with ID "Googleアカウントを使う" not found.'); } } //通常注文確定ボタン押下 if(event.data.event == "chatform_sent"){ //console.log("chatform_sent") var param={ event: "chatform_bindFormSubmit" } vframe.contentWindow.postMessage(param, "*"); } if(event.data.event == "chatform_bindFormConversion"){ //console.log("chatform_bindFormConversion") const target = document.querySelector('.chatform_widget'); var param={ event: "chatform_bindFormConversion", } target.contentWindow.postMessage(param, "*"); } if(event.data.event == "tryReset"){ window.aqur.reset() } if(event.data.event == "clinicfor2_slot_selected"){ const normalizedSlot = normalizeSlotPayload(event.data.slot); if (normalizedSlot) { latestTelemedicineSlot = normalizedSlot; } } if(event.data.event == "CLINICFOR2Calender"){ const slotValue = event.data.value?.values?.find((v) => v.id === "CLINICFOR2Calender")?.value; const normalizedSlot = normalizeSlotPayload(slotValue); if (normalizedSlot) { latestTelemedicineSlot = normalizedSlot; } } if(event.data.event == "createVframe"){ const incomingSlot = event.data?.slot; const normalizedIncomingSlot = normalizeSlotPayload(incomingSlot); if (normalizedIncomingSlot) { latestTelemedicineSlot = normalizedIncomingSlot; } const { url: baseUrl, payload } = buildTelemedicineUrl(normalizedIncomingSlot, latestTelemedicineSlot); let activePayload = payload || latestTelemedicineSlot; let urlToUse = baseUrl; // Get parameters from location.href and add to urlToUse const currentUrl = new URL(window.location.href); const urlToUseObj = new URL(urlToUse); // Copy all search parameters from current URL to urlToUse currentUrl.searchParams.forEach((value, key) => { if (['department', 'is_chat', 'date'].includes(key)) { return; } urlToUseObj.searchParams.set(key, value); }); applySelectedSlotToUrl(urlToUseObj, activePayload); if (!activePayload) { activePayload = normalizeSlotPayload(latestTelemedicineSlot); applySelectedSlotToUrl(urlToUseObj, activePayload); } urlToUse = urlToUseObj.toString(); if (activePayload && window.aqur && typeof window.aqur.save === "function") { window.aqur.save('TelemedicineSlot', activePayload); } window.aqur.vframe = vframe; createVframe(urlToUse); } if (window.aqur && typeof window.aqur.bind === "function") { window.aqur.bind(event) } },false) function createAqurBinding(){ //console.log("AqurBindingCreated") //aqur bind start window.aqur = {} window.aqur.debug = false; window.aqur.save = (key, value) => { window.aqur[key] = value; } window.aqur.reset = () => { //console.log("do reset",window.aqur) window.aqur.setLastName(window.aqur.LastName) window.aqur.setFirstName(window.aqur.FirstName) window.aqur.setLastNameKana(window.aqur.LastNameKana) window.aqur.setFirstNameKana(window.aqur.FirstNameKana) window.aqur.setTel(window.aqur.Tel) window.aqur.setBirthdayYear(window.aqur.Year) window.aqur.setBirthdayMonth(window.aqur.Month) window.aqur.setBirthdayDay(window.aqur.Day) window.aqur.setEmail(window.aqur.Email) window.aqur.setPassword(window.aqur.Password) } window.aqur.bind = (event) => { //console.log("waq",event.data.event) if(event.data.track){ var track = { pid:event.data.track.pid, sid:event.data.track.sid, uuId:event.data.track.uuId, customId:"conversion" } window.aqur.setTrack(track); window.aqur.save("Track", track); } if (event.data.event == "name") { var FullName = event.data.value.values[0].value + event.data.value.values[1].value + event.data.value.values[2].value + event.data.value.values[3].value if(FullName!=window.aqur.FullName){ 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) window.aqur.save("FullName", event.data.value.values[0].value + event.data.value.values[1].value + event.data.value.values[2].value + 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 == "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") { window.aqur.setPassword(event.data.value.values[0].value) window.aqur.save("Password", event.data.value.values[0].value) } } window.aqur.setTrack = (value) => { window.aqur.debug && console.log("debug setTrack"); localStorage.setItem('aqur', JSON.stringify(value)); } window.aqur.setLastName = (value) => { window.aqur.debug && console.log("debug setLastName", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setLastName",value:value}, "*"); } } window.aqur.setFirstName = (value) => { window.aqur.debug && console.log("debug setFirstName", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setFirstName",value:value}, "*"); } } window.aqur.setLastNameKana = (value) => { window.aqur.debug && console.log("debug setLastNameKana", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setLastNameKana",value:value}, "*"); } } window.aqur.setFirstNameKana = (value) => { window.aqur.debug && console.log("debug setFirstNameKana", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setFirstNameKana",value:value}, "*"); } } window.aqur.setTel = (value) => { window.aqur.debug && console.log("debug setTel", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setTel",value:value}, "*"); } } window.aqur.setBirthdayYear = (value) => { window.aqur.debug && console.log("debug setBirthdayYear", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setBirthdayYear",value:value}, "*"); } } window.aqur.setBirthdayMonth = (value) => { window.aqur.debug && console.log("debug setBirthdayMonth", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setBirthdayMonth",value:value}, "*"); } } window.aqur.setBirthdayDay = (value) => { window.aqur.debug && console.log("debug setBirthdayDay", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setBirthdayDay",value:value}, "*"); } } window.aqur.setEmail = (value) => { window.aqur.debug && console.log("debug setEmail", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setEmail",value:value}, "*"); } } window.aqur.setPassword = (value) => { window.aqur.debug && console.log("debug setPassword", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setPassword",value: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(", "); } } } setTimeout(take, 0); } }())