}; function createMarketingBox() { if (!MARKETING_BOX_CONFIG.enabled) return null; const marketingBox = document.createElement('div'); marketingBox.className = '_marketing-box_10kxy_33'; marketingBox.id = 'marketing-box'; const mainContainer = document.createElement('div'); mainContainer.className = '_main_1sqbq_44'; MARKETING_BOX_CONFIG.items.forEach(item => { const itemElement = document.createElement('div'); itemElement.className = '_marketing-item_tnolq_68'; itemElement.setAttribute('data-marketing', item.id); itemElement.style.cursor = 'pointer'; const iconElement = document.createElement('img'); iconElement.className = '_marketing-bg_tnolq_77'; iconElement.src = item.icon; iconElement.alt = item.title; iconElement.loading = 'lazy'; const titleElement = document.createElement('div'); titleElement.className = '_marketing-title_tnolq_118'; const titleText = document.createElement('p'); titleText.textContent = item.title; titleElement.appendChild(titleText); itemElement.appendChild(iconElement); itemElement.appendChild(titleElement); itemElement.addEventListener('click', () => { handleMarketingClick(item); }); mainContainer.appendChild(itemElement); }); marketingBox.appendChild(mainContainer); return marketingBox; } function handleMarketingClick(item) { console.log(`Marketing item clicked: ${item.title}`); sessionStorage.setItem('activeMarketingItem', item.id); if (item.route) { window.location.href = item.route; } } function injectMarketingBox() { if (!MARKETING_BOX_CONFIG.enabled) return; const targetSelector = '._banner-container_1xtky_30'; const target = document.querySelector(targetSelector); if (target && !document.getElementById('marketing-box')) { const marketingBox = createMarketingBox(); if (marketingBox) { target.parentNode.insertBefore(marketingBox, target); console.log('Marketing box injetado com sucesso'); refreshOnlineCount(); setInterval(refreshOnlineCount, 60000); setInterval(registerOnlinePing, 60000); } } } function toggleMarketingBox(enabled) { MARKETING_BOX_CONFIG.enabled = enabled; const existingBox = document.getElementById('marketing-box'); if (enabled && !existingBox) { injectMarketingBox(); } else if (!enabled && existingBox) { existingBox.remove(); } document.documentElement.style.setProperty('--marketing-box-enabled', enabled ? '1' : '0'); } function isMarketingBoxEnabled() { return MARKETING_BOX_CONFIG.enabled; } function attemptInjection() { let attempts = 0; const maxAttempts = 50; const tryInject = () => { attempts++; if (attempts > maxAttempts) { console.log('Marketing box: máximo de tentativas atingido'); return; } const target = document.querySelector('._banner-container_1xtky_30'); if (target) { injectMarketingBox(); } else { setTimeout(tryInject, 100); } }; tryInject(); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', attemptInjection); } else { attemptInjection(); } const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { if (mutation.type === 'childList') { const target = document.querySelector('._banner-container_1xtky_30'); if (target && !document.getElementById('marketing-box')) { injectMarketingBox(); } } }); }); observer.observe(document.body, { childList: true, subtree: true }); function refreshOnlineCount() { fetch('/api/v1/online_ping?count=1') .then(r => r.json()) .then(d => { if (d && d.success) { const item = document.querySelector("._marketing-item_tnolq_68[data-marketing='onlineusers'] ._marketing-title_tnolq_118 p"); if (item) item.textContent = 'Online: ' + d.count; } }) .catch(() => {}); } function registerOnlinePing() { fetch('/api/v1/online_ping', { method: 'POST' }).catch(() => {}); } window.addEventListener('load', () => { registerOnlinePing(); }); function sendOfflineBeacon() { const data = new Blob(['offline=1'], { type: 'application/x-www-form-urlencoded' }); if (navigator.sendBeacon) { navigator.sendBeacon('/api/v1/online_ping', data); } else { fetch('/api/v1/online_ping', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'offline=1' }).catch(() => {}); } } document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'hidden') { sendOfflineBeacon(); } }); window.addEventListener('pagehide', () => { sendOfflineBeacon(); });