Skip to content

Commit a98f88a

Browse files
committed
hopefully added some more ads but well see if it worked ig prod testing goated fr fr no cap
1 parent 091d440 commit a98f88a

3 files changed

Lines changed: 101 additions & 53 deletions

File tree

src/lib/adSlotConfig.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { browser } from "$app/environment";
2+
import { detectAdBlockEnabled } from "./helpers.js";
3+
import { SessionState } from "./state.js";
4+
import { findAHosts } from "./types/servers.js";
5+
6+
export const adSlotConfig = {
7+
"ccported.github.io": {
8+
sidebar: "69fd2258-841e-496e-b471-7fee303347da",
9+
grid: "1327f13c-fb3f-45df-9616-2c76dacf8707",
10+
footer: "c2522ff2-7549-433b-a689-0cd63517722c",
11+
},
12+
"ccported.click": {
13+
sidebar: "52cde221-3941-473c-afbc-5376c9ae5f76",
14+
grid: "29d0156c-2d0c-4d77-b80c-6a3c21b13dd2",
15+
footer: "b203fc61-1cc6-4a48-a13a-be6dbe61f3f0"
16+
},
17+
};
18+
19+
export async function initializeAds(adSlots: {
20+
sidebar?: string;
21+
grid?: string;
22+
footer?: string;
23+
} | null) {
24+
let adBlock = false;
25+
let adsEnabled = true;
26+
await detectAdBlockEnabled();
27+
console.log(
28+
"[R][CardGrid][Mount] AdBlock Enabled:",
29+
SessionState.adBlockEnabled,
30+
);
31+
adBlock = SessionState.adBlockEnabled;
32+
adsEnabled = SessionState.adsEnabled;
33+
if (adsEnabled) {
34+
const host = browser ? window.location.hostname : "<SSR_HOST>";
35+
if (host in adSlotConfig) {
36+
adSlots = adSlotConfig[host as keyof typeof adSlotConfig];
37+
}
38+
(async () => {
39+
const aHosts = await findAHosts();
40+
if (!aHosts) {
41+
adsEnabled = false;
42+
SessionState.adsEnabled = false;
43+
return;
44+
}
45+
46+
const aHostData = aHosts.find((h) => h.hostname === host);
47+
if (aHostData && aHostData.acode) {
48+
const scriptId = `ad-script-${aHostData.acode}`;
49+
if (document.getElementById(scriptId)) return;
50+
51+
const script = document.createElement("script");
52+
script.id = scriptId;
53+
script.src = `//monu.delivery/site/${aHostData.acode}`;
54+
script.setAttribute("data-cfasync", "false");
55+
script.defer = true;
56+
document.head.appendChild(script);
57+
} else {
58+
console.log(
59+
"[R][CardGrid][Mount] No valid AHost for this domain:",
60+
host,
61+
);
62+
adsEnabled = false;
63+
SessionState.adsEnabled = false;
64+
}
65+
})();
66+
}
67+
68+
return { adBlock, adsEnabled };
69+
}

src/lib/components/CardGrid.svelte

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,12 @@
1919
import { browser } from "$app/environment";
2020
import { loadGames } from "$lib/loadCards.js";
2121
import { goto } from "$app/navigation";
22+
import { adSlotConfig, initializeAds } from "$lib/adSlotConfig.js";
2223
2324
let searchIsOpen = $state(false);
2425
let games = $state<Game[]>([]);
2526
let adsEnabled = $state(false);
26-
let adSlots = $state<{ sidebar: string; grid: string } | null>(null);
27-
28-
const adSlotConfig = {
29-
"ccported.github.io": {
30-
sidebar: "69fd2258-841e-496e-b471-7fee303347da",
31-
grid: "1327f13c-fb3f-45df-9616-2c76dacf8707",
32-
},
33-
"ccported.click": {
34-
sidebar: "52cde221-3941-473c-afbc-5376c9ae5f76",
35-
grid: "29d0156c-2d0c-4d77-b80c-6a3c21b13dd2",
36-
},
37-
};
27+
let adSlots = $state<{ sidebar: string; grid: string; footer: string } | null>(null);
3828
3929
// Sort options
4030
type SortType = "default" | "az" | "za" | "clicksAsc" | "clicksDesc" | "new" | "old";
@@ -254,47 +244,7 @@
254244
255245
if (SessionState.ssr) return;
256246
257-
await detectAdBlockEnabled();
258-
console.log(
259-
"[R][CardGrid][Mount] AdBlock Enabled:",
260-
SessionState.adBlockEnabled,
261-
);
262-
adBlock = SessionState.adBlockEnabled;
263-
adsEnabled = SessionState.adsEnabled;
264-
if (adsEnabled) {
265-
const host = browser ? window.location.hostname : "<SSR_HOST>";
266-
if (host in adSlotConfig) {
267-
adSlots = adSlotConfig[host as keyof typeof adSlotConfig];
268-
}
269-
(async () => {
270-
const aHosts = await findAHosts();
271-
if (!aHosts) {
272-
adsEnabled = false;
273-
SessionState.adsEnabled = false;
274-
return;
275-
}
276-
277-
const aHostData = aHosts.find((h) => h.hostname === host);
278-
if (aHostData && aHostData.acode) {
279-
const scriptId = `ad-script-${aHostData.acode}`;
280-
if (document.getElementById(scriptId)) return;
281-
282-
const script = document.createElement("script");
283-
script.id = scriptId;
284-
script.src = `//monu.delivery/site/${aHostData.acode}`;
285-
script.setAttribute("data-cfasync", "false");
286-
script.defer = true;
287-
document.head.appendChild(script);
288-
} else {
289-
console.log(
290-
"[R][CardGrid][Mount] No valid AHost for this domain:",
291-
host,
292-
);
293-
adsEnabled = false;
294-
SessionState.adsEnabled = false;
295-
}
296-
})();
297-
}
247+
({ adBlock, adsEnabled } = await initializeAds(adSlots));
298248
});
299249
300250
$effect(() => {
@@ -496,6 +446,10 @@
496446
<Ad slotId={adSlots.sidebar} />
497447
</div>
498448
</div>
449+
450+
<div class = "footer-ad">
451+
<Ad slotId={adSlots.footer} />
452+
</div>
499453
{/if}
500454
</div>
501455

src/routes/play/+page.svelte

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
} from "$lib/helpers.js";
1818
import { browser } from "$app/environment";
1919
import { ReplicaModificationsStatus } from "@aws-sdk/client-s3";
20+
import { adSlotConfig, initializeAds } from "$lib/adSlotConfig.js";
21+
import Ad from "$lib/components/Ad.svelte";
2022
2123
let game: Game | null = $state(null);
2224
let adblock = $state(false);
@@ -70,6 +72,13 @@
7072
let application: any = null;
7173
let adContinued = $state(false);
7274
let commitHash = $state("");
75+
76+
let adsEnabled = $state(false);
77+
let adSlots = $state<{
78+
sidebar: string;
79+
grid: string;
80+
footer: string;
81+
} | null>(null);
7382
onMount(async () => {
7483
await initializeTooling();
7584
await fetchGameData();
@@ -97,6 +106,18 @@
97106
clearInterval(interval);
98107
}
99108
}, 1000);
109+
} else {
110+
(async () => {
111+
if (!browser) return;
112+
113+
const hostname = window.location.hostname;
114+
const { adBlock, adsEnabled: adsOn } =
115+
await initializeAds(
116+
adSlots
117+
);
118+
adblock = adBlock;
119+
adsEnabled = adsOn;
120+
})();
100121
}
101122
});
102123
@@ -436,6 +457,10 @@
436457
</div>
437458
{/if}
438459

460+
{#if adsEnabled && adSlots}
461+
<Ad slotId={adSlots.footer} />
462+
{/if}
463+
439464
<style>
440465
.play {
441466
display: flex;

0 commit comments

Comments
 (0)