(function() { var take = function() { var isAutoLaunchMode = false; var isLoadingScreenMode = true; let LOC = new URL(window.location); let p = LOC.searchParams.get('p') var screenURL; var btnUrl; if(p){ //omoikomendy if (p.includes('omoiko')) { btnUrl = "https://res.cloudinary.com/dts6mbw86/image/upload/v1705456567/aqur/tl/omoiko/07/launchBtn_pgjpdm.png" screenURL = 'https://res.cloudinary.com/dts6mbw86/image/upload/v1728437654/aqur/tl/omoiko/wait-img_omoiko_jpwnua.png'; } if(p=="omoiko_botc_07") { isAutoLaunchMode = true isLoadingScreenMode = true } if(p=="omoiko_botc_19") { isAutoLaunchMode = false isLoadingScreenMode = true } } if(isLoadingScreenMode){ const div = document.createElement('div'); div.id = 'loading-div'; // idを追加 div.style.position = 'fixed'; div.style.zIndex = 999999999999; div.style.top = '0'; div.style.left = '0'; div.style.width = '100%'; div.style.height = '100%'; div.style.backgroundColor = 'white'; div.style.padding = '20px'; div.style.display = 'flex'; div.style.justifyContent = 'center'; div.style.alignItems = 'center'; const img = document.createElement('img'); img.src = screenURL; img.alt = 'Centered Image'; img.style.maxWidth = '100%'; img.style.height = 'auto'; div.appendChild(img); document.body.appendChild(div); } createAqurBinding() window.addEventListener("chatform_initialized", (event) => { if(isLoadingScreenMode){ const loadingDiv = document.getElementById('loading-div'); if (loadingDiv) { loadingDiv.remove(); } if(isAutoLaunchMode){ activateChatformWidget() } }else{ if(isAutoLaunchMode){ activateChatformWidget() } } window.aqur.vframe=vframe; window.aqur.reset() }) var vframe; document.addEventListener("DOMContentLoaded", () => { //console.log("DOMContentLoaded") var launchBtn = document.createElement("img"); launchBtn.src=btnUrl; launchBtn.classList.add("launchBtn"); launchBtn.classList.add("chatformBtn"); document.body.appendChild(launchBtn); var elements = document.querySelectorAll('.bot_open'); // 各elementに対して新しいclassを追加 elements.forEach(function(element) { element.classList.add('chatformBtn'); }); const order_name01 = document.querySelector('#order_name01'); var isLogin = !order_name01 if(isLogin){ console.log("login") //const iframe = document.querySelector('.chatform_widget'); //iframe.remove(); const lpshoppingcolumn = document.querySelector('#lpshoppingcolumn, #smp-lpshoppingcolumn'); lpshoppingcolumn.style.display= "none!important"; lpshoppingcolumn.scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" }); localStorage.removeItem("chatform"); const launchBtn = document.querySelector('.launchBtn'); launchBtn.style.display= "none"; const loadingDiv = document.getElementById('loading-div'); if (loadingDiv) { loadingDiv.remove(); } } var url = new URL(window.location.href); let userChatbot = url.searchParams.get('usechatbot') if(userChatbot){ 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.width="1px"; vframe.height="1px"; var REF = new URL(window.location.href); REF.searchParams.append('usechatbot', "no"); vframe.src = REF; document.body.appendChild(vframe); vframe.addEventListener("load", (e) => { //console.log(e.target.src) var insertDDP =()=>{ var script = vframe.contentWindow.document.createElement('script'); //script.src = "http://localhost:8080/client/ddp"; if (window.location.hostname === 'localhost') { script.src = "http://localhost:8080/client/ddp"; } else { script.src = "https://tl.aqur.com/client/ddp"; } //console.log("vframe ddp_",script.src) vframe.contentWindow.document.head.appendChild(script); } var url = new URL(vframe.contentWindow.location.href) //console.log(url.href) const target = document.querySelector('.chatform_widget'); if(target){ var param={ event: "chatform_vframeLoaded", url:url.href } target.contentWindow.postMessage(param, "*"); } switch (url.origin) { default: insertDDP() } }) let vfmode = url.searchParams.get('vfmode') if(vfmode=="debug"){ const lpshoppingcolumn = document.querySelector('#lpshoppingcolumn, #smp-lpshoppingcolumn'); if(lpshoppingcolumn){ lpshoppingcolumn.style.display= "block"; } vframe.width="100%"; vframe.height="350px" vframe.style.display= "block"; vframe.style.zIndex= 1000000; vframe.style.position= "fixed"; vframe.style.backgroundColor= "white"; vframe.style.top=0; vframe.style.boxSizing="border-box"; vframe.style.border="2px solid red"; 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, "*"); } }) //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("chatbot is not ready yet") return } const w = document.querySelector('.chatform_widget'); w.classList.toggle("close"); w.classList.toggle("normal"); if(w.classList.contains("close")){ document.body.classList.remove("chat_open"); }else{ document.body.classList.add("chat_open"); } } var chatform_initialized = false const pid = "omik"; 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', "bbf732a6-5572-4b3c-aa8a-64ee50791e56"); 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.128.172.168"); REF.searchParams.append('ref', REF.href); REF.searchParams.append('path', REF.pathname); //for UI REF.searchParams.append('CLIENT_ID', 'TL'); REF.searchParams.append('BASE_URL', 'https://trustline-server-0fc1e9a8c6c9.herokuapp.com'); REF.searchParams.append('HEADER_LABEL', 'ご購入はこちら'); REF.searchParams.append('HEADER_BG_COLOR', '#fff'); REF.searchParams.append('HEADER_LABEL_COLOR', '#000'); REF.searchParams.append('SHOW_TIMER', 'false'); REF.searchParams.append('ICON_PATH', 'https://res.cloudinary.com/dts6mbw86/image/upload/v1713319985/aqur/common/icon_azvikf.png'); let utm_content = REF.searchParams.get('utm_content') if(utm_content){ let agent = utm_content.substring(utm_content.lastIndexOf("_")+1, utm_content.length) if(agent){ REF.searchParams.append('agent', agent); } } 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); } 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() filterid = event.target.closest(".chatformBtn").dataset.filterid //console.log(event.target.closest(".chatformBtn").dataset.filterid) } }); document.dispatchEvent(new CustomEvent("chatform_widget_creation_complete")); }; setTimeout(creationComplete, 0); window.addEventListener("message", (event) => { /* Default Actions*/ 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("chatform_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")); } //AqurBindng //エラー検知 if(event.data.event == "chatform_bindFormErrorFound"){ //console.log("chatform_bindFormErrorFound") const target = document.querySelector('.chatform_widget'); var param={ event: "chatform_bindFormErrorFound", text:event.data.text } target.contentWindow.postMessage(param, "*"); } //確認画面表示 if(event.data.event == "chatform_vframe_bind"){ //console.log("chatform_vframe_bind") var data = event.data.project; var param={ event: "chatform_vframe_bind", project:data } vframe.contentWindow.postMessage(param, "*"); } //購入ボタン押下 if(event.data.event == "chatform_vframe_submit"){ //console.log("chatform_vframe_submit") localStorage.removeItem('chatformAmazonPay'); var data = event.data.project; var param={ event: "chatform_vframe_submit" } 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", order_id:event.data.order_id, transaction_id:event.data.transaction_id } target.contentWindow.postMessage(param, "*"); } //アップセル成功 if(event.data.event == "chatform_bindFormUpcellComplete"){ //console.log("chatform_bindFormUpcellComplete",event.data) window.location.href=event.data.targetURL; } window.aqur.bind(event) },false) function createAqurBinding(){ //console.log("AqurBindingCreated") //aqur bind start window.aqur = {} window.aqur.debug = true; 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.setPostalCode(window.aqur.PostalCode) window.aqur.setPref(window.aqur.Pref) window.aqur.setCity(window.aqur.City) //window.aqur.setStreet(window.aqur.Street) window.aqur.setBuilding(window.aqur.Building) window.aqur.setTel(window.aqur.Tel) window.aqur.setPaymentMethod(window.aqur.PaymentMethod) window.aqur.setToken(window.aqur.Token) window.aqur.setBirthdayYear(window.aqur.Year) window.aqur.setBirthdayMonth(window.aqur.Month) window.aqur.setBirthdayDay(window.aqur.Day) setTimeout(() => { window.aqur.setCardNumber(window.aqur.CardNumber) window.aqur.setCardExpirationYear(window.aqur.CardExpirationYear) window.aqur.setCardExpirationMonth(window.aqur.CardExpirationMonth) }, "1000"); } window.aqur.bind = (event) => { //console.log("waq",event.data.event) if(event.data.event == "tryReset"){ window.aqur.reset() } 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 == "Address") { var FullAddress = event.data.value.values[0].value + event.data.value.values[1].value + event.data.value.values[2].value + event.data.value.values[3].value + event.data.value.values[4].value; if(FullAddress!=window.aqur.FullAddress){ window.aqur.setPostalCode(event.data.value.values[0].value) window.aqur.setPref(event.data.value.values[1].value) window.aqur.setCity(event.data.value.values[2].value) window.aqur.setBuilding(event.data.value.values[3].value + event.data.value.values[4].value) window.aqur.save("PostalCode", event.data.value.values[0].value) window.aqur.save("Pref", event.data.value.values[1].value) window.aqur.save("City", event.data.value.values[2].value) window.aqur.save("Building", event.data.value.values[3].value + event.data.value.values[4].value) window.aqur.save("FullAddress", event.data.value.values[0].value + event.data.value.values[1].value + event.data.value.values[2].value + event.data.value.values[3].value + event.data.value.values[4].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") { window.aqur.setPassword(event.data.value.values[0].value) window.aqur.setPasswordConfirmation(event.data.value.values[0].value) window.aqur.save("Password", event.data.value.values[0].value) } if (event.data.event == "payment") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if(item){ window.aqur.setPaymentMethod(item.value) window.aqur.save("PaymentMethod", item.value) } } if (event.data.event == "cc") { window.aqur.setCardNumber(event.data.value.values[0].value) window.aqur.setCardExpirationYear(event.data.value.values[1].value) window.aqur.setCardExpirationMonth(event.data.value.values[2].value) window.aqur.setCardCvc(event.data.value.values[3].value) window.aqur.setCardHolderName(event.data.value.values[4].value) window.aqur.save("CardNumber", event.data.value.values[0].value) window.aqur.save("CardExpirationYear", event.data.value.values[1].value) window.aqur.save("CardExpirationMonth", event.data.value.values[2].value) window.aqur.save("CardExpirationCvc", event.data.value.values[3].value) window.aqur.save("CardExpirationHolderName", event.data.value.values[4].value) } if (event.data.event == "mailmagazine") { var d = event.data.value || event.data.data.data var item = window.aqur.getCheckedOptionMA(d.options); window.aqur.setNewsletterSendable(item==="" ? false : true) window.aqur.save("NewsletterSendable", item==="" ? false : true) } if (event.data.event == "couponMethod") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if(item){ window.aqur.setCouponMethod(item.value) } } if (event.data.event == "upsell") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) window.aqur.setProduct(item.value) } if (event.data.event == "deliveryDate") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if(item){ window.aqur.setDeliveryDate(item.value) } } if (event.data.event == "deliveryTime") { var item = window.aqur.getCheckedOptionSA(event.data.value.options) if(item){ window.aqur.setDeliveryTime(item.value) } } if (event.data.event == "token") { window.aqur.setToken(event.data.value.values[0].value) window.aqur.save("Token", event.data.value.values[0].value) } } //Binding Method for リピスト window.aqur.setLastName = (value) => { window.aqur.debug && console.log("debug setLastName"); 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.setPostalCode = (value) => { window.aqur.debug && console.log("debug setPostalCode", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setPostalCode",value:value}, "*"); } } window.aqur.setPref = (value) => { window.aqur.debug && console.log("debug setPref", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setPref",value:value}, "*"); } } window.aqur.setCity = (value) => { window.aqur.debug && console.log("debug setCity_", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setCity",value:value}, "*"); } } window.aqur.setStreet = (value) => { window.aqur.debug && console.log("debug setStreet", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setStreet",value:value}, "*"); } } window.aqur.setBuilding = (value) => { window.aqur.debug && console.log("debug setBuilding", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setBuilding",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.setPaymentMethod = (value) => { window.aqur.debug && console.log("debug setPaymentMethod", value); if(value!=undefined&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setPaymentMethod",value:value}, "*"); } } window.aqur.setToken = (value) => { window.aqur.debug && console.log("debug setToken", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setToken",value:value}, "*"); } } window.aqur.setGender = (value) => { window.aqur.debug && console.log("debug setGender", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setGender",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.setCardNumber = (value) => { window.aqur.debug && console.log("debug setCardNumber", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setCardNumber",value:value}, "*"); } } window.aqur.setCardHolderName = (value) => { window.aqur.debug && console.log("debug setCardHolderName", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setCardHolderName",value:value}, "*"); } } window.aqur.setCardCvc = (value) => { window.aqur.debug && console.log("debug setCardCvc", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setCardCvc",value:value}, "*"); } } window.aqur.setCardExpirationYear = (value) => { window.aqur.debug && console.log("debug setCardExpirationYear", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setCardExpirationYear",value:value}, "*"); } } window.aqur.setCardExpirationMonth = (value) => { window.aqur.debug && console.log("debug setCardExpirationMonth", value); if(value&&window.aqur.vframe){ window.aqur.vframe.contentWindow.postMessage({ event: "setCardExpirationMonth",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); }())