Javascript загружает так много чатовJquery

Программирование на jquery
Ответить
Anonymous
 Javascript загружает так много чатов

Сообщение Anonymous »

Привет, это загрузчик чатбро. По сути, я пытаюсь сделать его совместимым с дневным и ночным режимом для моего веб-сайта, но он загружает 2 чата на странице 1 белый 1 черный чат, когда я переключаю дневной/ночной режим, он даже загружает больше, я просто хочу обновить текущий код, чтобы больше не загружать чаты, я хочу 1 блок чата! я загружаю Chatbro.php, используя тег php include, кстати, я не знаю, если это проблема.. вот код

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: '',
siteDomain: '',
chatHeaderBackgroundColor: getChatHeaderBackgroundColor(),
chatBodyBackgroundColor: getChatBodyBackgroundColor(),
chatInputBackgroundColor: getChatInputBackgroundColor(),
showChatShadow: 'true',
siteUserExternalId: '',
siteUserFullName: '',
siteUserAvatarUrl: '',
siteUserProfileUrl: '',
siteUserFullNameColor: '',
permissions: ,
signature: ''
});
}

// 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();





Подробнее здесь: https://stackoverflow.com/questions/787 ... many-chats
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Jquery»