(function () { const currentScript = document.currentScript || (function () { const scripts = document.getElementsByTagName('script'); return scripts[scripts.length - 1]; })(); // const code = currentScript.getAttribute('data-code') || ''; const code = 'WBG000006'; const http = window.location.origin; let iframeReady = false; let iframeCreated = false; function initWidget() { // 버튼 생성 const button = document.createElement('div'); button.id = 'withbot-button'; button.classList.add('withbot-button'); button.innerHTML = ''; document.body.appendChild(button); // 스타일 삽입 const style = document.createElement('style'); style.innerHTML = ` #withbot-button { position: fixed; bottom: 30px; right: 30px; background: url(https://withbot.withjsoft.com/chat-app/img/talk_hv5.gif) no-repeat; background-size: 100%; border-radius: 50%; width: 100px; height: 100px; z-index: 9998; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); transition: background 0.3s; } #withbot-button:hover { } #withbot-iframe { position: fixed; bottom: 20px; right: 20px; width: 400px; height: 600px; border: none; z-index: 9999; display: none; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); } @media (max-width: 480px) { #withbot-iframe { width: 100%; right: 0; bottom: 0; height: 100%; border-radius: 0; } } `; document.head.appendChild(style); // FontAwesome 로드 const fontAwesome = document.createElement('script'); fontAwesome.src = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/js/all.min.js'; document.head.appendChild(fontAwesome); // jQuery 로드 const jquery = document.createElement('script'); jquery.src = 'https://code.jquery.com/jquery-3.6.0.min.js'; document.head.appendChild(jquery); // iframe 메시지 수신 window.addEventListener('message', (event) => { const iframe = document.getElementById('withbot-iframe'); if (iframe && event.source === iframe.contentWindow && event.data?.type === 'ready') { iframeReady = true; iframe.contentWindow.postMessage({ code, http }, '*'); } if (event.data && event.data.type === 'closeIframe') { toggleIframe(); } }); button.addEventListener('click', () => { $.ajax({ type: "POST", url: "https://withbot.withjsoft.com/chat-app/wbtFaqChat.php", dataType: "json", cache: false, data: { wthMode: "faqCompanyCntReq", code, http }, success: function (res) { const iframeSrc = (res.wthCode === "YES") ? "https://withbot.withjsoft.com/chat-app/index_end.html?code=WBG000006" : "https://withbot.withjsoft.com/chat-app/info.html"; if (!iframeCreated) { const iframe = document.createElement('iframe'); iframe.id = 'withbot-iframe'; iframe.src = iframeSrc; iframe.style.display = 'none'; document.body.appendChild(iframe); iframeCreated = true; } else { document.getElementById('withbot-iframe').src = iframeSrc; } toggleIframe(); }, error: function () { alert("회사 정보 확인 중 오류가 발생했습니다."); } }); }); } function toggleIframe() { const iframe = document.getElementById('withbot-iframe'); if (!iframe) return; const isVisible = iframe.style.display === 'block'; iframe.style.display = isVisible ? 'none' : 'block'; if (iframeReady) { iframe.contentWindow.postMessage({ code, http }, '*'); } } // 우클릭 방지 document.addEventListener('contextmenu', function (e) { e.preventDefault(); }); //F12 등 키보드 막기 // document.addEventListener('keydown', function (e) { // if ( // e.key === "F12" || // (e.ctrlKey && e.shiftKey && (e.key === "I" || e.key === "J" || e.key === "C")) || // (e.ctrlKey && e.key === "U") // ) { // e.preventDefault(); // } // }); if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initWidget); } else { initWidget(); } })();