npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

anti-adblock-detector

v1.0.0

Published

A powerful, lightweight anti-adblock detection library for React and Vanilla JS. Detects ad blockers with multiple strategies and shows a professional, customizable overlay.

Readme

anti-adblock-detector

A powerful, lightweight, and professional anti-adblock detection library for React and Vanilla JavaScript. Protect your website's ad revenue with multiple detection strategies and a stunning, customizable overlay.

Features

  • 🛡️ Triple Detection: Uses 3 independent strategies (Bait Element, Fake Script, Fetch Test) for maximum accuracy.
  • ⚛️ React Component: Simple <AntiAdBlock /> drop-in component.
  • 🪝 React Hook: useAdBlockDetector() hook for custom UI implementations.
  • 🍦 Vanilla JS: detectAdBlocker() function for non-React projects.
  • 🎨 Premium UI: Glassmorphism overlay with smooth animations.
  • 🔒 Hard Block Mode: Optionally prevent site access until ad blocker is disabled.
  • ♻️ Recheck Support: Users can recheck after disabling their ad blocker.
  • 📱 Fully Responsive: Looks great on desktop and mobile.
  • 🪶 Zero Dependencies: No external runtime dependencies.

Installation

npm install anti-adblock-detector
# or
yarn add anti-adblock-detector

Quick Start (React)

import { AntiAdBlock } from 'anti-adblock-detector';
import 'anti-adblock-detector/styles.css';

function App() {
  return (
    <>
      <AntiAdBlock 
        onDetected={(result) => console.log('Ad blocker detected!', result)}
        onDismissed={() => console.log('User chose to continue')}
      />
      <div>Your website content here...</div>
    </>
  );
}

Hard Block Mode

Force users to disable their ad blocker before accessing the site:

<AntiAdBlock 
  hardBlock={true}
  title="Please Support Us"
  description="This content is only available without an ad blocker."
/>

Custom Hook

Build your own UI with the useAdBlockDetector hook:

import { useAdBlockDetector } from 'anti-adblock-detector';

function CustomBanner() {
  const { loading, detected, recheck } = useAdBlockDetector();

  if (loading) return <p>Checking...</p>;
  if (!detected) return null;

  return (
    <div className="my-custom-banner">
      <p>We noticed you're using an ad blocker. Please support us!</p>
      <button onClick={recheck}>I've disabled it</button>
    </div>
  );
}

Vanilla JavaScript

import { detectAdBlocker } from 'anti-adblock-detector';

async function checkAds() {
  const result = await detectAdBlocker();
  
  if (result.detected) {
    alert('Ad blocker detected!');
    console.log('Strategies:', result.strategies);
  }
}

checkAds();

Props

| Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | enabled | boolean | true | Enable/disable detection. | | hardBlock | boolean | false | If true, user cannot dismiss the overlay. | | title | string | "Ad Blocker Detected" | Modal title text. | | description | string | "We rely on ads..." | Modal description text. | | primaryButtonText | string | "I've Disabled My Ad Blocker" | Primary button label. | | dismissButtonText | string | "Continue Without Disabling" | Dismiss button label. | | tipText | string | "After disabling..." | Tip text at the bottom. | | delay | number | 500 | Delay (ms) before showing the modal. | | onDetected | (result) => void | - | Callback when ad blocker is detected. | | onAllowed | () => void | - | Callback when user confirms disable. | | onDismissed | () => void | - | Callback when user dismisses overlay. | | children | ReactNode | - | Render your own custom modal content. |

How Detection Works

The library uses three independent detection strategies:

  1. Bait Element: Creates a hidden DOM element with common ad-related class names (e.g., ad-banner, adsbox). If the element gets hidden/removed by an ad blocker, detection is positive.
  2. Fake Script: Attempts to load a script from Google AdSense's URL. If blocked, detection is positive.
  3. Fetch Test: Makes a HEAD request to a known ad-serving domain. If the request fails, detection is positive.

If any strategy returns positive, the ad blocker is considered active.

License

MIT © Antigravity