> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rev.iq/llms.txt
> Use this file to discover all available pages before exploring further.

# Adblock API

export const domain = (() => {
  const placeholder = "your-domain.com";
  if (typeof window !== "undefined" && !globalThis.__revDomainSetup) {
    globalThis.__revDomainSetup = true;
    function textNodes(node) {
      if (node.nodeType === Node.TEXT_NODE) return [node];
      const nodes = [];
      for (const child of node.childNodes) {
        nodes.push(...textNodes(child));
      }
      return nodes;
    }
    function anchorNodes(node) {
      if (node.nodeType === Node.ELEMENT_NODE && node.tagName === "A") return [node];
      const nodes = [];
      for (const child of node.childNodes) {
        nodes.push(...anchorNodes(child));
      }
      return nodes;
    }
    const domain = globalThis.__revDomain || new URLSearchParams(globalThis.location.search).get('domain') || "yourdomain.com";
    globalThis.__revDomain = domain;
    if (globalThis.__revDomainObs) return;
    const obs = globalThis.__revDomainObs || new MutationObserver(mutations => {
      for (const {addedNodes, removedNodes, target} of mutations) {
        for (const node of [...addedNodes, target]) {
          if (node instanceof HTMLScriptElement) continue;
          if (node instanceof HTMLStyleElement) continue;
          for (const textNode of textNodes(node)) {
            if (textNode.nodeValue && textNode.nodeValue.includes(placeholder)) {
              setTimeout(() => {
                textNode.nodeValue = textNode.nodeValue.replace(placeholder, domain);
              }, 100);
            }
          }
          for (const anchorNode of anchorNodes(node)) {
            if (anchorNode.href && anchorNode.href.includes(placeholder)) {
              setTimeout(() => {
                anchorNode.href = anchorNode.href.replace(placeholder, domain);
              }, 100);
            }
          }
        }
      }
    });
    obs.observe(document.body, {
      childList: true,
      subtree: true
    });
  }
  return placeholder;
})();

Roughly 40% of web users use adblock, which can significantly reduce ad revenue.
We offer an **Adblock API** which enables you to prompt adblock users to support
the site.

This API is available as a separate module that you can add to your site by
including an additional script tag. We designed this module to be fast and
lightweight, with a gzipped size of **under 0.3 kB** and requiring no external
dependencies.

## Enable Wrapper Adblock API

Add the Adblock API Module code to the \<head> section of your webpage. We put an `id` so you can remember what
it's for :)

```html theme={null}
<script id="rev-adblock-api">
(function(){var e=`rev_adblock`,t=localStorage,n=atob(`aHR0cHM6Ly9wYWdlYWQyLmdvb2dsZXN5bmRpY2F0aW9uLmNvbS9wYWdlYWQvanMvYWRzYnlnb29nbGUuanM`),r=fetch(n,{method:`HEAD`}).then(e=>!(e.ok&&!e.redirected)).catch(()=>!0).then(n=>n&&(t[e]=!0)),i=globalThis.reviq||=[];i.checkAdblock=()=>r,i.onAdblock=e=>r.then(t=>t&&e()),i.push(n=>r.then(()=>t[e]&&n.setKv(e,1)))})();
</script>
```

## Using the Adblock API

<Info>Note: You should **NOT** use the command queue (`reviq.push(cmd)`) for
these functions. These functions are always available immediately after the
Adblock API Module is loaded.</Info>

Suppose you have some function `showAdblockModal` that shows a modal asking
users to disable adblock.

`reviq.onAdblock(cb)`: runs a callback `cb` if adblock is detected

```js theme={null}
reviq.onAdblock(() => {
   // This only runs if adblock is detected
   showAdblockModal();
});
```

`checkAdblock()`: must be awaited and returns true if adblock is detected, false otherwise

```js theme={null}
// Check for adblock 
const hasAdblock = await reviq.checkAdblock();
if (hasAdblock) {
   showAdblockModal();
}
```
