(function() { //Global app embed for Rivo function loadScript(src, defer, done) { var js = document.createElement('script'); js.src = src; js.defer = defer; js.onload = function(){done();}; js.onerror = function(){ done(new Error('Failed to load script ' + src)); }; document.head.appendChild(js); } function browserSupportsAllFeatures() { return window.Promise && window.fetch && window.Symbol && window.localStorage; } if (browserSupportsAllFeatures()) { main(); } else { loadScript("https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=Promise,fetch,localStorage", true, main); } function loadAppScripts() { loadScript(window.Rivo.global_config.asset_urls.loy.init_js, true, function(){}); } function main(retries = 0, maxRetries = 30) { const isEdgeMesh = window.Rivo?.loy_config?.account_widget_settings?.cache_app_type == "edgemesh" || window.edgemesh || window.EDGEMESH; const isNostra = window.Rivo?.loy_config?.account_widget_settings?.cache_app_type == "nostra" || window.Nostra; if (!window.Rivo && !isEdgeMesh && !isNostra) { if (retries < maxRetries) { setTimeout(function() { main(retries + 1, maxRetries); }, 200); return; } else { console.error('Failed to load Rivo config after 6 seconds'); return; } } if (isNostra) { nostraRivoAppInit(); } else if (isEdgeMesh) { if (window.edgemesh?.lite){ loadScript(window.Rivo.global_config.asset_urls.global.helper_js, false, loadAppScripts); } else { edgemeshRivoAppInit(); } } else { loadScript(window.Rivo.global_config.asset_urls.global.helper_js, false, loadAppScripts); } } function edgemeshRivoAppInit() { fetch(`${window.location.origin}/em-cgi/dynamic`, { credentials: "include" }) .then(response => { const contentType = response.headers.get("content-type"); if (contentType && contentType.includes("application/json")) { return response.json(); } return null; }) .then(htmlArray => { if (!htmlArray) return; const rivoAppEmbedChunk = htmlArray.find(chunk => chunk.includes('window.Rivo.common.customer =')); if (rivoAppEmbedChunk) { const rivoAppEmbedInit = document.querySelector('#rivo-js-customer-init'); if (rivoAppEmbedInit) { rivoAppEmbedInit.innerHTML = rivoAppEmbedChunk; } const rivoProfileMainChunk = htmlArray.find(chunk => chunk.includes('
')); if (rivoProfileMainChunk) { const rivoProfileMain = document.querySelector('#rivo-profile-main'); if (rivoProfileMain) { rivoProfileMain.innerHTML = rivoProfileMainChunk; } } } loadScript(window.Rivo.global_config.asset_urls.global.helper_js, false, loadAppScripts); }) .catch(err => { console.log("EdgeMesh check failed:", err); }); } function nostraRivoAppInit() { const skipCacheURL = new URL(window.location.href); skipCacheURL.searchParams.set('skipCache', 'true'); fetch(skipCacheURL.toString()) .then(response => response.text()) .then(htmlText => { const parser = new DOMParser(); const freshDocument = parser.parseFromString(htmlText, 'text/html'); const currentElement = document.querySelector('#rivo-js-customer-init'); const freshElement = freshDocument.querySelector('#rivo-js-customer-init'); if (currentElement && freshElement) { const newElement = document.createElement(freshElement.tagName); Array.from(freshElement.attributes).forEach(attr => { newElement.setAttribute(attr.name, attr.value); }); newElement.innerHTML = freshElement.innerHTML; currentElement.replaceWith(newElement); } loadScript(window.Rivo.global_config.asset_urls.global.helper_js, false, loadAppScripts); }); } })();