AdShield
v1.03 · vanilla JavaScript · zero dependencies

AdShield

Ads help developers keep their projects running.

AdShield detects whether a visitor is running an ad blocker using three independent methods, then shows an on-brand warning modal when it finds one — no server, no third-party dependencies.

index.html
<script src="adshield.js"></script>
Features

One file, full control

Every behavior lives inside a single file: appearance, copy, strictness, and detection sensitivity.

01

Aggressive & informative modal

When an ad blocker is detected, a centered window opens over a blurred backdrop. It can be either impossible to dismiss (strict) or dismissible, depending on your configuration.

02

Theming that matches your site

The THEME array lets you map background, button, and text colors to your brand identity in minutes.

03

Copy optimization

Every title, description, and button label lives in the TEXTS array, so you can rewrite the tone and language to fit your brand.

04

Randomized element IDs

Every time the modal opens, all of its elements are built with a fresh, unique ID — so ad blocker filter lists that rely on static CSS/JS selectors can't target it.

05

Three-layer detection

Combines bait elements, ad script loading, and ad pixel loading into a scoring system that reduces false positives.

06

Zero dependencies

No build step, no package manager, no server-side setup. Add the file, and it runs automatically once the page loads.

How it works

Three methods, one score

AdShield runs three independent checks in the browser. Each check casts its own vote, and at least two of them need to come back "blocked" before AdShield is confident an ad blocker is present.

01

Bait elements

Small elements hidden off-screen are added to the page with class names commonly targeted by ad blocker filter lists, such as adsbox, adsbygoogle, and text-ad. Their visibility is checked at set intervals (50ms, 400ms, 1s, 2s). If more than half of them end up hidden, this check votes "blocked".

02

Ad script loading

Known ad network script files (e.g. adsbygoogle.js, gpt.js) are loaded into the page. If a script fails to load or times out (2.5 seconds by default), this check votes "blocked".

03

Ad pixel loading

Known tracking/ad pixel URLs are requested through an <img> tag. If loading fails or times out, this check votes "blocked" as well.

The default threshold (positiveThreshold) is 2: if at least two of the three checks vote "blocked", AdShield decides an ad blocker is active and shows the modal according to your configured mode.
Install

Up and running in one line

No build tools or package managers required. Copy adshield.js into your project and add one script tag — that's the entire setup.

<!-- 1. Copy adshield.js into your project --> <!-- 2. Add the script tag right before the closing body tag --> <body> ...your page content... <script src="adshield.js"></script> </body>
// AdShield runs automatically once the page has fully loaded. // If an ad blocker is detected, the modal opens on its own — // if not, nothing is shown at all. // Manual control is also available: AdShield.check(function(isBlocked, detail) { if (isBlocked) { console.log("Ad blocker detected", detail); } });
Configuration

Shape it around your brand

Edit the THEME, TEXTS, and CONFIG sections at the top of adshield.js to customize appearance and behavior.

ADBLOCK_DETECTOR_STRICT_MODE
true → the modal can't be dismissed; the visitor can only continue by disabling their ad blocker and reloading. false → the modal can be closed by clicking the backdrop (but it will reappear on the next page load if the ad blocker is still active).
THEME
The array that controls the modal's overlay, background, title, message, and button colors. Each entry is a color key paired with a hex or rgba value.
TEXTS
All of the modal's copy — title, message, and button labels. Separate messages can be defined for strict and dismissible modes.
CONFIG.iconImageUrl
The image shown at the top center of the modal (a URL or a base64 data URI).
CONFIG.recheckDelays
The list of delays (in milliseconds) at which bait elements are re-checked for visibility.
CONFIG.networkTimeout
The maximum time, in milliseconds, the script and pixel checks wait before being counted as blocked.
CONFIG.positiveThreshold
How many of the three checks need to vote "blocked" before the modal is shown (default: 2).
// These can also be updated dynamically from your page: AdShield.config.strictMode = false; AdShield.config.iconImageUrl = "/images/logo.png"; AdShield.config.theme = [ { key: "buttonBackground", value: "#0b5fff" } ];
The "Powered by AdShield" badge is fixed and can't be removed or re-themed through configuration — it's a permanent part of the modal.