Skip to content

Commit 8222fd5

Browse files
committed
Skip AdSense requests until real adSlot is set in games.json
1 parent a7b3c27 commit 8222fd5

3 files changed

Lines changed: 24 additions & 49 deletions

File tree

games.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"site": {
33
"baseUrl": "https://boardgaminghub.com",
4-
"publisherId": "ca-pub-2835365593874464"
4+
"publisherId": "ca-pub-2835365593874464",
5+
"adSlot": ""
56
},
67
"categories": [
78
{ "id": "puzzles", "label": "Classic Puzzles", "blurb": "The most-played puzzle games on the web — free, no signup, mobile-friendly." },

play.html

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<meta property="og:title" content="Play 31 free in-browser puzzle &amp; strategy games">
1515
<meta property="og:description" content="Solitaire, Sudoku, Mahjong, Wordform, 2048, Chess, Go, plus original designs and physics sims. Free, ad-supported, no signup.">
1616
<meta name="twitter:card" content="summary">
17-
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2835365593874464" crossorigin="anonymous"></script>
17+
1818
<style>
1919
* { box-sizing: border-box; }
2020
html, body { margin: 0; padding: 0; background: #0c1016; color: #d8d0c0; font-family: Georgia, "Times New Roman", serif; }
@@ -67,14 +67,7 @@ <h1>BOARD GAMING</h1>
6767
<a href="privacy.html">Privacy</a>
6868
</nav>
6969

70-
<div class="ad-slot">
71-
<ins class="adsbygoogle"
72-
style="display:block"
73-
data-ad-client="ca-pub-2835365593874464"
74-
data-ad-slot="0000000000"
75-
data-ad-format="auto"
76-
data-full-width-responsive="true"></ins>
77-
</div>
70+
<div class="ad-slot ad-slot--pending" aria-hidden="true"></div>
7871

7972
<div class="daily-strip">
8073
<b>TODAY'S DAILY PUZZLES</b>
@@ -124,14 +117,7 @@ <h2>Classic Puzzles</h2>
124117
</a>
125118
</div>
126119
</section>
127-
<div class="ad-slot" style="margin:32px 0">
128-
<ins class="adsbygoogle"
129-
style="display:block"
130-
data-ad-client="ca-pub-2835365593874464"
131-
data-ad-slot="0000000000"
132-
data-ad-format="auto"
133-
data-full-width-responsive="true"></ins>
134-
</div>
120+
<div class="ad-slot ad-slot--pending" style="margin:32px 0" aria-hidden="true"></div>
135121

136122
<section>
137123
<h2>Board Games</h2>
@@ -235,14 +221,7 @@ <h2>Simulations</h2>
235221
</div>
236222
</section>
237223

238-
<div class="ad-slot" style="margin:32px 0">
239-
<ins class="adsbygoogle"
240-
style="display:block"
241-
data-ad-client="ca-pub-2835365593874464"
242-
data-ad-slot="0000000000"
243-
data-ad-format="auto"
244-
data-full-width-responsive="true"></ins>
245-
</div>
224+
<div class="ad-slot ad-slot--pending" style="margin:32px 0" aria-hidden="true"></div>
246225

247226
<p class="disclosure">
248227
This page is supported by Google AdSense advertisements. Ads help keep the games free.
@@ -260,21 +239,7 @@ <h2>Simulations</h2>
260239
<a href="https://github.com/mf4633/board-gaming">github.com/mf4633/board-gaming</a>
261240
</footer>
262241
</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>
242+
278243
<script src="/analytics.js"></script>
279244
<script src="/nav.js" defer></script>
280245
</body>

scripts/generate-catalog.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const data = JSON.parse(fs.readFileSync(path.join(ROOT, 'games.json'), 'utf8'));
1111
const { site, categories, games } = data;
1212
const BASE = site.baseUrl.replace(/\/$/, '');
1313
const PUB = site.publisherId;
14+
const AD_SLOT = String(site.adSlot || '').trim();
15+
const ADS_ENABLED = /^\d{10}$/.test(AD_SLOT) && AD_SLOT !== '0000000000';
1416
const count = games.length;
1517

1618
function esc(s) {
@@ -82,18 +84,25 @@ const sharedCss = ` * { box-sizing: border-box; }
8284
footer a:hover { color: #d8d0c0; }
8385
.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; }`;
8486

85-
function adUnit(slot, style) {
87+
function adUnit(style) {
88+
if (!ADS_ENABLED) {
89+
return ` <div class="ad-slot ad-slot--pending"${style ? ` style="${style}"` : ''} aria-hidden="true"></div>`;
90+
}
8691
return ` <div class="ad-slot"${style ? ` style="${style}"` : ''}>
8792
<ins class="adsbygoogle"
8893
style="display:block"
8994
data-ad-client="${PUB}"
90-
data-ad-slot="${slot}"
95+
data-ad-slot="${AD_SLOT}"
9196
data-ad-format="auto"
9297
data-full-width-responsive="true"></ins>
9398
</div>`;
9499
}
95100

96-
const adInitScript = `<script>
101+
const adsenseHeadScript = ADS_ENABLED
102+
? `<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${PUB}" crossorigin="anonymous"></script>`
103+
: '';
104+
105+
const adInitScript = ADS_ENABLED ? `<script>
97106
(function () {
98107
function fillAds() {
99108
var slots = document.querySelectorAll('ins.adsbygoogle');
@@ -107,7 +116,7 @@ const adInitScript = `<script>
107116
requestAnimationFrame(fillAds);
108117
}
109118
})();
110-
</script>`;
119+
</script>` : '';
111120

112121
const dailyGames = games.filter(g => g.daily);
113122
const dailyStrip = dailyGames.length
@@ -134,7 +143,7 @@ const playHtml = `<!DOCTYPE html>
134143
<meta property="og:title" content="Play ${count} free in-browser puzzle &amp; strategy games">
135144
<meta property="og:description" content="Solitaire, Sudoku, Mahjong, Wordform, 2048, Chess, Go, plus original designs and physics sims. Free, ad-supported, no signup.">
136145
<meta name="twitter:card" content="summary">
137-
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${PUB}" crossorigin="anonymous"></script>
146+
${adsenseHeadScript}
138147
<style>
139148
${sharedCss}
140149
</style>
@@ -154,15 +163,15 @@ ${sharedCss}
154163
<a href="privacy.html">Privacy</a>
155164
</nav>
156165
157-
${adUnit('0000000000')}
166+
${adUnit()}
158167
159168
${dailyStrip}
160169
${section('puzzles', { highlightPuzzles: true })}
161-
${adUnit('0000000000', 'margin:32px 0')}
170+
${adUnit('margin:32px 0')}
162171
${section('board')}
163172
${section('sims')}
164173
165-
${adUnit('0000000000', 'margin:32px 0')}
174+
${adUnit('margin:32px 0')}
166175
167176
<p class="disclosure">
168177
This page is supported by Google AdSense advertisements. Ads help keep the games free.

0 commit comments

Comments
 (0)