function BixBot_Start(OpenBixBotWidget) { const token = localStorage.getItem('bixbot_token') || ''; const xhr = new XMLHttpRequest(); xhr.open('GET', `https://bixbot.ir/api/WidgetTokenGenerator/460bc3e8-1b84-4d8b-95b4-e2fc0a2c6e96?token=${token}`, true); xhr.responseType = 'json'; xhr.onload = function () { if (xhr.status === 200) { const response = xhr.response; if (response.succeeded) { document.querySelectorAll('.BixBot_Extra_Element').forEach(el => el.remove()); try{ StopBixBotSocketConnection() } catch{} localStorage.setItem('bixbot_token', response.data || ''); try { var script = document.createElement('script'); script.setAttribute('src', `https://bixbot.ir/socket.js?token=${localStorage.getItem('bixbot_token')}`); script.setAttribute('class', `BixBot_Extra_Element`); document.body.appendChild(script) } catch (error) { } try { var script = document.createElement('script'); script.setAttribute('src', `https://bixbot.ir/widget.js?token=${localStorage.getItem('bixbot_token')}`); script.setAttribute('class', `BixBot_Extra_Element`); if(OpenBixBotWidget){ script.onload = function () { setTimeout(() => { var chatButton = document.getElementById('ChatWidgetButtonImage'); if (chatButton) { chatButton.click(); } else { console.warn('دکمه ChatWidgetButtonImage پیدا نشد!'); } setTimeout(() => { var elements = document.querySelectorAll(`#ChatWidgetButtonImage`); if (elements.length > 1) { document.querySelectorAll('.BixBot_Extra_Element').forEach(el => el.remove()); try{ StopBixBotSocketConnection() } catch{} BixBot_Start(OpenBixBotWidget); } }, 500); }, 100); }; } document.body.appendChild(script) } catch { } } else { console.log('به هنگام اتصال به وبسایت BixBot خطایی رخ داده است.') } } else { console.log('خطا در دریافت پاسخ از سرور') } }; xhr.onerror = function () { console.log('به هنگام اتصال به وبسایت BixBot خطایی رخ داده است.') }; xhr.send() } BixBot_Start();