test2 / static /chat-loader2.js
joedown11's picture
Update internal URLs for testing space
be389db
Raw
History Blame Contribute Delete
1.75 kB
(function () {
const baseUrl = 'https://testingweb647-test2.hf.space';
function init() {
// Prevent duplicate containers
if (document.getElementById('martech-chat-widget-container')) return;
const container = document.createElement('div');
container.id = 'martech-chat-widget-container';
document.body.appendChild(container);
fetch(`${baseUrl}/widget?v=${Date.now()}`)
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
doc.querySelectorAll('style').forEach(st => {
document.head.appendChild(st.cloneNode(true));
});
const wrapper = doc.querySelector('#martech-chat-wrapper');
if (wrapper) {
container.innerHTML = wrapper.outerHTML;
} else {
container.innerHTML = doc.body.innerHTML;
}
doc.querySelectorAll('script').forEach(oldScript => {
const newScript = document.createElement('script');
Array.from(oldScript.attributes).forEach(attr => {
newScript.setAttribute(attr.name, attr.value);
});
newScript.innerHTML = oldScript.innerHTML;
document.body.appendChild(newScript);
});
})
.catch(err => console.error("Failed to load Martechsol Assistant:", err));
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();