UNPKG

richpartners-telegram-sdk

Version:
99 lines 3.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseAds = void 0; const index_js_1 = require("../../services/index.js"); class BaseAds { constructor() { this.widgetId = null; this.requestData = null; this.widgetManager = null; this.adRequestService = null; } isNeededIgnoreClickByEvent(e) { const target = e.target; if (!target) return false; return (target.id === this.getIdCloseButton() || !!target.closest('.native-block-tg') || !!target.closest('.banner-block-tg') || !!target.closest('.telegram-interstitial-banner-close-btn') || !!target.closest('.telegram-interstitial-banner-ad-overlay') || !!target.closest('.telegram-interstitial-video-close-btn') || !!target.closest('.telegram-interstitial-video-ad-overlay') || !!target.closest('#telegram-interstitial-video-container')); } initialize() { this.loadConfigByLocalStorage(); this.adRequestService = new index_js_1.AdRequestService(this.widgetManager.getDebug()); this.setWidgetId(this.widgetManager.getWidgetIdByType(this.getType())); this.validate(); } incrementCap(options) { const { capKey, expiresCapKey, capIntervalKey, delay, interval, showedItem = 0, } = options; const previousCap = Number(index_js_1.LS.get(capKey)) || 0; let newCap = previousCap + showedItem; index_js_1.LS.set(expiresCapKey, 1, delay); if (index_js_1.LS.get(capIntervalKey) === null) { newCap = showedItem; index_js_1.LS.set(capIntervalKey, 1, interval); } index_js_1.LS.set(capKey, newCap); } getIdCloseButton() { return 'el-notification-close-btn'; } getDefaultBidFloor() { return 0.001; } openAdLink(clickUrl) { if (!clickUrl) { throw new Error('clickUrl not found'); } try { if (typeof window.Telegram === 'object' && typeof window.Telegram.WebApp === 'object' && typeof window.Telegram.WebApp.expand === 'function' && typeof window.Telegram.WebApp.openLink === 'function') { window.Telegram.WebApp.expand(); window.Telegram.WebApp.openLink(clickUrl); } else { const newTab = window.open(clickUrl, '_blank'); if (newTab) { newTab.focus(); } else { new Error("New tab blocked"); } } } catch (e) { const newTab = window.open(clickUrl, '_blank'); if (newTab) { newTab.focus(); } else { new Error("New tab blocked"); } } } setWidgetId(widgetId) { this.widgetId = widgetId; } setRequestData(requestData) { this.requestData = requestData; } setWidgetManager(widgetManager) { this.widgetManager = widgetManager; } validate() { if (!this.widgetManager) { throw new Error('widgetManager not initialized.'); } if (!this.widgetId) { throw new Error('widgetId not initialized.'); } } } exports.BaseAds = BaseAds; //# sourceMappingURL=Base.js.map