@slashedcloud/player
Version:
A media player application utilizing Shaka Player for adaptive video streaming, capable of playing HLS, MPD and plain HTTP video streams.
116 lines (115 loc) • 3.67 kB
JavaScript
import '../AdBlockDetector.css';var m = Object.defineProperty;
var y = (a, e, t) => e in a ? m(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
var u = (a, e, t) => y(a, typeof e != "symbol" ? e + "" : e, t);
var h = (a, e, t) => new Promise((s, r) => {
var d = (n) => {
try {
o(t.next(n));
} catch (c) {
r(c);
}
}, i = (n) => {
try {
o(t.throw(n));
} catch (c) {
r(c);
}
}, o = (n) => n.done ? s(n.value) : Promise.resolve(n.value).then(d, i);
o((t = t.apply(a, e)).next());
});
import b from "./Base.js";
/*!
* SlashedCloud v0.1.2 (https://github.com/SlashedCloud/player#readme)
* Copyright 2024-2024 rogerio.jardim@fedrax.pt
* Licensed under Apache (https://github.com/SlashedCloud/player/blob/develop/LICENSE)
*/
var l = {};
Object.defineProperty(l, "__esModule", { value: !0 });
var p = l.AdblockDetector = void 0;
class k {
constructor() {
this.bannerIds = ["AdHeader", "AdContainer", "AD_Top", "homead", "ad-lead"], this.init();
}
/**
* Init library - add some tags to page with ads ids
*
* @returns {void} create detector instance
* @memberof AdblockDetector
*/
init() {
if (!this.isBrowser()) {
console.error("Detection on server side is not supported. Please use library only on client side.");
return;
}
const e = document.createElement("div");
e.innerHTML = this.generatesBannersString(), document.body.append(e);
}
/**
* Check enabling adblock
*
* @returns {Boolean} Status adblock enabling
* @memberof AdblockDetector
*/
detect() {
return this.isBrowser() ? !this.bannerIds.every((e) => this.checkVisibility(e)) : !1;
}
/**
* Generate all ads blocks from ids dictionary
*
* @returns {String} Ads blocks
* @private
* @memberof AdblockDetector
*/
generatesBannersString() {
return this.bannerIds.map((e) => `<div id="${e}"></div>`).join("");
}
/**
* Check visibility by banner id
*
* @param {Number} bannerId
* @returns {HTMLElement|null} Return banners if adblock is not enabled
* @private
* @memberof AdblockDetector
*/
checkVisibility(e) {
const t = document.querySelector(`#${e}`);
return t ? t.offsetParent : null;
}
isBrowser() {
return typeof window != "undefined";
}
}
p = l.AdblockDetector = k;
class D extends b {
constructor(t) {
super(t);
u(this, "name", "AdBlockDetectorPlugin");
}
setup() {
return h(this, null, function* () {
if (!new p().detect()) return;
this.player.container.classList.add("shaka-adblock-detected");
const r = document.createElement("div");
r.classList.add("shaka-modal", "active");
const d = document.createElement("div");
d.classList.add("shaka-modal-dialog");
const i = document.createElement("div");
i.classList.add("shaka-modal-content");
const o = document.createElement("div");
o.classList.add("shaka-ads"), o.innerHTML = '<i class="material-icons-round">error</i><h3>Ads</h3>';
const n = document.createElement("h3");
n.textContent = this.local("DISABLE_ADBLOCKER", "Please disable your ad blocker!"), i.appendChild(o), i.appendChild(n), d.appendChild(i), r.appendChild(d), this.player.once("ready", this.onReady.bind(this, r));
});
}
onReady(t) {
this.player.container.innerHTML = this.player.videoElement.outerHTML, this.player.container.appendChild(t), this.player.emit("adBlockDetected");
}
local(t, s) {
if (!this.player.localization) return s;
const r = this.player.localization.resolve(t);
return r || s;
}
}
export {
D as default
};