Skip to content

Commit a7b3c27

Browse files
committed
Fix AdSense availableWidth=0: full-width slots and deferred init
1 parent f3a77e5 commit a7b3c27

2 files changed

Lines changed: 46 additions & 18 deletions

File tree

play.html

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
.demo-badge { display: inline-block; margin-top: 6px; font-size: 0.78em; color: #a0c8a8; letter-spacing: 1px; }
4444
.demo-badge a { color: #94c3e8; }
4545
.daily-badge { display: inline-block; margin-left: 8px; font-size: 0.65em; color: #a0d0a8; letter-spacing: 2px; vertical-align: middle; font-weight: normal; }
46-
.ad-slot { position: relative; margin: 24px 0; min-height: 90px; display: flex; align-items: center; justify-content: center; background: #11161e; border: 1px dashed #2a3540; border-radius: 4px; padding: 6px; }
46+
.ad-slot { position: relative; width: 100%; margin: 24px 0; min-height: 90px; display: block; background: #11161e; border: 1px dashed #2a3540; border-radius: 4px; padding: 6px; overflow: hidden; }
4747
.ad-slot::before { content: 'Advertisement'; position: absolute; top: -18px; left: 50%; transform: translateX(-50%); color: #5a6874; font-size: 0.65em; letter-spacing: 3px; pointer-events: none; }
48-
.ad-slot ins { display: block !important; }
48+
.ad-slot ins.adsbygoogle { display: block !important; width: 100% !important; min-height: 90px; }
4949
footer { margin-top: 60px; text-align: center; color: #5a6874; font-size: 0.78em; letter-spacing: 2px; line-height: 1.8; }
5050
footer a { color: #8098a8; text-decoration: none; }
5151
footer a:hover { color: #d8d0c0; }
@@ -72,10 +72,9 @@ <h1>BOARD GAMING</h1>
7272
style="display:block"
7373
data-ad-client="ca-pub-2835365593874464"
7474
data-ad-slot="0000000000"
75-
data-ad-format="horizontal"
75+
data-ad-format="auto"
7676
data-full-width-responsive="true"></ins>
7777
</div>
78-
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
7978

8079
<div class="daily-strip">
8180
<b>TODAY'S DAILY PUZZLES</b>
@@ -127,13 +126,12 @@ <h2>Classic Puzzles</h2>
127126
</section>
128127
<div class="ad-slot" style="margin:32px 0">
129128
<ins class="adsbygoogle"
130-
style="display:block;text-align:center"
129+
style="display:block"
131130
data-ad-client="ca-pub-2835365593874464"
132131
data-ad-slot="0000000000"
133132
data-ad-format="auto"
134133
data-full-width-responsive="true"></ins>
135134
</div>
136-
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
137135

138136
<section>
139137
<h2>Board Games</h2>
@@ -239,13 +237,12 @@ <h2>Simulations</h2>
239237

240238
<div class="ad-slot" style="margin:32px 0">
241239
<ins class="adsbygoogle"
242-
style="display:block;text-align:center"
240+
style="display:block"
243241
data-ad-client="ca-pub-2835365593874464"
244242
data-ad-slot="0000000000"
245243
data-ad-format="auto"
246244
data-full-width-responsive="true"></ins>
247245
</div>
248-
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
249246

250247
<p class="disclosure">
251248
This page is supported by Google AdSense advertisements. Ads help keep the games free.
@@ -263,6 +260,21 @@ <h2>Simulations</h2>
263260
<a href="https://github.com/mf4633/board-gaming">github.com/mf4633/board-gaming</a>
264261
</footer>
265262
</div>
263+
<script>
264+
(function () {
265+
function fillAds() {
266+
var slots = document.querySelectorAll('ins.adsbygoogle');
267+
for (var i = 0; i < slots.length; i++) {
268+
(adsbygoogle = window.adsbygoogle || []).push({});
269+
}
270+
}
271+
if (document.readyState === 'loading') {
272+
document.addEventListener('DOMContentLoaded', function () { requestAnimationFrame(fillAds); });
273+
} else {
274+
requestAnimationFrame(fillAds);
275+
}
276+
})();
277+
</script>
266278
<script src="/analytics.js"></script>
267279
<script src="/nav.js" defer></script>
268280
</body>

scripts/generate-catalog.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,41 @@ const sharedCss = ` * { box-sizing: border-box; }
7474
.demo-badge { display: inline-block; margin-top: 6px; font-size: 0.78em; color: #a0c8a8; letter-spacing: 1px; }
7575
.demo-badge a { color: #94c3e8; }
7676
.daily-badge { display: inline-block; margin-left: 8px; font-size: 0.65em; color: #a0d0a8; letter-spacing: 2px; vertical-align: middle; font-weight: normal; }
77-
.ad-slot { position: relative; margin: 24px 0; min-height: 90px; display: flex; align-items: center; justify-content: center; background: #11161e; border: 1px dashed #2a3540; border-radius: 4px; padding: 6px; }
77+
.ad-slot { position: relative; width: 100%; margin: 24px 0; min-height: 90px; display: block; background: #11161e; border: 1px dashed #2a3540; border-radius: 4px; padding: 6px; overflow: hidden; }
7878
.ad-slot::before { content: 'Advertisement'; position: absolute; top: -18px; left: 50%; transform: translateX(-50%); color: #5a6874; font-size: 0.65em; letter-spacing: 3px; pointer-events: none; }
79-
.ad-slot ins { display: block !important; }
79+
.ad-slot ins.adsbygoogle { display: block !important; width: 100% !important; min-height: 90px; }
8080
footer { margin-top: 60px; text-align: center; color: #5a6874; font-size: 0.78em; letter-spacing: 2px; line-height: 1.8; }
8181
footer a { color: #8098a8; text-decoration: none; }
8282
footer a:hover { color: #d8d0c0; }
8383
.disclosure { color: #5a6874; font-size: 0.72em; max-width: 700px; margin: 30px auto 0; line-height: 1.6; letter-spacing: 0.5px; font-style: italic; }`;
8484

85-
function adUnit(slot, format, style) {
85+
function adUnit(slot, style) {
8686
return ` <div class="ad-slot"${style ? ` style="${style}"` : ''}>
8787
<ins class="adsbygoogle"
88-
style="display:block${format === 'horizontal' ? '' : ';text-align:center'}"
88+
style="display:block"
8989
data-ad-client="${PUB}"
9090
data-ad-slot="${slot}"
91-
data-ad-format="${format}"
91+
data-ad-format="auto"
9292
data-full-width-responsive="true"></ins>
93-
</div>
94-
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>`;
93+
</div>`;
9594
}
9695

96+
const adInitScript = `<script>
97+
(function () {
98+
function fillAds() {
99+
var slots = document.querySelectorAll('ins.adsbygoogle');
100+
for (var i = 0; i < slots.length; i++) {
101+
(adsbygoogle = window.adsbygoogle || []).push({});
102+
}
103+
}
104+
if (document.readyState === 'loading') {
105+
document.addEventListener('DOMContentLoaded', function () { requestAnimationFrame(fillAds); });
106+
} else {
107+
requestAnimationFrame(fillAds);
108+
}
109+
})();
110+
</script>`;
111+
97112
const dailyGames = games.filter(g => g.daily);
98113
const dailyStrip = dailyGames.length
99114
? ` <div class="daily-strip">
@@ -139,15 +154,15 @@ ${sharedCss}
139154
<a href="privacy.html">Privacy</a>
140155
</nav>
141156
142-
${adUnit('0000000000', 'horizontal')}
157+
${adUnit('0000000000')}
143158
144159
${dailyStrip}
145160
${section('puzzles', { highlightPuzzles: true })}
146-
${adUnit('0000000000', 'auto', 'margin:32px 0')}
161+
${adUnit('0000000000', 'margin:32px 0')}
147162
${section('board')}
148163
${section('sims')}
149164
150-
${adUnit('0000000000', 'auto', 'margin:32px 0')}
165+
${adUnit('0000000000', 'margin:32px 0')}
151166
152167
<p class="disclosure">
153168
This page is supported by Google AdSense advertisements. Ads help keep the games free.
@@ -165,6 +180,7 @@ ${adUnit('0000000000', 'auto', 'margin:32px 0')}
165180
<a href="https://github.com/mf4633/board-gaming">github.com/mf4633/board-gaming</a>
166181
</footer>
167182
</div>
183+
${adInitScript}
168184
<script src="/analytics.js"></script>
169185
<script src="/nav.js" defer></script>
170186
</body>

0 commit comments

Comments
 (0)