Skip to content

Commit 40b9837

Browse files
committed
removed script loading if ads not enabled... cause why make things slow huh?
1 parent 84e39b7 commit 40b9837

3 files changed

Lines changed: 51 additions & 45 deletions

File tree

components/chead.html

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,4 @@
1414
referrerpolicy="no-referrer"
1515
/>
1616
<title>{{title}}</title>
17-
<script src="/assets/scripts/navigation.js"></script>
18-
19-
{% if (ads == "true") %}
20-
<script>
21-
window.adsEnabled = true;
22-
</script>
23-
{% else %}
24-
<script>
25-
window.adsEnabled = false;
26-
</script>
27-
{% endif %}
17+
<script src="/assets/scripts/navigation.js"></script>

static/assets/scripts/home.js

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -110,30 +110,34 @@ try {
110110
}
111111
return { games }
112112
}
113-
async function adsEnabled() {
113+
async function adBlockEnabled() {
114114
let adBlockEnabled = false
115115
const googleAdUrl = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'
116116
try {
117117
await fetch(new Request(googleAdUrl)).catch(_ => adBlockEnabled = true)
118118
} catch (e) {
119-
adBlockEnabled = true
120-
} finally {
121-
if (!window.ccPorted.aHosts) {
122-
const res = await fetch("/ahosts.txt");
123-
const text = await res.text();
124-
const hosts = text.split('\n');
125-
window.ccPorted.aHosts = hosts.map(h => h.trim());
126-
if (window.ccPorted.aHosts.includes(window.location.hostname)) {
127-
return !adBlockEnabled;
128-
} else {
129-
return false;
130-
}
119+
adBlockEnabled = true;
120+
}
121+
return adBlockEnabled;
122+
}
123+
async function adsEnabled() {
124+
let adBlockEnabled = false
125+
adBlockEnabled = (typeof window.ccPorted.adBlockEnabled !== "undefined") ? window.ccPorted.adBlockEnabled : await adBlockEnabled();
126+
if (!window.ccPorted.aHosts) {
127+
const res = await fetch("/ahosts.txt");
128+
const text = await res.text();
129+
const hosts = text.split('\n');
130+
window.ccPorted.aHosts = hosts.map(h => h.trim());
131+
if (window.ccPorted.aHosts.includes(window.location.hostname)) {
132+
return !adBlockEnabled;
131133
} else {
132-
if (window.ccPorted.aHosts.includes(window.location.hostname)) {
133-
return !adBlockEnabled;
134-
} else {
135-
return false;
136-
}
134+
return false;
135+
}
136+
} else {
137+
if (window.ccPorted.aHosts.includes(window.location.hostname)) {
138+
return !adBlockEnabled;
139+
} else {
140+
return false;
137141
}
138142
}
139143
}
@@ -282,7 +286,17 @@ try {
282286
await checkForSwitchToAHost();
283287
window.ccPorted = window.ccPorted || {};
284288
window.ccPorted.cardsRendered = false;
289+
window.ccPorted.adBlockEnabled = await adBlockEnabled();
285290
window.ccPorted.adsEnabled = await adsEnabled();
291+
292+
if (window.ccPorted.adsEnabled && window.innerWidth > 800) {
293+
// add margin for the ads
294+
document.querySelector(".cards").style.marginRight = "300px";
295+
document.querySelector(".search").style.marginRight = "300px";
296+
}
297+
if (!window.ccPorted.adsEnabled) {
298+
hideAds();
299+
}
286300
showKofiDonationModal();
287301
// createNotif({
288302
// cta: {
@@ -292,14 +306,6 @@ try {
292306
// message: "Get your own custom CCPorted link!",
293307
// autoClose: 7
294308
// })
295-
if (window.ccPorted.adsEnabled && window.innerWidth > 800) {
296-
// add margin for the ads
297-
document.querySelector(".cards").style.marginRight = "300px";
298-
document.querySelector(".search").style.marginRight = "300px";
299-
}
300-
if (!window.ccPorted.adsEnabled) {
301-
hideAds();
302-
}
303309
const [chosenServer, index, path] = await testOpenServers();
304310
window.ccPorted.gameServer = {};
305311
window.ccPorted.gameServer.server = chosenServer.trim();
@@ -354,6 +360,17 @@ try {
354360
}
355361
log("Home page loaded");
356362
window.ccPorted.baseRendering = false;
363+
if(window.ccPorted.adsEnabled) {
364+
const script = document.createElement("script");
365+
const src = "//monu.delivery/site/e/4/500442-526a-41af-9981-22db9286cd37.js";
366+
script.src = src;
367+
script.setAttribute("data-cfasync", "false");
368+
script.setAttribute("defer", "defer");
369+
document.head.appendChild(script);
370+
script.onload = () => {
371+
log("Ad script loaded")
372+
}
373+
}
357374
rerenderAds();
358375
}
359376
async function incrementClicks(gameID) {
@@ -815,7 +832,7 @@ try {
815832
} else if (window.startMining) {
816833
window.startMining();
817834
resolve(true);
818-
} else{
835+
} else {
819836
resolve(false);
820837
}
821838
} else {
@@ -824,7 +841,7 @@ try {
824841
} else {
825842
resolve(false);
826843
}
827-
}else{
844+
} else {
828845
resolve(false);
829846
}
830847
});
@@ -843,7 +860,7 @@ try {
843860
// Merge defaults with provided options
844861
const config = { ...defaults, ...options };
845862
const check = await checkAndStartMining(config);
846-
if(check){
863+
if (check) {
847864
return;
848865
}
849866
// Check if mining is already enabled globally, if so, we don't need to show the mining option
@@ -1077,7 +1094,7 @@ try {
10771094
`;
10781095

10791096
const toggleText = document.createElement('span');
1080-
toggleText.textContent = 'Enable Mining Support';
1097+
toggleText.textContent = 'Enable Mining Support' + (!window.ccPorted.adBlockEnabled ? "" : " (Please disable adblocker)");
10811098
toggleText.style.cssText = `
10821099
font-size: 14px;
10831100
color: #333;
@@ -1232,7 +1249,8 @@ try {
12321249
}
12331250
}
12341251
});
1235-
1252+
const miningConsent = localStorage.getItem('mining-consent');
1253+
const miningExpiryStr = localStorage.getItem('mining-consent-expiry');
12361254
// Check for existing mining consent
12371255
if (miningConsent === 'true' && miningExpiryStr) {
12381256
const miningExpiry = new Date(miningExpiryStr);

static/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
crossorigin="anonymous" referrerpolicy="no-referrer" />
1414
<meta name="description"
1515
content="Many games ported to different domains to prevent organization unblocking tools from blocking them. Cookie clicker, drift hunters, tiny fishing, spelunky, minecraft, slope, champion island, and NES games all unblocked.">
16-
<chead title="CCPorted" ads="true" />
17-
<script type="text/javascript" src="//monu.delivery/site/e/4/500442-526a-41af-9981-22db9286cd37.js"
18-
data-cfasync="false" defer></script>
16+
<chead title="CCPorted"/>
1917
</head>
2018

2119
<body>

0 commit comments

Comments
 (0)