/*(function () { | |
const API_HOST = 'https://app.tinyadz.com/' | |
const managerScriptUrl = 'https://app.tinyadz.com/libs/manager.js'; | |
const config = JSON.parse('{"enablePaidAds":false,"renderMode":"FULL_SCREEN"}'); | |
const enabled = 'true' === 'true'; | |
const renderMode = 'FULL_SCREEN'; | |
const siteId = '6801696780614e3db552df1d'; | |
// API Endpoints | |
const API_ENDPOINTS = { | |
GET_AVAILABLE_WIDGETS: `${API_HOST}api/GetAvailableWidgetsAPI`, | |
}; | |
// Ad Layout Types | |
const AD_LAYOUTS = { | |
POPUP_BANNER: 'POPUP_BANNER', | |
TOP_BANNER: 'TOP_BANNER', | |
BOTTOM_BANNER: 'BOTTOM_BANNER', | |
}; | |
class AdsManager { | |
constructor(siteId, enabled, config) { | |
if (!enabled) return; // Exit if not enabled | |
this.siteId = siteId; | |
this.config = config; | |
this.init(); | |
} | |
async init() { | |
await this.loadManagerScript(); | |
if (window.ta) { | |
this.fetchAndDisplayAds(); | |
} else { | |
console.error('Ad manager script failed to load or window.ta is undefined'); | |
} | |
} | |
loadManagerScript() { | |
return new Promise((resolve, reject) => { | |
if (document.getElementById('tinyadz-manager-script')) { | |
return resolve(); | |
} | |
const script = document.createElement('script'); | |
script.id = 'tinyadz-manager-script'; | |
script.src = managerScriptUrl; | |
script.async = true; | |
script.onload = () => { | |
if (window.ta) { | |
resolve(); | |
} else { | |
reject(new Error('Failed to initialize ad manager')); | |
} | |
}; | |
script.onerror = () => reject(new Error('Failed to load manager script')); | |
document.head.appendChild(script); | |
}); | |
} | |
async fetchAndDisplayAds() { | |
try { | |
const params = new URLSearchParams({ | |
siteId: this.siteId, | |
pageUrl: location.href, | |
width: window.innerWidth, | |
height: window.innerHeight, | |
}).toString(); | |
const response = await fetch(`${API_ENDPOINTS.GET_AVAILABLE_WIDGETS}?${params}`); | |
const { widgets } = await response.json(); | |
if (widgets && widgets.length > 0) { | |
const { widgetId, snapshotId } = widgets[0]; | |
ta.showPopup(widgetId, null, { | |
snapshotId, | |
theme: config.theme || 'light', | |
renderMode | |
}); | |
} | |
} catch (error) { | |
console.error('Failed to fetch available ads', error); | |
} | |
} | |
showConnectionIndicator() { | |
const indicator = document.createElement('div'); | |
indicator.innerHTML = ` | |
<span style="margin-right: 8px;">TinyAdz connected β </span> | |
<span id="TA_NOTICE_CLOSE"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="cursor: pointer;"> | |
<line x1="18" y1="6" x2="6" y2="18"></line> | |
<line x1="6" y1="6" x2="18" y2="18"></line> | |
</svg></span> | |
`; | |
Object.assign(indicator.style, { | |
position: 'fixed', | |
bottom: '-40px', | |
left: '10px', | |
backgroundColor: 'rgba(255, 255,255, 0.9)', | |
color: '#222', | |
padding: '8px 12px', | |
borderRadius: '5px', | |
fontSize: '14px', | |
display: 'flex', | |
alignItems: 'center', | |
gap: '5px', | |
border: '1px solid #ccc', | |
transition: 'bottom 0.3s ease-in-out', | |
zIndex: '10000', | |
}); | |
document.body.appendChild(indicator); | |
setTimeout(() => { | |
indicator.style.bottom = '10px'; | |
document.querySelector('#TA_NOTICE_CLOSE').addEventListener('click', () => { | |
indicator.style.bottom = '-40px'; | |
setTimeout(() => document.body.removeChild(indicator), 300); | |
}); | |
}, 100); | |
} | |
} | |
window.tam = new AdsManager(siteId, enabled, config); | |
})(); |