richpartners-telegram-sdk
Version:
richPartners ads telegram
949 lines (946 loc) • 54.7 kB
JavaScript
import m from "crypto-js";
import { init as D, initData as p } from "@telegram-apps/sdk";
var g = /* @__PURE__ */ ((E) => (E.positionTop = "TOP", E.positionBottom = "BOTTOM", E.positionMiddle = "MIDDLE", E))(g || {}), S = /* @__PURE__ */ ((E) => (E.PUSH_STYLE = "PUSH_STYLE", E.PUSH_STYLE_OLD = "native", E.EMBEDDED_BANNER = "EMBEDDED_BANNER", E.EMBEDDED_BANNER_OLD = "banner", E.INTERSTITIAL_BANNER = "INTERSTITIAL_BANNER", E.INTERSTITIAL_VIDEO = "INTERSTITIAL_VIDEO", E))(S || {});
const O = "https://cdn.adx1.com/publisher-config/", M = 86400, s = {
WIDGET_TYPE: "RP_ADVERTISER_TELEGRAM_WIDGET_TYPE",
ACTIVE_WIDGET_TYPE: "RP_ADVERTISER_TELEGRAM_ACTIVE_WIDGET_TYPE",
PUSH_STYLE_AUTO_MODE: "RP_ADVERTISER_TELEGRAM_PUSH_STYLE_AUTO_MODE",
EMBEDDED_BANNER_AUTO_MODE: "RP_ADVERTISER_TELEGRAM_EMBEDDED_BANNER_AUTO_MODE",
INTERSTITIAL_BANNER_AUTO_MODE: "RP_ADVERTISER_TELEGRAM_INTERSTITIAL_BANNER_AUTO_MODE",
INTERSTITIAL_VIDEO_AUTO_MODE: "RP_ADVERTISER_TELEGRAM_INTERSTITIAL_VIDEO_AUTO_MODE",
IS_PREMIUM: "IS_PREMIUM",
CONFIG_UPDATE_TIME: "CONFIG_UPDATE_TIME",
PUSH_STYLE_IMPRESSION_DELAY: "PUSH_STYLE_IMPRESSION_DELAY",
PUSH_STYLE_IMPRESSION_INTERVAL: "PUSH_STYLE_IMPRESSION_INTERVAL",
PUSH_STYLE_LIMIT_IMPRESSION_PER_INTERVAL: "PUSH_STYLE_LIMIT_IMPRESSION_PER_INTERVAL",
PUSH_STYLE_LIMIT_IMPRESSION_PER_VIEW: "PUSH_STYLE_LIMIT_IMPRESSION_PER_VIEW",
PUSH_STYLE_RESTART_LIMIT_IMPRESSIONS: "PUSH_STYLE_RESTART_LIMIT_IMPRESSIONS",
PUSH_STYLE_POSITION_TYPE: "PUSH_STYLE_POSITION_TYPE",
PUSH_STYLE_CLOSABLE_WITHOUT_VIEW: "PUSH_STYLE_CLOSABLE_WITHOUT_VIEW",
PUSH_STYLE_SSP_ID: "PUSH_STYLE_SSP_ID",
PUSH_STYLE_CAP: "PUSH_STYLE_CAP",
PUSH_STYLE_EXPIRES_CAP: "PUSH_STYLE_EXPIRES_CAP",
PUSH_STYLE_CAP_PER_INTERVAL: "PUSH_STYLE_CAP_PER_INTERVAL",
INTERSTITIAL_BANNER_IMPRESSION_DELAY: "INTERSTITIAL_BANNER_IMPRESSION_DELAY",
INTERSTITIAL_BANNER_IMPRESSION_INTERVAL: "INTERSTITIAL_BANNER_IMPRESSION_INTERVAL",
INTERSTITIAL_BANNER_LIMIT_IMPRESSION_PER_INTERVAL: "INTERSTITIAL_BANNER_LIMIT_IMPRESSION_PER_INTERVAL",
INTERSTITIAL_BANNER_RESTART_LIMIT_IMPRESSIONS: "INTERSTITIAL_BANNER_RESTART_LIMIT_IMPRESSIONS",
INTERSTITIAL_BANNER_CLOSABLE_WITHOUT_VIEW: "INTERSTITIAL_BANNER_CLOSABLE_WITHOUT_VIEW",
INTERSTITIAL_BANNER_SSP_ID: "INTERSTITIAL_BANNER_SSP_ID",
INTERSTITIAL_BANNER_AD_DURATION: "INTERSTITIAL_BANNER_AD_DURATION",
INTERSTITIAL_BANNER_WIDTH: "INTERSTITIAL_BANNER_WIDTH",
INTERSTITIAL_BANNER_HEIGHT: "INTERSTITIAL_BANNER_HEIGHT",
INTERSTITIAL_BANNER_CAP: "INTERSTITIAL_BANNER_CAP",
INTERSTITIAL_BANNER_EXPIRES_CAP: "INTERSTITIAL_BANNER_EXPIRES_CAP",
INTERSTITIAL_BANNER_CAP_PER_INTERVAL: "INTERSTITIAL_BANNER_CAP_PER_INTERVAL",
INTERSTITIAL_VIDEO_IMPRESSION_DELAY: "INTERSTITIAL_VIDEO_IMPRESSION_DELAY",
INTERSTITIAL_VIDEO_IMPRESSION_INTERVAL: "INTERSTITIAL_VIDEO_IMPRESSION_INTERVAL",
INTERSTITIAL_VIDEO_LIMIT_IMPRESSION_PER_INTERVAL: "INTERSTITIAL_VIDEO_LIMIT_IMPRESSION_PER_INTERVAL",
INTERSTITIAL_VIDEO_RESTART_LIMIT_IMPRESSIONS: "INTERSTITIAL_VIDEO_RESTART_LIMIT_IMPRESSIONS",
INTERSTITIAL_VIDEO_CLOSABLE_WITHOUT_VIEW: "INTERSTITIAL_VIDEO_CLOSABLE_WITHOUT_VIEW",
INTERSTITIAL_VIDEO_SSP_ID: "INTERSTITIAL_VIDEO_SSP_ID",
INTERSTITIAL_VIDEO_AD_DURATION: "INTERSTITIAL_VIDEO_AD_DURATION",
INTERSTITIAL_VIDEO_CAP: "INTERSTITIAL_VIDEO_CAP",
INTERSTITIAL_VIDEO_EXPIRES_CAP: "INTERSTITIAL_VIDEO_EXPIRES_CAP",
INTERSTITIAL_VIDEO_CAP_PER_INTERVAL: "INTERSTITIAL_VIDEO_CAP_PER_INTERVAL",
EMBEDDED_BANNER_DATA: "EMBEDDED_BANNER_DATA",
EMBEDDED_BANNER_SSP_ID: "EMBEDDED_BANNER_SSP_ID",
RICHPARTNERS_STW: "RICHPARTNERS_STW",
RICHPARTNERS_TON_WALLET: "ton-connect-storage_bridge-connection"
};
class h {
static createRichPartnersAdsByType(e) {
switch (e) {
case S.PUSH_STYLE:
return new v();
case S.EMBEDDED_BANNER:
return new B();
case S.INTERSTITIAL_BANNER:
return new y();
case S.INTERSTITIAL_VIDEO:
return new b();
default:
throw new Error("WidgetType not found");
}
}
}
class L {
constructor() {
this.widgetId = null, this.requestData = null, this.widgetManager = null, this.adRequestService = null;
}
isNeededIgnoreClickByEvent(e) {
const t = e.target;
return t ? t.id === this.getIdCloseButton() || !!t.closest(".native-block-tg") || !!t.closest(".banner-block-tg") || !!t.closest(".telegram-interstitial-banner-close-btn") || !!t.closest(".telegram-interstitial-banner-ad-overlay") || !!t.closest(".telegram-interstitial-video-close-btn") || !!t.closest(".telegram-interstitial-video-ad-overlay") || !!t.closest("#telegram-interstitial-video-container") : !1;
}
initialize() {
this.loadConfigByLocalStorage(), this.adRequestService = new W(this.widgetManager.getDebug()), this.setWidgetId(this.widgetManager.getWidgetIdByType(this.getType())), this.validate();
}
incrementCap(e) {
const {
capKey: t,
expiresCapKey: i,
capIntervalKey: I,
delay: r,
interval: a,
showedItem: _ = 0
} = e;
let l = (Number(n.get(t)) || 0) + _;
n.set(i, 1, r), n.get(I) === null && (l = _, n.set(I, 1, a)), n.set(t, l);
}
getIdCloseButton() {
return "el-notification-close-btn";
}
getDefaultBidFloor() {
return 1e-3;
}
openAdLink(e) {
if (!e)
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(e);
else {
const t = window.open(e, "_blank");
t ? t.focus() : new Error("New tab blocked");
}
} catch {
const i = window.open(e, "_blank");
i && i.focus();
}
}
setWidgetId(e) {
this.widgetId = e;
}
setRequestData(e) {
this.requestData = e;
}
setWidgetManager(e) {
this.widgetManager = e;
}
validate() {
if (!this.widgetManager)
throw new Error("widgetManager not initialized.");
if (!this.widgetId)
throw new Error("widgetId not initialized.");
}
}
class B extends L {
constructor() {
super(...arguments), this.IMPRESSION_INTERVAL = 60, this.config = {
EMBEDDED_BANNER_DATA: [],
EMBEDDED_BANNER_SSP_ID: 14263
};
}
getType() {
return S.EMBEDDED_BANNER;
}
getSsp() {
return this.config.EMBEDDED_BANNER_SSP_ID;
}
handleTrigger(e) {
return new Promise((t) => {
t("success");
});
}
handle() {
this.initialize(), this.config.EMBEDDED_BANNER_DATA.forEach((e) => {
if (e.impression_interval = this.IMPRESSION_INTERVAL, document.querySelectorAll(e.selector).length === 0) return;
const i = {
...this.requestData,
motivated: !1,
width: e.banner_width,
height: e.banner_height,
widget_id: this.widgetId,
bid_floor: this.getDefaultBidFloor(),
number_of_bids: 1
}, I = () => {
this.adRequestService.fetchAds(i, this.getSsp(), (a) => {
a.length > 0 && this.showAd(a[0], e);
});
};
e.limit_impression_per_interval && e.impression_interval && e.impression_delay ? this.runAdCycle(I, e) : I();
});
}
runAdCycle(e, t) {
let i = 1;
const I = Date.now();
e();
const r = setInterval(() => {
const a = Date.now() - I, _ = i < t.limit_impression_per_interval, T = a <= t.impression_interval * 1e3;
if (!_ || !T) {
clearInterval(r);
return;
}
i++, e();
}, t.impression_delay * 1e3);
}
showAd(e, t) {
var r;
const i = document.querySelector(t.selector);
if (!i) {
console.warn(`[showAds] Element with selector "${t.selector}" not found.`);
return;
}
let I = "banner-" + Math.random().toString(36).substr(2, 9);
i.innerHTML = `
<a href="${e.link}" target="_blank" id="${I}" class="banner-block-tg">
<img src="${e.image}" alt="${t.tooltip ?? "banner"}">
</a>
`, (r = t.tooltip) != null && r.trim() && i.setAttribute("title", t.tooltip.trim());
}
isConfigInstalledInLocalStorage() {
return n.get(s.EMBEDDED_BANNER_DATA);
}
loadConfigByLocalStorage() {
this.config.EMBEDDED_BANNER_DATA = JSON.parse(n.get(s.EMBEDDED_BANNER_DATA)), this.config.EMBEDDED_BANNER_SSP_ID = Number(n.get(s.EMBEDDED_BANNER_SSP_ID)) || this.config.EMBEDDED_BANNER_SSP_ID;
}
updateConfigParams(e) {
let t = e.widget[this.getType()];
t && t.ssp_id && (this.config.EMBEDDED_BANNER_SSP_ID = t.ssp_id ?? this.config.EMBEDDED_BANNER_SSP_ID), n.set(s.EMBEDDED_BANNER_DATA, JSON.stringify([])), t && (t["config-banner"] ? n.set(s.EMBEDDED_BANNER_DATA, JSON.stringify(t["config-banner"])) : t["config-embedded-banner"] && n.set(s.EMBEDDED_BANNER_DATA, JSON.stringify(t["config-embedded-banner"])), n.get(s.EMBEDDED_BANNER_DATA) && (this.config.EMBEDDED_BANNER_DATA = JSON.parse(n.get(s.EMBEDDED_BANNER_DATA))));
}
}
class y extends L {
constructor() {
super(...arguments), this.waitShowed = !1, this.config = {
INTERSTITIAL_BANNER_IMPRESSION_DELAY: 15,
INTERSTITIAL_BANNER_IMPRESSION_INTERVAL: 86400,
INTERSTITIAL_BANNER_LIMIT_IMPRESSION_PER_INTERVAL: 20,
INTERSTITIAL_BANNER_RESTART_LIMIT_IMPRESSIONS: !1,
INTERSTITIAL_BANNER_CLOSABLE_WITHOUT_VIEW: !0,
INTERSTITIAL_BANNER_SSP_ID: 14657,
INTERSTITIAL_BANNER_AD_DURATION: 10,
INTERSTITIAL_BANNER_WIDTH: 1,
INTERSTITIAL_BANNER_HEIGHT: 1
};
}
getSsp() {
return this.config.INTERSTITIAL_BANNER_SSP_ID;
}
getType() {
return S.INTERSTITIAL_BANNER;
}
handleTrigger(e) {
return new Promise((t, i) => {
this.initialize();
const I = {
...this.requestData,
motivated: !0,
widget_id: this.widgetId,
bid_floor: this.getDefaultBidFloor(),
width: this.config.INTERSTITIAL_BANNER_WIDTH,
height: this.config.INTERSTITIAL_BANNER_HEIGHT,
number_of_bids: 1
};
this.adRequestService.fetchAds(I, this.getSsp(), (r) => {
r.length === 0 && i(new Error("Ads not found")), this.displayInterstitialBannerAds(r), this.startTimer(this.config.INTERSTITIAL_BANNER_AD_DURATION);
const a = document.querySelector(".telegram-interstitial-banner-ad-overlay");
if (e && a) {
const _ = a.querySelector(".telegram-interstitial-banner-ad-image"), T = a.querySelector(".telegram-interstitial-banner-ad-content-link");
_ && T && T.href ? _.onload = () => {
document.getElementById("telegram-interstitial-banner-content").remove();
try {
this.openAdLink(T.href), t("success");
} catch {
i(new Error("New tab blocked"));
}
} : i(new Error("Missing ad image or link"));
}
document.addEventListener("click", function(_) {
_.target.closest(".telegram-interstitial-banner-ad-overlay") && t("success");
});
}).catch(i);
});
}
handle() {
this.initialize();
const e = {
...this.requestData,
motivated: !1,
widget_id: this.widgetId,
bid_floor: this.getDefaultBidFloor(),
width: this.config.INTERSTITIAL_BANNER_WIDTH,
height: this.config.INTERSTITIAL_BANNER_HEIGHT,
number_of_bids: 1
};
document.addEventListener("click", (t) => {
this.isNeededIgnoreClickByEvent(t) || this.isNeedFetchAds() && (this.waitShowed = !0, this.adRequestService.fetchAds(e, this.getSsp(), (i) => {
i.length > 0 && (this.displayInterstitialBannerAds(i), this.incrementInterstitialBannerCap(i.length)), this.waitShowed = !1;
}));
});
}
isCapped() {
if (this.waitShowed)
return !0;
let e = Math.floor(n.get(s.INTERSTITIAL_BANNER_CAP)) ?? 0;
return this.config.INTERSTITIAL_BANNER_LIMIT_IMPRESSION_PER_INTERVAL <= e || n.get(s.INTERSTITIAL_BANNER_EXPIRES_CAP) === 1;
}
incrementInterstitialBannerCap(e = 0) {
const t = {
capKey: s.INTERSTITIAL_BANNER_CAP,
expiresCapKey: s.INTERSTITIAL_BANNER_EXPIRES_CAP,
capIntervalKey: s.INTERSTITIAL_BANNER_CAP_PER_INTERVAL,
delay: this.config.INTERSTITIAL_BANNER_IMPRESSION_DELAY,
interval: this.config.INTERSTITIAL_BANNER_LIMIT_IMPRESSION_PER_INTERVAL,
showedItem: e
};
this.incrementCap(t);
}
isNeedFetchAds() {
var e;
return ((e = this.widgetManager) == null ? void 0 : e.getDebug()) === !0 || !this.isCapped();
}
displayInterstitialBannerAds(e) {
e.length > 0 && this.getOrCreateInterstitialBannerContainer(), e.forEach((t) => {
this.showInterstitialBannerAds(t);
});
}
getOrCreateInterstitialBannerContainer() {
const e = document.getElementById("telegram-interstitial-banner-content");
e == null || e.remove();
const t = document.createElement("div"), i = document.createElement("div");
return t.id = "telegram-interstitial-banner-content", t.className = "telegram-interstitial-banner-container", this.config.INTERSTITIAL_BANNER_CLOSABLE_WITHOUT_VIEW && (i.id = this.getIdCloseButton(), i.className = "telegram-interstitial-banner-close-btn", i.addEventListener("click", () => t.remove()), t.appendChild(i)), document.body.appendChild(t), t;
}
startTimer(e) {
let t = document.querySelector(".telegram-interstitial-banner-close-btn"), i = document.querySelector(".telegram-interstitial-banner-timer");
i.style.display = "block", t.style.display = "none";
function I(_) {
let T = Math.floor(_ / 60), l = _ % 60;
i.textContent = `${T}:${l.toString().padStart(2, "0")}`;
}
let r = e;
I(r);
let a = setInterval(function() {
r--, I(r), r <= 0 && (clearInterval(a), i.style.display = "none", t.style.display = "flex");
}, 1e3);
}
showInterstitialBannerAds(e) {
const t = document.getElementById("telegram-interstitial-banner-content");
if (!t)
throw new Error("Container telegram-notification-content not found.");
const i = document.createElement("div");
let I = "interstitial-banner-" + Math.random().toString(36).substr(2, 9);
i.innerHTML = `
<div class="telegram-interstitial-banner-ad-overlay" id="${I}">
<div class="telegram-interstitial-banner-timer"></div>
<div class="telegram-interstitial-banner-ad-container">
<img src="${e.icon}" class="telegram-interstitial-banner-icon" alt="telegram-interstitial-banner-avatar">
<a class="telegram-interstitial-banner-ad-content-link" href="${e.link}" target="_blank">
<div class="telegram-interstitial-banner-ad-block">
<img src="${e.banner}" class="telegram-interstitial-banner-ad-image" alt="telegram-interstitial-banner-banner">
<div class="telegram-interstitial-banner-ad-header">
<p class="telegram-interstitial-banner-ad-title">${e.title}</p>
</div>
<div class="telegram-interstitial-banner-ad-message">
<p>${e.message}</p>
</div>
<div class="telegram-interstitial-banner-ad-brand">
<p>${e.brand}</p>
</div>
<div class="telegram-interstitial-banner-ad-tail"></div>
</div>
<div class="telegram-interstitial-banner-ad-button">${e.button}</div>
</a>
</div>
</div>
`, t.appendChild(i);
const r = document.querySelector(".telegram-interstitial-banner-ad-content-link");
if (!r)
throw new Error("element telegram-interstitial-banner-ad-content-link not found.");
r.addEventListener("click", (a) => {
t.remove();
});
}
isConfigInstalledInLocalStorage() {
return n.get(s.INTERSTITIAL_BANNER_IMPRESSION_DELAY) && n.get(s.INTERSTITIAL_BANNER_IMPRESSION_INTERVAL) && n.get(s.INTERSTITIAL_BANNER_LIMIT_IMPRESSION_PER_INTERVAL) && n.get(s.INTERSTITIAL_BANNER_WIDTH) && n.get(s.INTERSTITIAL_BANNER_HEIGHT) && n.get(s.INTERSTITIAL_BANNER_AD_DURATION) && n.get(s.INTERSTITIAL_BANNER_SSP_ID) && n.get(s.INTERSTITIAL_BANNER_RESTART_LIMIT_IMPRESSIONS) !== void 0 && n.get(s.INTERSTITIAL_BANNER_CLOSABLE_WITHOUT_VIEW) !== void 0;
}
loadConfigByLocalStorage() {
this.config.INTERSTITIAL_BANNER_IMPRESSION_DELAY = Number(n.get(s.INTERSTITIAL_BANNER_IMPRESSION_DELAY)), this.config.INTERSTITIAL_BANNER_IMPRESSION_INTERVAL = Number(n.get(s.INTERSTITIAL_BANNER_IMPRESSION_INTERVAL)), this.config.INTERSTITIAL_BANNER_LIMIT_IMPRESSION_PER_INTERVAL = Number(n.get(s.INTERSTITIAL_BANNER_LIMIT_IMPRESSION_PER_INTERVAL)), this.config.INTERSTITIAL_BANNER_RESTART_LIMIT_IMPRESSIONS = n.get(s.INTERSTITIAL_BANNER_RESTART_LIMIT_IMPRESSIONS) === "true", this.config.INTERSTITIAL_BANNER_CLOSABLE_WITHOUT_VIEW = n.get(s.INTERSTITIAL_BANNER_CLOSABLE_WITHOUT_VIEW), this.config.INTERSTITIAL_BANNER_SSP_ID = Number(n.get(s.INTERSTITIAL_BANNER_SSP_ID)), this.config.INTERSTITIAL_BANNER_AD_DURATION = Number(n.get(s.INTERSTITIAL_BANNER_AD_DURATION)), this.config.INTERSTITIAL_BANNER_WIDTH = Number(n.get(s.INTERSTITIAL_BANNER_WIDTH)), this.config.INTERSTITIAL_BANNER_HEIGHT = Number(n.get(s.INTERSTITIAL_BANNER_HEIGHT));
}
updateConfigParams(e) {
let t = e.widget[this.getType()];
if (t && (t.ssp_id && (this.config.INTERSTITIAL_BANNER_SSP_ID = t.ssp_id ?? this.config.INTERSTITIAL_BANNER_SSP_ID), "config-interstitial-banner" in t)) {
let i = t["config-interstitial-banner"];
this.config.INTERSTITIAL_BANNER_IMPRESSION_DELAY = Number(i.impression_delay), this.config.INTERSTITIAL_BANNER_IMPRESSION_INTERVAL = Number(i.impression_interval), this.config.INTERSTITIAL_BANNER_LIMIT_IMPRESSION_PER_INTERVAL = Number(i.limit_impression_per_interval), this.config.INTERSTITIAL_BANNER_RESTART_LIMIT_IMPRESSIONS = i.restart_limit_impressions, this.config.INTERSTITIAL_BANNER_CLOSABLE_WITHOUT_VIEW = i.closable_without_view_available ?? this.config.INTERSTITIAL_BANNER_CLOSABLE_WITHOUT_VIEW, this.config.INTERSTITIAL_BANNER_AD_DURATION = Number(i.ad_duration), this.config.INTERSTITIAL_BANNER_WIDTH = Number(i.banner_width), this.config.INTERSTITIAL_BANNER_HEIGHT = Number(i.banner_height);
}
this.setLocalStorageConfig();
}
setLocalStorageConfig() {
n.set(s.INTERSTITIAL_BANNER_IMPRESSION_INTERVAL, this.config.INTERSTITIAL_BANNER_IMPRESSION_INTERVAL), n.set(s.INTERSTITIAL_BANNER_IMPRESSION_DELAY, this.config.INTERSTITIAL_BANNER_IMPRESSION_DELAY), n.set(s.INTERSTITIAL_BANNER_LIMIT_IMPRESSION_PER_INTERVAL, this.config.INTERSTITIAL_BANNER_LIMIT_IMPRESSION_PER_INTERVAL), n.set(s.INTERSTITIAL_BANNER_RESTART_LIMIT_IMPRESSIONS, this.config.INTERSTITIAL_BANNER_RESTART_LIMIT_IMPRESSIONS), n.set(s.INTERSTITIAL_BANNER_SSP_ID, this.config.INTERSTITIAL_BANNER_SSP_ID), n.set(s.INTERSTITIAL_BANNER_CLOSABLE_WITHOUT_VIEW, this.config.INTERSTITIAL_BANNER_CLOSABLE_WITHOUT_VIEW), n.set(s.INTERSTITIAL_BANNER_AD_DURATION, this.config.INTERSTITIAL_BANNER_AD_DURATION), n.set(s.INTERSTITIAL_BANNER_WIDTH, this.config.INTERSTITIAL_BANNER_WIDTH), n.set(s.INTERSTITIAL_BANNER_HEIGHT, this.config.INTERSTITIAL_BANNER_HEIGHT);
}
}
class v extends L {
constructor() {
super(...arguments), this.waitShowed = !1, this.PUBLISHER_ID_FOR_DIRECT_LINK = "958045", this.config = {
PUSH_STYLE_IMPRESSION_DELAY: 15,
PUSH_STYLE_IMPRESSION_INTERVAL: 86400,
PUSH_STYLE_LIMIT_IMPRESSION_PER_INTERVAL: 20,
PUSH_STYLE_LIMIT_IMPRESSION_PER_VIEW: 3,
PUSH_STYLE_RESTART_LIMIT_IMPRESSIONS: !1,
PUSH_STYLE_POSITION_TYPE: g.positionBottom,
PUSH_STYLE_CLOSABLE_WITHOUT_VIEW: !0,
PUSH_STYLE_SSP_ID: 13988
}, this.setPushStyleConfigParams = (e) => {
this.config.PUSH_STYLE_IMPRESSION_DELAY = Number(e.impression_delay), this.config.PUSH_STYLE_IMPRESSION_INTERVAL = Number(e.impression_interval), this.config.PUSH_STYLE_LIMIT_IMPRESSION_PER_INTERVAL = Number(e.limit_impression_per_interval), this.config.PUSH_STYLE_LIMIT_IMPRESSION_PER_VIEW = Number(e.limit_impression_per_view), this.config.PUSH_STYLE_RESTART_LIMIT_IMPRESSIONS = e.restart_limit_impressions, this.config.PUSH_STYLE_POSITION_TYPE = e.block_position ?? this.config.PUSH_STYLE_POSITION_TYPE, this.config.PUSH_STYLE_CLOSABLE_WITHOUT_VIEW = e.closable_without_view_available ?? this.config.PUSH_STYLE_CLOSABLE_WITHOUT_VIEW;
}, this.setLocalStorageConfig = () => {
n.set(s.PUSH_STYLE_IMPRESSION_INTERVAL, this.config.PUSH_STYLE_IMPRESSION_INTERVAL), n.set(s.PUSH_STYLE_IMPRESSION_DELAY, this.config.PUSH_STYLE_IMPRESSION_DELAY), n.set(s.PUSH_STYLE_LIMIT_IMPRESSION_PER_INTERVAL, this.config.PUSH_STYLE_LIMIT_IMPRESSION_PER_INTERVAL), n.set(s.PUSH_STYLE_LIMIT_IMPRESSION_PER_VIEW, this.config.PUSH_STYLE_LIMIT_IMPRESSION_PER_VIEW), n.set(s.PUSH_STYLE_RESTART_LIMIT_IMPRESSIONS, this.config.PUSH_STYLE_RESTART_LIMIT_IMPRESSIONS), n.set(s.PUSH_STYLE_POSITION_TYPE, this.config.PUSH_STYLE_POSITION_TYPE), n.set(s.PUSH_STYLE_CLOSABLE_WITHOUT_VIEW, this.config.PUSH_STYLE_CLOSABLE_WITHOUT_VIEW), n.set(s.PUSH_STYLE_SSP_ID, this.config.PUSH_STYLE_SSP_ID);
};
}
getSsp() {
return this.config.PUSH_STYLE_SSP_ID;
}
getType() {
return S.PUSH_STYLE;
}
getDefaultBidFloor() {
return 1e-3;
}
handleTrigger(e) {
return new Promise((t, i) => {
this.initialize();
const I = {
...this.requestData,
motivated: !0,
widget_id: this.widgetId,
bid_floor: this.getDefaultBidFloor(),
number_of_bids: this.config.PUSH_STYLE_LIMIT_IMPRESSION_PER_VIEW
};
this.adRequestService.fetchAds(I, this.getSsp(), (r) => {
r = this.updateFetchAdsData(r, I.publisher_id), r.length === 0 && i(new Error("Ads not found")), this.displayPushStyleAds(r);
const a = document.getElementById(this.getNameIdBlock());
if (e && a) {
const _ = a.querySelector(".notification-icon"), T = a.querySelector(".native-block-tg");
_ && T && T.href ? _.onload = () => {
const l = document.getElementById(this.getNameIdBlock());
l == null || l.remove();
try {
this.openAdLink(T.href), t("success");
} catch {
i(new Error("New tab blocked"));
}
} : i(new Error("Missing ad image or link"));
}
document.addEventListener("click", function(_) {
_.preventDefault(), _.target.closest(".native-block-tg") && t("success");
}, { once: !0 });
}).catch(i);
});
}
handle() {
this.initialize();
const e = {
...this.requestData,
motivated: !1,
widget_id: this.widgetId,
bid_floor: this.getDefaultBidFloor(),
number_of_bids: this.config.PUSH_STYLE_LIMIT_IMPRESSION_PER_VIEW
};
document.addEventListener("click", (t) => {
this.isNeededIgnoreClickByEvent(t) || this.isNeedFetchAds() && (this.waitShowed = !0, this.adRequestService.fetchAds(e, this.getSsp(), (i) => {
i = this.updateFetchAdsData(i, e.publisher_id), i.length > 0 && (this.displayPushStyleAds(i), this.incrementPushStyleCap(i.length)), this.waitShowed = !1;
}));
});
}
getNameIdBlock() {
return "telegram-notification-content";
}
isNeedFetchAds() {
var e;
return ((e = this.widgetManager) == null ? void 0 : e.getDebug()) === !0 || !this.isCapped();
}
isCapped() {
if (this.waitShowed)
return !0;
let e = Math.floor(n.get(s.PUSH_STYLE_CAP)) ?? 0;
return this.config.PUSH_STYLE_LIMIT_IMPRESSION_PER_INTERVAL <= e || n.get(s.PUSH_STYLE_EXPIRES_CAP) === 1;
}
incrementPushStyleCap(e = 0) {
const t = {
capKey: s.PUSH_STYLE_CAP,
expiresCapKey: s.PUSH_STYLE_EXPIRES_CAP,
capIntervalKey: s.PUSH_STYLE_CAP_PER_INTERVAL,
delay: this.config.PUSH_STYLE_IMPRESSION_DELAY,
interval: this.config.PUSH_STYLE_LIMIT_IMPRESSION_PER_INTERVAL,
showedItem: e
};
this.incrementCap(t);
}
isConfigInstalledInLocalStorage() {
return n.get(s.PUSH_STYLE_IMPRESSION_INTERVAL) && n.get(s.PUSH_STYLE_IMPRESSION_DELAY) && n.get(s.PUSH_STYLE_LIMIT_IMPRESSION_PER_INTERVAL) && n.get(s.PUSH_STYLE_LIMIT_IMPRESSION_PER_VIEW) && n.get(s.PUSH_STYLE_POSITION_TYPE) && n.get(s.PUSH_STYLE_SSP_ID) && n.get(s.PUSH_STYLE_RESTART_LIMIT_IMPRESSIONS) !== void 0 && n.get(s.PUSH_STYLE_CLOSABLE_WITHOUT_VIEW) !== void 0;
}
loadConfigByLocalStorage() {
this.config.PUSH_STYLE_IMPRESSION_DELAY = Number(n.get(s.PUSH_STYLE_IMPRESSION_DELAY)) || 0, this.config.PUSH_STYLE_IMPRESSION_INTERVAL = Number(n.get(s.PUSH_STYLE_IMPRESSION_INTERVAL)) || 0, this.config.PUSH_STYLE_LIMIT_IMPRESSION_PER_INTERVAL = Number(n.get(s.PUSH_STYLE_LIMIT_IMPRESSION_PER_INTERVAL)) || 0, this.config.PUSH_STYLE_LIMIT_IMPRESSION_PER_VIEW = Number(n.get(s.PUSH_STYLE_LIMIT_IMPRESSION_PER_VIEW)) || 0, this.config.PUSH_STYLE_RESTART_LIMIT_IMPRESSIONS = n.get(s.PUSH_STYLE_RESTART_LIMIT_IMPRESSIONS) === !0, this.config.PUSH_STYLE_POSITION_TYPE = n.get(s.PUSH_STYLE_POSITION_TYPE) || "", this.config.PUSH_STYLE_CLOSABLE_WITHOUT_VIEW = n.get(s.PUSH_STYLE_CLOSABLE_WITHOUT_VIEW) === !0, this.config.PUSH_STYLE_SSP_ID = Number(n.get(s.PUSH_STYLE_SSP_ID)) || this.config.PUSH_STYLE_SSP_ID;
}
updateConfigParams(e) {
this.setPushStyleConfigParams(e);
let t = e.widget[this.getType()];
t && (t.ssp_id && (this.config.PUSH_STYLE_SSP_ID = t.ssp_id ?? this.config.PUSH_STYLE_SSP_ID), "config" in t ? this.setPushStyleConfigParams(t.config) : "config-push-style" in t && this.setPushStyleConfigParams(t["config-push-style"])), this.setLocalStorageConfig();
}
updateFetchAdsData(e, t) {
return e.length === 0 && t === this.PUBLISHER_ID_FOR_DIRECT_LINK && (e = [{
title: "🎁 100% Bonus Up to $500! 🎁",
description: "🎰 Get Extra Cash with Our Generous First Deposit Bonus!",
image: "https://static.creatives.admachine.co/files/67daa21b23bf5_2025_03_19_10_53_15_image.jpeg",
image_preload: "https://static.creatives.admachine.co/files/67daa21b23bf5_2025_03_19_10_53_15_image.jpeg",
notification_url: "",
link: "https://11745.xml.4armn.com/direct-link?pubid=792489&siteid=1111",
bid_price: 1e-3,
creative_type: "native"
}]), e;
}
displayPushStyleAds(e) {
e.length > 0 && this.getOrCreatePushStyleContainer(), e.forEach((t, i) => {
this.showPushStyleAds(t, i === 0);
});
}
getOrCreatePushStyleContainer() {
const e = document.getElementById(this.getNameIdBlock());
e == null || e.remove();
const t = document.createElement("div"), i = document.createElement("div");
return t.id = this.getNameIdBlock(), t.className = "notification-container", t.classList.add(this.getClassTypePosition(this.config.PUSH_STYLE_POSITION_TYPE)), this.config.PUSH_STYLE_CLOSABLE_WITHOUT_VIEW && (i.id = this.getIdCloseButton(), i.className = "close-btn", i.addEventListener("click", () => t.remove()), t.appendChild(i)), document.body.appendChild(t), t;
}
showPushStyleAds({ title: e, description: t, image: i, link: I }, r) {
const a = document.getElementById(this.getNameIdBlock());
if (!a)
throw new Error(`Container ${this.getNameIdBlock()} not found.`);
const _ = document.createElement("div");
let T = "notification-" + Math.random().toString(36).substr(2, 9);
r && this.config.PUSH_STYLE_CLOSABLE_WITHOUT_VIEW && _.classList.add("first-block"), _.innerHTML = `
<a id="${T}" class="rp-notification show native-block-tg" href="${I}" target="_blank">
<img src="${i}" alt="icon" class="notification-icon" id="notification-icon">
<div class="notification-text">
<h4 id="notification-title">${e}</h4>
<p id="notification-description">${t}</p>
</div>
</a>
`, _.addEventListener("click", (l) => {
var c, N;
_.remove(), a.querySelectorAll(":scope > :not(.close-btn)").length === 0 && a.remove();
const o = document.querySelector(".rp-notification");
o && this.config.PUSH_STYLE_CLOSABLE_WITHOUT_VIEW && !((c = o.parentElement) != null && c.classList.contains("first-block")) && ((N = o.parentElement) == null || N.classList.add("first-block"));
}), a.appendChild(_);
}
getClassTypePosition(e) {
return e === g.positionBottom ? "notification-container-bottom" : e === g.positionTop ? "notification-container-top" : e === g.positionMiddle ? "notification-container-middle" : "";
}
}
class b extends L {
constructor() {
super(...arguments), this.waitShowed = !1, this.isPause = !1, this.videoLink = null, this.config = {
INTERSTITIAL_VIDEO_IMPRESSION_DELAY: 30,
INTERSTITIAL_VIDEO_IMPRESSION_INTERVAL: 86400,
INTERSTITIAL_VIDEO_LIMIT_IMPRESSION_PER_INTERVAL: 20,
INTERSTITIAL_VIDEO_RESTART_LIMIT_IMPRESSIONS: !1,
INTERSTITIAL_VIDEO_CLOSABLE_WITHOUT_VIEW: !1,
INTERSTITIAL_VIDEO_SSP_ID: 14862,
INTERSTITIAL_VIDEO_AD_DURATION: 10
}, this.togglePlayPause = () => {
let e = document.getElementById("adVideo");
const t = document.getElementById("videoPlaceholder");
e.paused ? (e.play(), this.isPause = !1, t.style.display = "none") : (e.pause(), this.isPause = !0, t.style.display = "block", this.openAdLink(this.videoLink));
};
}
getSsp() {
return this.config.INTERSTITIAL_VIDEO_SSP_ID;
}
getType() {
return S.INTERSTITIAL_VIDEO;
}
getConfigTypeName() {
return "config-interstitial-video";
}
handleTrigger(e) {
return new Promise((t, i) => {
this.initialize();
const I = {
...this.requestData,
motivated: !0,
widget_id: this.widgetId,
bid_floor: this.getDefaultBidFloor(),
number_of_bids: 1
};
this.adRequestService.fetchAds(I, this.getSsp(), (r) => {
r.length === 0 && i(new Error("Ads not found")), this.displayInterstitialVideoAds(r), document.addEventListener("click", function(a) {
a.target.closest(".telegram-interstitial-video-ad-overlay") && t("success");
});
}).catch(i);
});
}
handle() {
this.initialize();
const e = {
...this.requestData,
motivated: !1,
widget_id: this.widgetId,
bid_floor: this.getDefaultBidFloor(),
number_of_bids: 1
};
document.addEventListener("click", (t) => {
this.isNeededIgnoreClickByEvent(t) || this.isNeedFetchAds() && (this.waitShowed = !0, this.adRequestService.fetchAds(e, this.getSsp(), (i) => {
i.length > 0 && (this.displayInterstitialVideoAds(i), this.incrementInterstitialBannerCap(i.length)), this.waitShowed = !1;
}));
});
}
displayInterstitialVideoAds(e) {
e.length > 0 && this.getOrCreateInterstitialVideoContainer(), e.forEach((t) => {
this.showInterstitialVideoAds(t);
});
}
getOrCreateInterstitialVideoContainer() {
const e = document.getElementById("telegram-interstitial-video-content");
e == null || e.remove();
const t = document.createElement("div"), i = document.createElement("div");
return t.id = "telegram-interstitial-video-content", t.className = "telegram-interstitial-video-container", i.id = this.getIdCloseButton(), i.className = "telegram-interstitial-video-close-btn", i.addEventListener("click", () => t.remove()), i.style.display = "none", t.appendChild(i), document.body.appendChild(t), t;
}
showInterstitialVideoAds(e) {
const t = document.getElementById("telegram-interstitial-video-content");
if (!t)
throw new Error("Container telegram-interstitial-video-content not found.");
const i = document.createElement("div");
let I = "interstitial-video-" + Math.random().toString(36).substr(2, 9), r = this.config.INTERSTITIAL_VIDEO_AD_DURATION;
this.videoLink = e.link, i.innerHTML = `
<div class="telegram-interstitial-video-ad-overlay" id="${I}">
<div id="videoTimer" class="telegram-interstitial-video-timer">10</div>
<div class="telegram-interstitial-video-ad-container">
<img src="${e.icon}" class="telegram-interstitial-video-icon" alt="telegram-interstitial-video-avatar">
<div class="telegram-interstitial-video-ad-content-link">
<div class="telegram-interstitial-video-ad-block">
<div class="telegram-interstitial-video-block">
<video id="adVideo" class="telegram-interstitial-video-ad-image" playsinline muted autoplay>
<source src="${e.video}" type="video/mp4">
</video>
<div id="videoPlaceholder" class="video-placeholder">
<button id="playButton">▶</button>
</div>
<button id="muteToggle" class="video-mute-button">🔇</button>
</div>
<div class="telegram-interstitial-video-ad-header">
<p class="telegram-interstitial-video-ad-title">${e.title}</p>
</div>
<div class="telegram-interstitial-video-ad-message">
<p>${e.message}</p>
</div>
<button id="closeAd" disabled> Close in ${r}</button>
<div class="telegram-interstitial-video-ad-tail"></div>
</div>
<div class="telegram-interstitial-video-ad-button">${e.button}</div>
</div>
</div>
</div>
`, t.appendChild(i);
let a = document.getElementById("adVideo");
const _ = document.getElementById("muteToggle"), T = document.getElementById("closeAd"), l = document.getElementById("videoPlaceholder"), o = document.getElementById("videoTimer"), c = document.querySelector(".telegram-interstitial-video-close-btn"), N = document.querySelector(".telegram-interstitial-video-ad-button"), d = setInterval(() => {
this.isPause || (r--, o.textContent = r.toString(), T.textContent = `Close in ${r}`, r <= 0 && (clearInterval(d), T.style.display = "none", c.style.display = "flex"));
}, 1e3);
a && (_.addEventListener("click", () => {
a.muted = !a.muted, _.textContent = a.muted ? "🔇" : "🔊";
}), T.addEventListener("click", () => {
t.remove();
}), N.addEventListener("click", () => {
this.openAdLink(this.videoLink), r <= 0 && t.remove();
}), a.play().then((u) => {
l.style.display = "none";
}).catch(() => console.log("Autoplay disabled")), a.addEventListener("click", this.togglePlayPause), l.addEventListener("click", this.togglePlayPause));
}
isCapped() {
if (this.waitShowed)
return !0;
let e = Math.floor(n.get(s.PUSH_STYLE_CAP)) ?? 0;
return this.config.INTERSTITIAL_VIDEO_LIMIT_IMPRESSION_PER_INTERVAL <= e || n.get(s.PUSH_STYLE_EXPIRES_CAP) === 1;
}
isNeedFetchAds() {
var e;
return ((e = this.widgetManager) == null ? void 0 : e.getDebug()) === !0 || !this.isCapped();
}
incrementInterstitialBannerCap(e = 0) {
const t = {
capKey: s.INTERSTITIAL_VIDEO_CAP,
expiresCapKey: s.INTERSTITIAL_VIDEO_EXPIRES_CAP,
capIntervalKey: s.INTERSTITIAL_VIDEO_CAP_PER_INTERVAL,
delay: this.config.INTERSTITIAL_VIDEO_IMPRESSION_DELAY,
interval: this.config.INTERSTITIAL_VIDEO_LIMIT_IMPRESSION_PER_INTERVAL,
showedItem: e
};
this.incrementCap(t);
}
isConfigInstalledInLocalStorage() {
return n.get(s.INTERSTITIAL_VIDEO_IMPRESSION_DELAY) && n.get(s.INTERSTITIAL_VIDEO_IMPRESSION_INTERVAL) && n.get(s.INTERSTITIAL_VIDEO_LIMIT_IMPRESSION_PER_INTERVAL) && n.get(s.INTERSTITIAL_VIDEO_AD_DURATION) && n.get(s.INTERSTITIAL_VIDEO_SSP_ID) && n.get(s.INTERSTITIAL_VIDEO_RESTART_LIMIT_IMPRESSIONS) !== void 0 && n.get(s.INTERSTITIAL_VIDEO_CLOSABLE_WITHOUT_VIEW) !== void 0;
}
loadConfigByLocalStorage() {
this.config.INTERSTITIAL_VIDEO_IMPRESSION_DELAY = Number(n.get(s.INTERSTITIAL_VIDEO_IMPRESSION_DELAY)), this.config.INTERSTITIAL_VIDEO_IMPRESSION_INTERVAL = Number(n.get(s.INTERSTITIAL_VIDEO_IMPRESSION_INTERVAL)), this.config.INTERSTITIAL_VIDEO_LIMIT_IMPRESSION_PER_INTERVAL = Number(n.get(s.INTERSTITIAL_VIDEO_LIMIT_IMPRESSION_PER_INTERVAL)), this.config.INTERSTITIAL_VIDEO_RESTART_LIMIT_IMPRESSIONS = n.get(s.INTERSTITIAL_VIDEO_RESTART_LIMIT_IMPRESSIONS) === !0, this.config.INTERSTITIAL_VIDEO_CLOSABLE_WITHOUT_VIEW = n.get(s.INTERSTITIAL_VIDEO_CLOSABLE_WITHOUT_VIEW) === !0, this.config.INTERSTITIAL_VIDEO_SSP_ID = Number(n.get(s.INTERSTITIAL_VIDEO_SSP_ID)), this.config.INTERSTITIAL_VIDEO_AD_DURATION = Number(n.get(s.INTERSTITIAL_VIDEO_AD_DURATION));
}
updateConfigParams(e) {
let t = e.widget[this.getType()];
if (t && (t.ssp_id && (this.config.INTERSTITIAL_VIDEO_SSP_ID = t.ssp_id ?? this.config.INTERSTITIAL_VIDEO_SSP_ID), this.getConfigTypeName() in t)) {
let i = t[this.getConfigTypeName()];
this.config.INTERSTITIAL_VIDEO_IMPRESSION_DELAY = Number(i.impression_delay), this.config.INTERSTITIAL_VIDEO_IMPRESSION_INTERVAL = Number(i.impression_interval), this.config.INTERSTITIAL_VIDEO_LIMIT_IMPRESSION_PER_INTERVAL = Number(i.limit_impression_per_interval), this.config.INTERSTITIAL_VIDEO_RESTART_LIMIT_IMPRESSIONS = i.restart_limit_impressions ?? this.config.INTERSTITIAL_VIDEO_RESTART_LIMIT_IMPRESSIONS, this.config.INTERSTITIAL_VIDEO_CLOSABLE_WITHOUT_VIEW = i.closable_without_view_available ?? this.config.INTERSTITIAL_VIDEO_CLOSABLE_WITHOUT_VIEW, this.config.INTERSTITIAL_VIDEO_AD_DURATION = Number(i.ad_duration) ?? this.config.INTERSTITIAL_VIDEO_AD_DURATION;
}
this.setLocalStorageConfig();
}
setLocalStorageConfig() {
n.set(s.INTERSTITIAL_VIDEO_IMPRESSION_INTERVAL, this.config.INTERSTITIAL_VIDEO_IMPRESSION_INTERVAL), n.set(s.INTERSTITIAL_VIDEO_IMPRESSION_DELAY, this.config.INTERSTITIAL_VIDEO_IMPRESSION_DELAY), n.set(s.INTERSTITIAL_VIDEO_LIMIT_IMPRESSION_PER_INTERVAL, this.config.INTERSTITIAL_VIDEO_LIMIT_IMPRESSION_PER_INTERVAL), n.set(s.INTERSTITIAL_VIDEO_RESTART_LIMIT_IMPRESSIONS, this.config.INTERSTITIAL_VIDEO_RESTART_LIMIT_IMPRESSIONS), n.set(s.INTERSTITIAL_VIDEO_SSP_ID, this.config.INTERSTITIAL_VIDEO_SSP_ID), n.set(s.INTERSTITIAL_VIDEO_CLOSABLE_WITHOUT_VIEW, this.config.INTERSTITIAL_VIDEO_CLOSABLE_WITHOUT_VIEW), n.set(s.INTERSTITIAL_VIDEO_AD_DURATION, this.config.INTERSTITIAL_VIDEO_AD_DURATION);
}
}
class V {
constructor() {
this.publisherId = "", this.appId = "", this.debug = !1, this.shouldUpdateConfig = !1, this.activeWidgetTypes = [], this.pushStyleAutoMode = !1, this.embeddedBannerAutoMode = !1, this.interstitialBannerAutoMode = !1, this.interstitialVideoAutoMode = !1, this.isPremium = !1, this.initAppSettings = () => {
if (this.isUploadedOldVersion()) {
this.shouldUpdateConfig = !0;
return;
}
if (n.getWithPrefix(s.WIDGET_TYPE) && n.getWithPrefix(s.ACTIVE_WIDGET_TYPE) && n.getWithPrefix(s.CONFIG_UPDATE_TIME) && n.getWithPrefix(s.PUSH_STYLE_AUTO_MODE) !== void 0 && n.getWithPrefix(s.EMBEDDED_BANNER_AUTO_MODE) !== void 0 && n.getWithPrefix(s.INTERSTITIAL_BANNER_AUTO_MODE) !== void 0 && n.getWithPrefix(s.INTERSTITIAL_VIDEO_AUTO_MODE) !== void 0) {
this.widgetTypes = n.getWithPrefix(s.WIDGET_TYPE), this.activeWidgetTypes = n.getWithPrefix(s.ACTIVE_WIDGET_TYPE), this.pushStyleAutoMode = n.getWithPrefix(s.PUSH_STYLE_AUTO_MODE), this.embeddedBannerAutoMode = n.getWithPrefix(s.EMBEDDED_BANNER_AUTO_MODE), this.interstitialBannerAutoMode = n.getWithPrefix(s.INTERSTITIAL_BANNER_AUTO_MODE), this.interstitialVideoAutoMode = n.getWithPrefix(s.INTERSTITIAL_VIDEO_AUTO_MODE), this.isPremium = n.getWithPrefix(s.IS_PREMIUM);
return;
}
this.shouldUpdateConfig = !0;
}, this.initPersonalSettings = () => {
if (!this.shouldUpdateConfig) {
let e = null;
this.activeWidgetTypes.forEach((t) => {
e = h.createRichPartnersAdsByType(String(t)), e.isConfigInstalledInLocalStorage() ? e.loadConfigByLocalStorage() : this.shouldUpdateConfig = !0;
});
}
}, this.transformWidgetTypes = (e) => {
const t = {
PUSH_STYLE: "",
EMBEDDED_BANNER: ""
};
return e.native || e.banner ? (e.native && (t.PUSH_STYLE = e.native), e.banner && (t.EMBEDDED_BANNER = e.banner)) : Object.assign(t, e), t;
};
}
/**
* @param config
*/
initialize(e) {
this.publisherId = e.pubId, this.appId = e.appId, this.debug = e.debug ?? !1, this.initAppSettings(), this.initPersonalSettings(), this.shouldUpdateConfig && this.loadConfiguration().then((t) => {
this.updateAppConfigs(t), this.updateWidgetConfigs(t);
}).catch((t) => {
throw new Error(t.toString());
});
}
async loadConfiguration() {
const e = await fetch(this.getJsonConfigUrl(), {
method: "GET",
headers: {
accept: "application/json"
}
});
if (!e.ok)
throw new Error("Network response was not ok");
return (await e.json()).telegram;
}
getDebug() {
return this.debug;
}
getActiveWidgetTypes() {
return this.activeWidgetTypes;
}
getWidgetIdByType(e) {
return this.isWidgetTypeValid(e) ? String(this.widgetTypes[e]) : null;
}
isWidgetTypeValid(e) {
return this.widgetTypes[e] && this.activeWidgetTypes.includes(e);
}
updateAppConfigs(e) {
let t = e.app_id[this.appId];
t && (this.widgetTypes = this.transformWidgetTypes(t.widgetTypes), this.activeWidgetTypes = [], this.pushStyleAutoMode = (t.pushStyleAutoMode ?? !1) || (t.nativeAutoMode ?? !1), this.embeddedBannerAutoMode = (t.embeddedBannerAutoMode ?? !1) || (t.bannerAutoMode ?? !1), this.interstitialBannerAutoMode = t.embeddedBannerAutoMode ?? !1, (t.activeWidgetTypes.includes(S.PUSH_STYLE_OLD) || t.activeWidgetTypes.includes(S.PUSH_STYLE)) && this.activeWidgetTypes.push(S.PUSH_STYLE), (t.activeWidgetTypes.includes(S.EMBEDDED_BANNER_OLD) || t.activeWidgetTypes.includes(S.EMBEDDED_BANNER)) && this.activeWidgetTypes.push(S.EMBEDDED_BANNER), t.activeWidgetTypes.includes(S.INTERSTITIAL_BANNER) && this.activeWidgetTypes.push(S.INTERSTITIAL_BANNER), t.activeWidgetTypes.includes(S.INTERSTITIAL_VIDEO) && this.activeWidgetTypes.push(S.INTERSTITIAL_VIDEO), n.set(s.WIDGET_TYPE, this.widgetTypes), n.set(s.ACTIVE_WIDGET_TYPE, this.activeWidgetTypes), n.set(s.PUSH_STYLE_AUTO_MODE, this.pushStyleAutoMode), n.set(s.EMBEDDED_BANNER_AUTO_MODE, this.embeddedBannerAutoMode), n.set(s.INTERSTITIAL_BANNER_AUTO_MODE, this.interstitialBannerAutoMode), n.set(s.INTERSTITIAL_VIDEO_AUTO_MODE, this.interstitialVideoAutoMode), n.set(s.CONFIG_UPDATE_TIME, 1, M));
}
updateWidgetConfigs(e) {
let t = null;
this.activeWidgetTypes.forEach((i) => {
t = h.createRichPartnersAdsByType(String(i)), t.updateConfigParams(e), t.setWidgetId(this.widgetTypes[t.getType()]);
});
}
isUploadedOldVersion() {
const e = n.get(s.ACTIVE_WIDGET_TYPE) || [];
return e.includes(S.EMBEDDED_BANNER_OLD) || e.includes(S.PUSH_STYLE_OLD);
}
getJsonConfigUrl() {
const e = m.MD5(String(this.publisherId));
return O + e + ".json";
}
}
class U {
constructor() {
this.USERINFO_ENDPOINT = "https://eu.convers.link/users/info?callback=userinfo_rp_pu", this.USERINFO_ENDPOINT_2 = "https://us.convers.link/users/info?callback=userinfo_rp_pu", this.publisherInfo = { ip: "" };
}
async setIp() {
const e = Math.random() < 0.5 ? this.USERINFO_ENDPOINT : this.USERINFO_ENDPOINT_2;
return new Promise((t, i) => {
window.userinfo_rp_pu = (I) => {
this.publisherInfo.ip = I.ip, t();
}, w.loadJs(e).catch(i);
});
}
getIp() {
return this.publisherInfo.ip;
}
}
class w {
static async loadJs(e) {
if (!document.querySelector(`script[src="${e}"]`))
return new Promise((t, i) => {
const I = document.createElement("script");
Object.assign(I, {
type: "text/javascript",
src: e,
async: !0,
onload: () => t(),
onerror: () => i(new Error(`Failed to load script: ${e}`))
}), document.head.appendChild(I);
});
}
static loadCss(e) {
if (document.querySelector(`link[href="${e}"]`)) return;
const t = document.createElement("link");
Object.assign(t, {
rel: "stylesheet",
type: "text/css",
href: e,
media: "all"
}), document.head.appendChild(t);
}
}
class C {
set(e, t, i = null) {
if (i !== null) {
const I = Date.now(), r = {
value: t,
ttl: I + i * 1e3
};
localStorage.setItem(e, JSON.stringify(r));
} else
localStorage.setItem(e, JSON.stringify(t));
}
get(e) {
const t = localStorage.getItem(e);
if (!t) return null;
if (t !== "undefined")
try {
const i = JSON.parse(t);
return i.ttl && Date.now() > i.ttl ? (localStorage.removeItem(e), null) : i.value || i;
} catch {
return t;
}
}
remove(e) {
localStorage.removeItem(e);
}
clear() {
localStorage.clear();
}
getWithPrefix(e) {
return n.get(e);
}
}
const n = new C();
class H {
constructor() {
this.telegramData = {};
}
initTelegramData(e) {
var a, _, T, l;
if (typeof window > "u")
throw new Error("RichPartnersTelegramAds can only be called in a browser environment.");
if (e) {
this.telegramData = {
telegram_id: "123456789",
language_code: "en",
premium: !1,
last_name: "publisher",
firstName: "publisher",
version: "8.0",
platform: "weba"
};
return;
}
D(), (a = p) != null && a.user, (_ = window.Telegram) != null && _.WebApp;
const t = sessionStorage.getItem("__telegram__initParams"), i = sessionStorage.getItem("tapps/launchParams") ?? sessionStorage.getItem("telegram-apps/launch-params") ?? sessionStorage.getItem("tma.js/launch-params"), I = t && JSON.parse(t), r = i && JSON.parse(i);
if (I && Object.keys(I).length) {
const o = JSON.parse(t), N = new URLSearchParams(o.tgWebAppData).get("user"), d = N ? JSON.parse(decodeURIComponent(N)) : {};
if (d.id === void 0)
throw new Error("initParams not installed.");
this.telegramData = {
telegram_id: String(d.id || ""),
language_code: d.language_code || "",
premium: d.is_premium || !1,
last_name: d.last_name || "",
firstName: d.first_name || "",
version: o.tgWebAppVersion || "",
platform: o.tgWebAppPlatform || ""
};
} else if (r && Object.keys(r).length) {
const o = decodeURIComponent(r), c = new URLSearchParams(o), N = c.get("user"), d = c.get("tgWebAppData"), u = c.get("tgWebAppVersion"), P = c.get("tgWebAppPlatform");
if (N) {
let A = JSON.parse(decodeURIComponent(N));
this.telegramData = {
telegram_id: String(A.id || ""),
language_code: A.language_code || "",
premium: A.is_premium || !1,
last_name: A.last_name || "",
firstName: A.first_name || "",
version: u || "",
platform: P || ""
};
}
if (d) {
const f = new URLSearchParams(d).get("user");
if (f) {
const R = JSON.parse(f);
this.telegramData = {
telegram_id: String(R.id || ""),
language_code: R.language_code || "",
premium: R.is_premium || !1,
last_name: R.last_name || "",
firstName: R.first_name || "",
version: u || "",
platform: P || ""
};
}
}
} else {
if (window.Telegram === void 0)
throw new Error("The script telegram-web-app.js not connected.");
const o = (T = window.Telegram) == null ? void 0 : T.WebApp;
if (!((l = o == null ? void 0 : o.initDataUnsafe) != null && l.user))
throw new Error("telegram user not found.");
this.telegramData = {
telegram_id: String(o.initDataUnsafe.user.id),
language_code: o.initDataUnsafe.user.language_code,
premium: o.initDataUnsafe.user.is_premium || !1,
last_name: o.initDataUnsafe.user.last_name || "",
firstName: o.initDataUnsafe.user.first_name,
version: o.version
};
}
}
getTelegramData(e) {
return this.initTelegramData(e), this.telegramData;
}
}
class W {
constructor(e = !1) {
this.debug = e, this.TELEGRAM_BID_BASE_ENDPOINT = "https://{{ssp_id}}.xml.4armn.com/telegram-bid";
}
async fetchAds(e, t, i) {
if (this.debug) {
i(this.generateDebugAdData());
return;
}
try {
const I = this.TELEGRAM_BID_BASE_ENDPOINT.replace("{{ssp_id}}", String(t)), a = await (await fetch(I, {
method: "POST",
body: JSON.stringify(e)
})).json();
i(Array.isArray(a) ? a : []);
} catch {
throw new Error("[fetchAds] Error fetching ads:");
}
}
generateDebugAdData(e = 1) {
const t = [];
for (let i = 0; i < e; i++)
t.push({
title: `Weather Forecaster ${i + 1}`,
description: `Accurate 12 Day Weather Forecasts for thousands of places around the World ${i + 1}`,
image: "https://richads.com/assets/img/logos/crown-desk.svg",
banner: "https://richads.com/assets/img/logos