-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathads.js
More file actions
64 lines (56 loc) · 2.12 KB
/
ads.js
File metadata and controls
64 lines (56 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* QuickTools Ad Integration
*
* Ad zones are HIDDEN by default (no ugly "Ad Space" placeholders).
* When AdSense is enabled and fills an ad, the zone becomes visible.
*
* HOW TO USE:
* 1. Get approved by Google AdSense
* 2. Replace slot IDs below with your actual ad unit slot IDs
* 3. Set ADSENSE_ENABLED to true
* 4. Redeploy. Ads will replace all placeholder zones automatically.
*/
const ADSENSE_ENABLED = false; // ← Set to true after AdSense approval
const YOUR_PUB_ID = 'ca-pub-2658921743607446';
const SLOT_LEADERBOARD = '1234567890';
const SLOT_RECTANGLE = '0987654321';
const SLOT_BOTTOM = '1122334455';
(function() {
// Always hide placeholder text inside ad zones
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.ad-zone').forEach(zone => {
zone.textContent = '';
});
});
if (!ADSENSE_ENABLED) return;
// Inject AdSense script
const script = document.createElement('script');
script.async = true;
script.src = `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${YOUR_PUB_ID}`;
script.crossOrigin = 'anonymous';
document.head.appendChild(script);
// Wait for DOM, then replace placeholder zones
document.addEventListener('DOMContentLoaded', function() {
const zones = document.querySelectorAll('.ad-zone');
zones.forEach((zone, index) => {
const isTop = zone.classList.contains('ad-zone-top');
const isBottom = zone.classList.contains('ad-zone-bottom');
const slot = isTop ? SLOT_LEADERBOARD : isBottom ? SLOT_BOTTOM : SLOT_RECTANGLE;
const format = (isTop || isBottom) ? 'horizontal' : 'rectangle';
zone.innerHTML = `
<ins class="adsbygoogle"
style="display:block"
data-ad-client="${YOUR_PUB_ID}"
data-ad-slot="${slot}"
data-ad-format="${format}"
data-full-width-responsive="true"></ins>
`;
zone.classList.add('ad-active');
zone.style.background = 'none';
zone.style.border = 'none';
try {
(window.adsbygoogle = window.adsbygoogle || []).push({});
} catch(e) {}
});
});
})();