(function() { var take = function() { if(/stg.cbon.co.jp/.test(window.location.href) || /pr.aqur.com/.test(window.location.href) || /www.cbon.co.jp/.test(window.location.href)){ let chatformSentOccurred = false; //Inserted Start ! var vframe; document.addEventListener("DOMContentLoaded", () => { //console.log("DOMContentLoaded") }) window.addEventListener("chatform_initialized", (event) => { if(/stg.cbon.co.jp/.test(window.location.href) || /www.cbon.co.jp/.test(window.location.href)){ //console.log('staging') const chatformBtnElement = document.querySelector('.chatformBtn'); if (chatformBtnElement) { const anchorTags = chatformBtnElement.querySelectorAll('a'); anchorTags.forEach(anchor => { anchor.addEventListener('click', function(event) { if (!chatformSentOccurred) { event.preventDefault(); } }); }); } } createVframe() }) function createVframe(){ 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("https://www.cbon.co.jp/net/reserveform/entry.aspx"); //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 url = new URL(e.target.src) switch (url.origin) { case 'https://www.example.com': window.location.href= url.href break; default: } // Metaピクセルコードをiframe内に挿入 const metaPixelCode = ` `; vframe.contentDocument.body.insertAdjacentHTML('beforeend', metaPixelCode); }) 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="250px" vframe.style.display= "block"; vframe.style.zIndex= 100; vframe.style.position= "fixed"; vframe.style.backgroundColor= "white"; vframe.style.bottom=0; vframe.style.left=0; vframe.style.boxSizing="border-box"; vframe.style.border="2px solid red"; vframe.scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" }); var param={ event: "chatform_vframe_debug" } vframe.contentWindow.postMessage(param, "*"); } } //Inserted End 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 = "cbn"; 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', "7cf31542-9d5a-4ff8-b08f-e1a2a72929ef"); 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.14.134.188"); REF.searchParams.append('ref', REF.href); REF.searchParams.append('path', REF.pathname); //for UI REF.searchParams.append('CLIENT_ID', 'PR'); REF.searchParams.append('BASE_URL', 'https://pr.aqur.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'); 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"){ function applyMediaQueryStyle() { var element = document.querySelector('.chatform_widget'); if (element) { if (window.innerHeight <= 600) { element.style.height = '450px'; } else if (window.innerHeight >= 600 && window.innerHeight <= 700) { element.style.height = '500px'; } else { element.style.height = '600px'; } } } applyMediaQueryStyle(); window.addEventListener('resize', applyMediaQueryStyle); 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 } }); document.dispatchEvent(new CustomEvent("chatform_widget_creation_complete")); }; setTimeout(creationComplete, 0); window.addEventListener("message", (event) => { if(event.data.event == "redirect_thankPage"){ //console.log("redirect_chatform", event.data.event) const target = document.querySelector('.chatform_widget'); var param={ event: "chatform_clear", text: event.data.text } target.contentWindow.postMessage(param, "*"); } if(event.data.event == "chatform_vframe_bind"){ //console.log("chatform_vframe_bind",event.data.project) var project = event.data.project; var param={ event: "chatform_bindForm", data:project } vframe.contentWindow.postMessage(param, "*"); } if(event.data.event == "chatform_vframe_submit"){ console.log("chatform_vframe_submit") var project = event.data.project; var param={ event: "chatform_bindFormSubmit", data:project } vframe.contentWindow.postMessage(param, "*"); } 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_bindFormdone"){ //console.log("chatform_bindFormdone") const target = document.querySelector('.chatform_widget'); var param={ event: "chatform_bindFormdone" } target.contentWindow.postMessage(param, "*"); } if(event.data.event == "chatform_close"){ //console.log("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")); const iframe = document.querySelector('.chatform_widget'); var contentWindow = iframe.contentWindow; if(contentWindow){ var shareProductList = [] var mobileCheck = document.querySelector("body").classList.contains("mobile"); if(mobileCheck){ var li = document.querySelectorAll(".repOrderFormProductRow"); li.forEach((item)=>{ var value = item.querySelector("[value=rbnSelectProduct]").value var name = item.querySelector(".itemlist").textContent var price = item.querySelector('.itemprice').textContent var quantity = item.querySelector('#ctl00_cphMain_repOrderRowForm_ctl00_OrderSuryo_ddlNum').value var subTotal = item.querySelector('#ctl00_cphMain_repOrderRowForm_ctl00_lblSubTotal').textContent var obj ={ value:value, label:name, price:price, quantity:quantity, subTotal:subTotal, checked:false, name:"orderSelect", supplement:"", } shareProductList.push(obj) }) }else{ var li = document.querySelectorAll(".repOrderFormProductRow"); li.forEach((item)=>{ var value = item.querySelector("[value=rbnSelectProduct]").value var name = item.querySelector(".itemlist").textContent var price = item.querySelector('.itemprice').textContent var quantity = item.querySelector('.itemcount').value var subTotal = item.querySelector('.itemsubtitle').textContent var obj ={ value:value, label:name, price:price, quantity:quantity, subTotal:subTotal, checked:false, name:"orderSelect", supplement:"", } shareProductList.push(obj) }) } contentWindow.postMessage( { type:"shareProductList", data:shareProductList }, "*"); } } },false) } } setTimeout(take, 0); }())