function processMattrzCxLibrary() { const mattrzCxLibraryInstance = new window.MattrzCxLibrary({ clientKey: "dwmall", url: location.href, }); mattrzCxLibraryInstance.exec() .catch(error => console.error('Library execution failed:', error)); window.mattrzCxLibraryInstance = mattrzCxLibraryInstance; } function loadMattrzCxLibrary() { const mattrzCxSrc = "https://library.mattrz-cx.com/index.js"; let mattrzCxDone = false; const mattrzCxHead = document.getElementsByTagName("head")[0]; const mattrzCxScript = document.createElement("script"); mattrzCxScript.onerror = function() { console.error('Failed to load the library script.'); }; mattrzCxScript.src = mattrzCxSrc; mattrzCxHead.appendChild(mattrzCxScript); mattrzCxScript.onload = mattrzCxScript.onreadystatechange = function() { if ( !mattrzCxDone && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") ) { mattrzCxDone = true; mattrzCxScript.onload = mattrzCxScript.onreadystatechange = null; if (mattrzCxHead && mattrzCxScript.parentNode) { mattrzCxHead.removeChild(mattrzCxScript); } processMattrzCxLibrary(); } }; } function setupMattrzCxLibraryLoader() { let mattrzCxTagCount = 0; const mattrzCxWaitDomInterval = setInterval(() => { if (document.readyState === "complete" || ++mattrzCxTagCount >= 50) { loadMattrzCxLibrary(); clearInterval(mattrzCxWaitDomInterval); } }, 100); } setupMattrzCxLibraryLoader();