h
This commit is contained in:
@@ -0,0 +1,208 @@
|
||||
// AdinPlay Ad Provider Module
|
||||
// This module handles all AdinPlay-specific ad functionality
|
||||
|
||||
(function() {
|
||||
console.log("[adinplay-ads.js] Module loading...");
|
||||
|
||||
// AdinPlay tag mapping - can be customized per game
|
||||
const ADINPLAY_TAG_MAPPING = {
|
||||
"300x250": "2v2-io_300x250",
|
||||
"728x90": "2v2-io_728x90",
|
||||
"300x600": "2v2-io_300x600"
|
||||
};
|
||||
|
||||
// Ensure global providers exist
|
||||
window.videoAdProviders = window.videoAdProviders || {};
|
||||
window.bannerAdProviders = window.bannerAdProviders || {};
|
||||
|
||||
// AdinPlay initialization
|
||||
function initAdinPlay() {
|
||||
console.log("[adinplay-ads.js] Initializing AdinPlay...");
|
||||
|
||||
window.aiptag = window.aiptag || { cmd: [] };
|
||||
aiptag.cmd.display = aiptag.cmd.display || [];
|
||||
aiptag.cmd.player = aiptag.cmd.player || [];
|
||||
aiptag.cmp = {
|
||||
show: true,
|
||||
position: "bottom",
|
||||
button: false,
|
||||
buttonText: "Privacy settings",
|
||||
buttonPosition: "bottom-left"
|
||||
};
|
||||
|
||||
// aiptag.pageProtect = true;
|
||||
|
||||
aiptag.cmd.player.push(function () {
|
||||
console.log("[adinplay-ads.js] Creating AdinPlay player...");
|
||||
aiptag.adplayer = new aipPlayer({
|
||||
AD_WIDTH: 960,
|
||||
AD_HEIGHT: 540,
|
||||
AD_DISPLAY: 'fullscreen',
|
||||
LOADING_TEXT: 'Loading advertisement',
|
||||
PREROLL_ELEM: function () {
|
||||
const elem = document.getElementById('videoad');
|
||||
console.log(`[adinplay-ads.js] Preroll element: ${elem ? 'found' : 'not found'}`);
|
||||
return elem;
|
||||
},
|
||||
AIP_COMPLETE: function (state) {
|
||||
console.log(`[adinplay-ads.js] Video Ad Completed: ${state}`);
|
||||
|
||||
const lowerCaseState = state.toLowerCase();
|
||||
const isFailure = lowerCaseState.includes("adblock") ||
|
||||
lowerCaseState.includes("failed") ||
|
||||
lowerCaseState.includes("empty") ||
|
||||
lowerCaseState.includes("error");
|
||||
|
||||
if (isFailure) {
|
||||
console.log("[adinplay-ads.js] Ad failed");
|
||||
if (window._adinplayTempFailure) {
|
||||
window._adinplayTempFailure();
|
||||
delete window._adinplayTempFailure;
|
||||
delete window._adinplayTempSuccess;
|
||||
} else if (typeof unityInstance !== 'undefined') {
|
||||
unityInstance.SendMessage("SDKManager", "OnVideoAdEnded", "false");
|
||||
}
|
||||
} else {
|
||||
console.log("[adinplay-ads.js] Ad succeeded");
|
||||
if (window._adinplayTempSuccess) {
|
||||
window._adinplayTempSuccess();
|
||||
delete window._adinplayTempSuccess;
|
||||
delete window._adinplayTempFailure;
|
||||
} else if (typeof unityInstance !== 'undefined') {
|
||||
unityInstance.SendMessage("SDKManager", "OnVideoAdEnded", "true");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log("[adinplay-ads.js] AdinPlay player created");
|
||||
});
|
||||
|
||||
// Load the AdinPlay script
|
||||
console.log("[adinplay-ads.js] Loading AdinPlay script...");
|
||||
const adinplayScript = document.createElement('script');
|
||||
adinplayScript.type = "text/javascript";
|
||||
adinplayScript.src = '//api.adinplay.com/libs/aiptag/pub/LGP/2v2.io/tag.min.js';
|
||||
adinplayScript.async = true;
|
||||
adinplayScript.onload = function() {
|
||||
console.log("[adinplay-ads.js] Script loaded successfully");
|
||||
};
|
||||
adinplayScript.onerror = function() {
|
||||
console.error("[adinplay-ads.js] Failed to load script");
|
||||
};
|
||||
document.head.appendChild(adinplayScript);
|
||||
}
|
||||
|
||||
// Video ad provider implementation
|
||||
window.videoAdProviders.adinplay = {
|
||||
showMidroll: function(onSuccess, onFailure) {
|
||||
console.log(`[adinplay-ads.js] showMidroll called`);
|
||||
|
||||
if (typeof aiptag !== 'undefined' && typeof aiptag.adplayer !== 'undefined') {
|
||||
window._adinplayTempSuccess = onSuccess;
|
||||
window._adinplayTempFailure = onFailure;
|
||||
|
||||
aiptag.cmd.player.push(function () {
|
||||
console.log(`[adinplay-ads.js] Starting preroll`);
|
||||
aiptag.adplayer.startPreRoll();
|
||||
});
|
||||
} else {
|
||||
console.log(`[adinplay-ads.js] API not available`);
|
||||
onFailure();
|
||||
}
|
||||
},
|
||||
showRewarded: function(onSuccess, onFailure) {
|
||||
console.log(`[adinplay-ads.js] showRewarded called (delegates to showMidroll)`);
|
||||
this.showMidroll(onSuccess, onFailure);
|
||||
}
|
||||
};
|
||||
|
||||
// Banner ad provider implementation
|
||||
window.bannerAdProviders.adinplay = {
|
||||
displayBanner: async function(adTag, container) {
|
||||
console.log(`[adinplay-ads.js] displayBanner for tag: ${adTag}`);
|
||||
|
||||
// Map generic adTag to AdinPlay-specific tag
|
||||
const adinplayTag = ADINPLAY_TAG_MAPPING[adTag];
|
||||
if (!adinplayTag) {
|
||||
console.error(`[adinplay-ads.js] No mapping found for adTag: ${adTag}`);
|
||||
return false;
|
||||
}
|
||||
console.log(`[adinplay-ads.js] Using AdinPlay tag: ${adinplayTag}`);
|
||||
|
||||
// Ensure our container has a proper placeholder element for AdinPlay
|
||||
try {
|
||||
// Remove any existing placeholder with the same id elsewhere
|
||||
const existing = document.getElementById(adinplayTag);
|
||||
if (existing && existing.parentNode) {
|
||||
existing.parentNode.removeChild(existing);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
// Clear and prepare container
|
||||
container.innerHTML = "";
|
||||
const placeholder = document.createElement('div');
|
||||
placeholder.id = adinplayTag;
|
||||
placeholder.style.width = '100%';
|
||||
placeholder.style.height = '100%';
|
||||
placeholder.style.position = 'relative';
|
||||
container.appendChild(placeholder);
|
||||
|
||||
// Wait for AdinPlay to be ready
|
||||
const isReady = await window.waitForAdinPlay();
|
||||
|
||||
if (!(isReady && typeof aiptag !== "undefined" && typeof aipDisplayTag !== "undefined")) {
|
||||
console.log(`[adinplay-ads.js] Not available for banner`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Display and verify fill. Resolve true only if creative appears; else false to allow fallback
|
||||
return await new Promise((resolve) => {
|
||||
let settled = false;
|
||||
|
||||
const settle = (ok) => {
|
||||
if (!settled) { settled = true; resolve(ok); }
|
||||
};
|
||||
|
||||
// Observe for injected content
|
||||
const observer = new MutationObserver(() => {
|
||||
// Ad networks typically inject iframes or images
|
||||
const hasCreative = placeholder.querySelector('iframe, img, ins, div');
|
||||
if (hasCreative && placeholder.children.length > 0) {
|
||||
observer.disconnect();
|
||||
settle(true);
|
||||
}
|
||||
});
|
||||
try {
|
||||
observer.observe(placeholder, { childList: true, subtree: true });
|
||||
} catch {}
|
||||
|
||||
// Safety timeout in case nothing is injected (e.g., adblock)
|
||||
const timeoutMs = 3000;
|
||||
const timeoutId = setTimeout(() => {
|
||||
observer.disconnect();
|
||||
// Consider it a failure if no children were added
|
||||
const ok = placeholder.children.length > 0;
|
||||
settle(ok);
|
||||
}, timeoutMs);
|
||||
|
||||
// Request display
|
||||
aiptag.cmd.display.push(function() {
|
||||
try {
|
||||
aipDisplayTag.display(adinplayTag);
|
||||
} catch (e) {
|
||||
clearTimeout(timeoutId);
|
||||
observer.disconnect();
|
||||
settle(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize AdinPlay
|
||||
initAdinPlay();
|
||||
|
||||
console.log("[adinplay-ads.js] Module loaded successfully");
|
||||
})();
|
||||
@@ -0,0 +1,298 @@
|
||||
// CPMStar Ad Provider Module
|
||||
// This module handles all CPMStar-specific ad functionality
|
||||
|
||||
(function() {
|
||||
console.log("[cpmstar-ads.js] Module loading...");
|
||||
|
||||
// Ensure global providers exist
|
||||
window.videoAdProviders = window.videoAdProviders || {};
|
||||
window.bannerAdProviders = window.bannerAdProviders || {};
|
||||
|
||||
// CPMStar configuration
|
||||
const CPMSTAR_ZONE_FILE = '1137_54105_gameapi';
|
||||
|
||||
// CPMStar banner placement IDs (replace with your actual placement IDs)
|
||||
window.cpmstarBannerMapping = {
|
||||
0: '88824', // 300x250
|
||||
1: '88823', // 728x90
|
||||
2: '88827' // 300x600
|
||||
};
|
||||
|
||||
// CPMStar state
|
||||
let cpmstarRewardedVideo = null;
|
||||
let cpmstarInitialized = false;
|
||||
|
||||
// Initialize CPMStar for video ads
|
||||
function initCpmstarVideo() {
|
||||
console.log("[cpmstar-ads.js] Initializing CPMStar video ads...");
|
||||
|
||||
(function (zonefile) {
|
||||
var y = "cpmstarx";
|
||||
var drutObj = window[y] = window[y] || {};
|
||||
function failCpmstarAPI() {
|
||||
var failFn = function (o) { o && typeof (o) === "object" && o.fail && o.fail(); };
|
||||
drutObj && Array.isArray(drutObj.cmd) && drutObj.cmd.forEach(failFn) && (drutObj.cmd.length = 0);
|
||||
window.cpmstarAPI = window["_" + zonefile] = failFn;
|
||||
}
|
||||
var rnd = Math.round(Math.random() * 999999);
|
||||
var s = document.createElement('script');
|
||||
s.type = 'text/javascript';
|
||||
s.async = true;
|
||||
s.onerror = failCpmstarAPI;
|
||||
s.onload = initCpmstarAPI;
|
||||
var proto = document.location.protocol;
|
||||
var host = (proto == "https:" || proto == "file:") ? "https://server" : "//cdn";
|
||||
if (window.location.hash == "#cpmstarDev") host = "//dev.server";
|
||||
if (window.location.hash == "#cpmstarStaging") host = "//staging.server";
|
||||
s.src = host + ".cpmstar.com/cached/zonefiles/" + zonefile + ".js?rnd=" + rnd;
|
||||
var s2 = document.getElementsByTagName('script')[0];
|
||||
s2.parentNode.insertBefore(s, s2);
|
||||
window.cpmstarAPI = function (o) { (drutObj.cmd = drutObj.cmd || []).push(o); }
|
||||
})(CPMSTAR_ZONE_FILE);
|
||||
}
|
||||
|
||||
function initCpmstarAPI() {
|
||||
console.log("[cpmstar-ads.js] CPMStar API callback");
|
||||
|
||||
if (typeof cpmstarAPI !== 'undefined') {
|
||||
cpmstarAPI(function(api) {
|
||||
console.log("[cpmstar-ads.js] Setting up CPMStar...");
|
||||
|
||||
// Set target for game ads
|
||||
api.game.setTarget(document.body);
|
||||
|
||||
// Initialize interstitial ad
|
||||
cpmstarAPI({
|
||||
kind: "game.createInterstitial",
|
||||
onAdOpened: function () {
|
||||
console.log("[cpmstar-ads.js] Interstitial opened");
|
||||
},
|
||||
onAdClosed: function () {
|
||||
console.log("[cpmstar-ads.js] Interstitial closed");
|
||||
},
|
||||
fail: function () {
|
||||
console.log("[cpmstar-ads.js] Interstitial failed");
|
||||
window.adblocked = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize rewarded video
|
||||
cpmstarRewardedVideo = new api.game.RewardedVideoView("rewardedvideo");
|
||||
|
||||
cpmstarRewardedVideo.addEventListener("ad_opened", function(e) {
|
||||
console.log("[cpmstar-ads.js] Rewarded video opened");
|
||||
});
|
||||
|
||||
cpmstarRewardedVideo.addEventListener("ad_closed", function(e) {
|
||||
console.log("[cpmstar-ads.js] Rewarded video closed");
|
||||
if (window._cpmstarTempSuccess) {
|
||||
window._cpmstarTempSuccess();
|
||||
delete window._cpmstarTempSuccess;
|
||||
delete window._cpmstarTempFailure;
|
||||
} else if (typeof unityInstance !== 'undefined') {
|
||||
unityInstance.SendMessage("SDKManager", "OnVideoAdEnded", "true");
|
||||
}
|
||||
// Preload another ad
|
||||
setTimeout(function() {
|
||||
cpmstarRewardedVideo.load();
|
||||
}, 700);
|
||||
});
|
||||
|
||||
cpmstarRewardedVideo.addEventListener("loaded", function(e) {
|
||||
console.log("[cpmstar-ads.js] Rewarded video loaded");
|
||||
});
|
||||
|
||||
cpmstarRewardedVideo.addEventListener("load_failed", function(e) {
|
||||
console.log("[cpmstar-ads.js] Rewarded video failed to load");
|
||||
});
|
||||
|
||||
// Preload first rewarded video
|
||||
cpmstarRewardedVideo.load();
|
||||
cpmstarInitialized = true;
|
||||
console.log("[cpmstar-ads.js] Initialization complete");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to trigger CPMStar banner
|
||||
function triggerCpmstarBanner(placementId, element) {
|
||||
console.log(`[cpmstar-ads.js] Triggering banner for placement ID: ${placementId}`);
|
||||
|
||||
if (typeof window.cpmstarx === 'undefined') {
|
||||
window.cpmstarx = {};
|
||||
}
|
||||
|
||||
if (!window.cpmstarx.libcmd) {
|
||||
window.cpmstarx.libcmd = [];
|
||||
}
|
||||
|
||||
// Find all elements with this class and get the last one
|
||||
const els = document.getElementsByClassName(`div-${placementId}`);
|
||||
const pindex = els.length - 1;
|
||||
const el = els[pindex];
|
||||
|
||||
console.log(`[cpmstar-ads.js] Elements found: ${els.length}, using index: ${pindex}`);
|
||||
|
||||
// Push the banner command
|
||||
window.cpmstarx.libcmd.push({
|
||||
kind: 'asynctagfetch',
|
||||
el: el,
|
||||
pid: placementId,
|
||||
pindex: pindex
|
||||
});
|
||||
|
||||
console.log(`[cpmstar-ads.js] Banner command queued`);
|
||||
}
|
||||
|
||||
// Video ad provider implementation
|
||||
window.videoAdProviders.cpmstar = {
|
||||
showMidroll: function(onSuccess, onFailure) {
|
||||
console.log(`[cpmstar-ads.js] showMidroll called`);
|
||||
|
||||
if (typeof cpmstarAPI !== 'undefined') {
|
||||
cpmstarAPI({
|
||||
kind: "game.displayInterstitial",
|
||||
onAdOpened: function () {
|
||||
console.log(`[cpmstar-ads.js] Midroll opened`);
|
||||
},
|
||||
onAdClosed: function () {
|
||||
console.log(`[cpmstar-ads.js] Midroll closed`);
|
||||
onSuccess();
|
||||
},
|
||||
fail: function () {
|
||||
console.log(`[cpmstar-ads.js] Midroll failed`);
|
||||
onFailure();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log(`[cpmstar-ads.js] API not available`);
|
||||
onFailure();
|
||||
}
|
||||
},
|
||||
showRewarded: function(onSuccess, onFailure) {
|
||||
console.log(`[cpmstar-ads.js] showRewarded called`);
|
||||
|
||||
if (cpmstarRewardedVideo && cpmstarRewardedVideo.isLoaded()) {
|
||||
window._cpmstarTempSuccess = onSuccess;
|
||||
window._cpmstarTempFailure = onFailure;
|
||||
cpmstarRewardedVideo.show();
|
||||
} else if (cpmstarRewardedVideo) {
|
||||
console.log(`[cpmstar-ads.js] Rewarded video not loaded`);
|
||||
cpmstarRewardedVideo.load();
|
||||
onFailure();
|
||||
} else {
|
||||
console.log(`[cpmstar-ads.js] Rewarded video not initialized`);
|
||||
onFailure();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Banner ad provider implementation
|
||||
window.bannerAdProviders.cpmstar = {
|
||||
displayBanner: async function(bannerType, container) {
|
||||
const placementId = window.cpmstarBannerMapping[bannerType];
|
||||
console.log(`[cpmstar-ads.js] displayBanner for type: ${bannerType}, placement ID: ${placementId}`);
|
||||
|
||||
if (!placementId) {
|
||||
console.log(`[cpmstar-ads.js] No placement ID for banner type ${bannerType}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get dimensions from global bannerDimensions
|
||||
const dims = window.bannerDimensions[bannerType];
|
||||
if (!dims) {
|
||||
console.log(`[cpmstar-ads.js] No dimensions for banner type ${bannerType}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create CPMStar banner container
|
||||
const cpmstarDiv = document.createElement('div');
|
||||
cpmstarDiv.className = `div-${placementId}`;
|
||||
cpmstarDiv.style.width = dims.width;
|
||||
cpmstarDiv.style.height = dims.height;
|
||||
cpmstarDiv.style.position = 'relative';
|
||||
cpmstarDiv.style.display = 'block';
|
||||
|
||||
// Clear existing content and add CPMStar div
|
||||
container.innerHTML = '';
|
||||
container.appendChild(cpmstarDiv);
|
||||
|
||||
// Observe for creative injection
|
||||
const success = await new Promise((resolve) => {
|
||||
let settled = false;
|
||||
const settle = (ok) => { if (!settled) { settled = true; resolve(ok); } };
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
const hasCreative = cpmstarDiv.querySelector('iframe, img, ins, div');
|
||||
if (hasCreative && cpmstarDiv.children.length > 0) {
|
||||
observer.disconnect();
|
||||
settle(true);
|
||||
}
|
||||
});
|
||||
try {
|
||||
observer.observe(cpmstarDiv, { childList: true, subtree: true });
|
||||
} catch {}
|
||||
|
||||
const timeoutMs = 3000;
|
||||
const timeoutId = setTimeout(() => {
|
||||
observer.disconnect();
|
||||
const ok = cpmstarDiv.children.length > 0;
|
||||
settle(ok);
|
||||
}, timeoutMs);
|
||||
|
||||
// Load CPMStar banner script if not already loaded
|
||||
if (!window.cpmstarBannerScriptLoaded) {
|
||||
console.log(`[cpmstar-ads.js] Loading banner script`);
|
||||
const script = document.createElement('script');
|
||||
script.async = true;
|
||||
script.src = 'https://ssl.cdne.cpmstar.com/cached/js/lib.js';
|
||||
script.onload = function() {
|
||||
console.log(`[cpmstar-ads.js] Banner script loaded`);
|
||||
window.cpmstarBannerScriptLoaded = true;
|
||||
try {
|
||||
triggerCpmstarBanner(placementId, cpmstarDiv);
|
||||
} catch (e) {
|
||||
clearTimeout(timeoutId);
|
||||
observer.disconnect();
|
||||
settle(false);
|
||||
}
|
||||
};
|
||||
script.onerror = function() {
|
||||
console.log(`[cpmstar-ads.js] Failed to load banner script`);
|
||||
clearTimeout(timeoutId);
|
||||
observer.disconnect();
|
||||
settle(false);
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
} else {
|
||||
try {
|
||||
triggerCpmstarBanner(placementId, cpmstarDiv);
|
||||
} catch (e) {
|
||||
clearTimeout(timeoutId);
|
||||
observer.disconnect();
|
||||
settle(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return success;
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize CPMStar video ads
|
||||
initCpmstarVideo();
|
||||
|
||||
// Ensure CPMStar API is initialized when available
|
||||
if (typeof cpmstarAPI !== 'undefined') {
|
||||
initCpmstarAPI();
|
||||
} else {
|
||||
var checkInterval = setInterval(function () {
|
||||
if (typeof cpmstarAPI !== 'undefined') {
|
||||
clearInterval(checkInterval);
|
||||
initCpmstarAPI();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
console.log("[cpmstar-ads.js] Module loaded successfully");
|
||||
})();
|
||||
@@ -0,0 +1,100 @@
|
||||
// Local Ads Fallback Provider Module
|
||||
// This module provides local image fallbacks for ads
|
||||
//
|
||||
// To enable clickable banners, set URLs in LOCAL_BANNER_LINKS:
|
||||
// - Set to a URL string to make the banner clickable
|
||||
// - Set to null to disable click functionality
|
||||
// - Example: 0: 'https://example.com', 1: null, 2: 'https://another-site.com'
|
||||
|
||||
(function() {
|
||||
console.log("[local-ads.js] Module loading...");
|
||||
|
||||
// Ensure global providers exist
|
||||
window.videoAdProviders = window.videoAdProviders || {};
|
||||
window.bannerAdProviders = window.bannerAdProviders || {};
|
||||
|
||||
// Local banner image paths (adblock-safe names)
|
||||
const LOCAL_BANNER_IMAGES = {
|
||||
0: 'ads/local-ads-assets/a.png', // 300x250
|
||||
1: 'ads/local-ads-assets/b.png', // 728x90
|
||||
2: 'ads/local-ads-assets/c.png' // 300x600
|
||||
};
|
||||
|
||||
// Optional banner links (set to null to disable click functionality)
|
||||
const LOCAL_BANNER_LINKS = {
|
||||
0: 'https://kour.io/?utm_source=2v2&utm_medium=banner&utm_campaign=crosspromo', // 300x250
|
||||
1: 'https://veck.io/?utm_source=2v2&utm_medium=banner&utm_campaign=crosspromo', // 728x90
|
||||
2: 'https://growden.io/?utm_source=2v2&utm_medium=banner&utm_campaign=crosspromo' // 300x600
|
||||
};
|
||||
|
||||
// Video ad provider implementation (simulated)
|
||||
window.videoAdProviders.local = {
|
||||
showMidroll: function(onSuccess, onFailure) {
|
||||
console.log(`[local-ads.js] showMidroll called - failing immediately`);
|
||||
onFailure();
|
||||
},
|
||||
|
||||
showRewarded: function(onSuccess, onFailure) {
|
||||
console.log(`[local-ads.js] showRewarded called - failing immediately`);
|
||||
onFailure();
|
||||
}
|
||||
};
|
||||
|
||||
// Banner ad provider implementation
|
||||
window.bannerAdProviders.local = {
|
||||
displayBanner: async function(bannerType, container) {
|
||||
console.log(`[local-ads.js] displayBanner for type: ${bannerType}`);
|
||||
|
||||
const imagePath = LOCAL_BANNER_IMAGES[bannerType];
|
||||
if (!imagePath) {
|
||||
console.log(`[local-ads.js] No local image for banner type ${bannerType}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get dimensions from global bannerDimensions
|
||||
const dims = window.bannerDimensions[bannerType];
|
||||
if (!dims) {
|
||||
console.log(`[local-ads.js] No dimensions for banner type ${bannerType}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Preload image and resolve true on success, false on failure
|
||||
return await new Promise((resolve) => {
|
||||
const testImg = new Image();
|
||||
testImg.onload = function() {
|
||||
const img = document.createElement('img');
|
||||
img.src = imagePath;
|
||||
img.style.width = dims.width;
|
||||
img.style.height = dims.height;
|
||||
img.style.display = 'block';
|
||||
img.style.cursor = 'pointer';
|
||||
img.alt = `Local Banner ${dims.width}x${dims.height}`;
|
||||
|
||||
// Add click handler if link is configured
|
||||
const bannerLink = LOCAL_BANNER_LINKS[bannerType];
|
||||
if (bannerLink) {
|
||||
img.addEventListener('click', function() {
|
||||
console.log(`[local-ads.js] Banner clicked, opening: ${bannerLink}`);
|
||||
window.open(bannerLink, '_blank', 'noopener,noreferrer');
|
||||
});
|
||||
} else {
|
||||
// Still show pointer cursor but no click action
|
||||
img.style.cursor = 'default';
|
||||
}
|
||||
|
||||
container.innerHTML = '';
|
||||
container.appendChild(img);
|
||||
console.log(`[local-ads.js] Local banner displayed: ${imagePath}${bannerLink ? ` (clickable: ${bannerLink})` : ' (no link)'}`);
|
||||
resolve(true);
|
||||
};
|
||||
testImg.onerror = function() {
|
||||
console.log('[local-ads.js] Local image blocked/missing');
|
||||
resolve(false);
|
||||
};
|
||||
testImg.src = imagePath;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
console.log("[local-ads.js] Module loaded successfully");
|
||||
})();
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 113 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 156 KiB |
Reference in New Issue
Block a user