Notice
In case it wasn't clear, the first inline <script> in each of these examples should be replaced with <script src="/ads/ads.js"></script> in order to work. I just can't do that here.
tl;dr
On the website, your ads.js file is loaded asynchronously using data-rocketsrc="ads.js". Replace this with src="ads.js" to load it synchronously before the next inline script executes. Your page (omitting the CloudFlare) should look like this:
<html>
<head>
<title>Test Adblock</title>
<script src="ads.js"></script>
</head>
<body>
<script>
'use strict';
if (typeof canRunAds === 'undefined') {
document.write('canRunAds is being blocked<br/>');
}
</script>
</body>
</html>
And the content of https://flamingocams.com/ads/ads.js should be:
var canRunAds = true;
Currently it has the contents:
<script>var canRunAds=true;</script>
I will admit I'm no expert in rocketscript, but my guess is that the running context of the script using that preprocessor is not window. Run it as regular JavaScript to guarantee synchronous execution in the window context.
Answer
Simply use typeof canRunAds === 'undefined'. There is no need to use window.canRunAds, since typeof suppresses any possible ReferenceError when checking an undeclared variable, even in strict mode:
<script>
'use strict';
var canRunAds = true;
// to demonstrate the conditional `if` works
// var someOtherFlag = true;
</script>
<script>
'use strict';
if (typeof canRunAds === 'undefined') {
document.write('canRunAds is being blocked<br/>');
}
if (typeof someOtherFlag === 'undefined') {
document.write('someOtherFlag is being blocked<br/>');
}
</script>
However, it's generally a more common practice to have an element on the page that's conditionally visible based on CSS like this:
p.adblock-warning {
display: none;
color: red;
}
body.adblock p.adblock-warning {
display: initial;
}
<script>
// assume this couldn't run
// var canRunAds = true;
</script>
<script>
if (typeof canRunAds === 'undefined') {
document.body.classList.add('adblock');
}
</script>
<p class="adblock-warning">Adblock is enabled, Please disabled to continue.</p>