hello this is chatbro loader basicly i try to make it day-night mode compatable for my website,but it loads 2 chats on page 1 white 1 black chat when i switch day/night mode it even loads more i just wanna refresh the current code to make not load any more chats i want 1 chat block! i load chatbro.php using php include tag btw idk if tis the issiue.. here s the code
<script id="chatBroEmbedCode">
function ChatbroLoader(chats, async) {
async = !1 !== async;
var params = {
embedChatsParameters: chats instanceof Array ? chats : [chats],
lang: navigator.language || navigator.userLanguage,
needLoadCode: 'undefined' == typeof Chatbro,
embedParamsVersion: localStorage.embedParamsVersion,
chatbroScriptVersion: localStorage.chatbroScriptVersion
},
xhr = new XMLHttpRequest;
xhr.withCredentials = !0;
xhr.onload = function() {
eval(xhr.responseText);
};
xhr.onerror = function() {
console.error('Chatbro loading error')
};
xhr.open('GET', '//www.chatbro.com/embed.js?' +
btoa(unescape(encodeURIComponent(JSON.stringify(params)))), async);
xhr.send();
}
// Function to get the chat header background color for night mode
function getChatHeaderBackgroundColor() {
var body = document.querySelector('body');
if (body && body.getAttribute('data-style') === 'dark-layout') {
return '#7367f0'; // Replace with your desired dark mode color
} else {
return '#ffffff'; // Default day mode color
}
}
// Function to get the chat body background color for night mode
function getChatBodyBackgroundColor() {
var body = document.querySelector('body');
if (body && body.getAttribute('data-style') === 'dark-layout') {
return '#1F2937'; // Replace with your desired dark mode body color
} else {
return '#ffffff'; // Default day mode color
}
}
// Function to get the chat input background color for night mode
function getChatInputBackgroundColor() {
var body = document.querySelector('body');
if (body && body.getAttribute('data-style') === 'dark-layout') {
return '#1F2937'; // Replace with your desired dark mode input color
} else {
return '#ffffff'; // Default day mode color
}
}
// Function to reload the Chatbro widget with the correct colors
function reloadChatbroWidget() {
var chatContainer = document.getElementById('chatbroContainer');
if (chatContainer) {
chatContainer.innerHTML = ''; // Clear the existing widget
}
ChatbroLoader({
encodedChatId: '<?= $encodedChatId ?>',
siteDomain: '<?= $siteDomain ?>',
chatHeaderBackgroundColor: getChatHeaderBackgroundColor(),
chatBodyBackgroundColor: getChatBodyBackgroundColor(),
chatInputBackgroundColor: getChatInputBackgroundColor(),
showChatShadow: 'true',
siteUserExternalId: '<?= $siteUserExternalId ?>',
siteUserFullName: '<?= $siteUserFullName ?>',
siteUserAvatarUrl: '<?= $siteUserAvatarUrl ?>',
siteUserProfileUrl: '<?= $siteUserProfileUrl ?>',
siteUserFullNameColor: '<?= $siteUserFullNameColor ?>',
permissions: <?= $permissionsDisplay ?>,
signature: '<?= md5($siteDomain . '' . $siteUserExternalId . '' . $siteUserFullName . '' . $siteUserAvatarUrl . '' . $siteUserProfileUrl . '' . $siteUserFullNameColor . '' . implode('', $permissions) . '' . $secretKey) ?>'
});
}
// Set up a MutationObserver to watch for changes to the data-style attribute
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName === 'data-style') {
reloadChatbroWidget();
}
});
});
// Start observing the body element for attribute changes
var body = document.querySelector('body');
if (body) {
observer.observe(body, {
attributes: true // Configure it to listen for attribute changes
});
}
// Initial load of the Chatbro widget
reloadChatbroWidget();
</script>
<?php }
} ?>