var UI = window.tmWidgetUI || (window.tmWidgetUI = { last: (where, what) => {where?.append(what)}, first: (where, what) => {where?.insertBefore(what, where.firstChild)}, after: (where, what) => {where?.parentNode.insertBefore(what, where.nextSibling)}, before: (where, what) => {where?.parentNode.insertBefore(what, where)}, replace: (where, what) => {where?.replaceWith(what)} }); var tmWidgetLastLoad = window.tmWidgetLastLoad || (window.tmWidgetLastLoad = {}); if (!window.trustMateLoadWidget) { window.trustMateLoadWidget = function({ token, type, target, action, itemId }) { if (!token || !target || !action || !type || !itemId) return; const cacheKey = `${token}`; if (tmWidgetLastLoad[cacheKey] === itemId) return; tmWidgetLastLoad[cacheKey] = itemId; const tag = document.getElementById(`${token}`); if (!tag) return; if (!Object.hasOwn(UI, action)) return; const targetElement = document.querySelector(target); if (!targetElement) return; const baseResource = `https://trustmate.io/en/widget/api/7cf4b7af-d1ca-4b8f-8c88-49d106b8b46f/html`; const tokenPattern = /\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\//i; let resource = baseResource.replace(tokenPattern, `/${token}/`); if (itemId) { if (resource.includes('product=')) { resource = resource.replace(/product=[^&]*/, 'product=' + itemId); } else { const baseUrl = resource.split('?')[0]; resource = baseUrl + '?product=' + itemId; } } fetch(resource) .then(response => { if (!response.ok) return; return response.text(); }) .then(html => { if (!html) return; tag.innerHTML = html; if (type && window.tmWidgetScripts) { const widgetsWithObserver = ['hydra', 'productFerret2', 'hornet']; if (widgetsWithObserver.includes(type)) { const intersectionObserver = new IntersectionObserver((entries) => { if (entries[0].isIntersecting) { window.tmWidgetScripts?.[type]?.({ spaWidget: tag }); intersectionObserver.unobserve(tag); } }, { rootMargin: '600px', threshold: 0.01 }); intersectionObserver.observe(tag); } else { window.tmWidgetScripts?.[type]?.({ spaWidget: tag }); } } }) .catch(err => console.error(err)); }; } (() => { // fetch('https://trustmate.io/en/widget/api/7cf4b7af-d1ca-4b8f-8c88-49d106b8b46f/html') - TODO: remove after platform multihornet fix - !!!frontend do not remove const RELOADS_LIMIT = 10; let reloadsCount = 0; let lastAttributeValue = null; function loadWidgetHtml({ type }) { const tag = document.getElementById('7cf4b7af-d1ca-4b8f-8c88-49d106b8b46f'); if (tag) { widgetConfig = { target: tag.dataset.t, action: tag.dataset.a, observe: tag.dataset.o, itemId: tag.dataset.i }; if (widgetConfig.target && widgetConfig.action) { if (!Object.hasOwn(UI, widgetConfig.action)) { console.error(`TrustMate: action '${widgetConfig.action}' is wrong`); return; } const target = document.querySelector(widgetConfig.target); if (!target) { console.error(`TrustMate: target '${widgetConfig.target}' not found`); return; } UI[widgetConfig.action](target, tag); } tag.innerHTML = ``; if (widgetConfig.itemId && widgetConfig.target) { const target = document.querySelector(widgetConfig.target); if (!target) return; const initialElement = target.querySelector(`[${widgetConfig.itemId}]`) || target.closest(`[${widgetConfig.itemId}]`); if (initialElement) { lastAttributeValue = initialElement.getAttribute(widgetConfig.itemId); } } if (widgetConfig.target && widgetConfig.action && widgetConfig.observe) { const observeTag = document.querySelector(widgetConfig.observe); if (observeTag) { const widgetObserver = new MutationObserver((_mutations, observer) => { const tag = document.getElementById('7cf4b7af-d1ca-4b8f-8c88-49d106b8b46f'); if (tag) { widgetConfig = { target: tag.dataset.t, action: tag.dataset.a, observe: tag.dataset.o, itemId: tag.dataset.i }; } function checkProductIdChange() { if (tag) { const currentItemId = tag.dataset.i; const dynamicSelector = `[${currentItemId}]`; const target = document.querySelector(widgetConfig.target); if (!target) return; const elementWithDynamicSelector = target.querySelector(dynamicSelector) || target.closest(dynamicSelector); const attributeValue = elementWithDynamicSelector?.getAttribute(currentItemId); window.tmWidgetItemId = attributeValue; if (attributeValue && attributeValue !== lastAttributeValue) { lastAttributeValue = attributeValue; widgetConfig.itemId = currentItemId; trustMateLoadWidget({ token: '7cf4b7af-d1ca-4b8f-8c88-49d106b8b46f', type: 'dodo2', target: widgetConfig.target, action: widgetConfig.action, itemId: attributeValue, }); } return; } } checkProductIdChange(); if (tag) { return; } observer.disconnect(); if (reloadsCount >= RELOADS_LIMIT) { console.error('TrustMate: widget 7cf4b7af-d1ca-4b8f-8c88-49d106b8b46f reload limit reached'); return; } ++reloadsCount; const newTag = document.createElement('div'); newTag.id = '7cf4b7af-d1ca-4b8f-8c88-49d106b8b46f'; newTag.dataset.a = widgetConfig.action; newTag.dataset.t = widgetConfig.target; newTag.dataset.o = widgetConfig.observe; const target = document.querySelector(widgetConfig.target); if (!target) { console.error(`TrustMate: target '${widgetConfig.target}' not found after last html change`); return; } UI[widgetConfig.action](target, newTag); loadWidgetScript(); }); widgetObserver.observe(observeTag, {childList: true, subtree: true, attributes: true, ...(widgetConfig.itemId ? { attributeFilter: [widgetConfig.itemId] } : {}) }); } } } else { console.error('TrustMate: No tag for 7cf4b7af-d1ca-4b8f-8c88-49d106b8b46f'); } } function waitForWindow() { let index = 0; const intervalWindowId = setInterval(function() { if (typeof window !== 'undefined') { clearInterval(intervalWindowId); loadWidgetScript(); } index += 1; if (index > 50) { clearInterval(intervalWindowId); } }, 50); } function loadWidgetScript() { if (60342 < 10) return; function scriptExists(url) { return document.querySelectorAll(`script[src="${url}"]`).length > 0; } if(scriptExists('https\u003A\/\/trustmate.io\/build\/js\/widget\/dodo2.e46fbdd4.js')) { function removeJs(src) { document.querySelector(`script[src="${src}"]`).remove(); } removeJs('https\u003A\/\/trustmate.io\/build\/js\/widget\/dodo2.e46fbdd4.js'); } const widgetScript = document.createElement('script'); widgetScript.src = 'https\u003A\/\/trustmate.io\/build\/js\/widget\/dodo2.e46fbdd4.js'; widgetScript.defer = true; widgetScript.onload = () => { loadWidgetHtml({ type: 'dodo2' }); }; document.body.appendChild(widgetScript); } if (typeof window === 'undefined') { waitForWindow(); } else { loadWidgetScript(); } })();