> ## 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.

# アドブロック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;
})();

ウェブユーザーの約40%がアドブロックを使用しており、広告収益を大幅に減少
させる可能性があります。RevIQでは、アドブロック使用者にサイトの支援を
促すことができる**アドブロックAPI**を提供しています。

このAPIは独立したモジュールとして提供されており、追加のスクリプトタグを
サイトに含めるだけで利用できます。このモジュールは高速かつ軽量に設計されて
おり、gzip圧縮後のサイズは**0.3 kB未満**で、外部依存もありません。

## アドブロックAPIラッパーの有効化

アドブロックAPIモジュールのコードを、ウェブページの\<head>セクションに追加
してください。用途が分かるように`id`を付けています :)

```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>
```

## アドブロックAPIの使用方法

<Info>注意: これらの関数にはコマンドキュー（`reviq.push(cmd)`）を使用
**しないでください**。これらの関数は、アドブロックAPIモジュールの読み込み
直後から常に利用可能です。</Info>

例えば、アドブロックを無効にするようユーザーに促すモーダルを表示する関数
`showAdblockModal`があるとします。

`reviq.onAdblock(cb)`: アドブロックが検出された場合にコールバック`cb`を実行します

```js theme={null}
reviq.onAdblock(() => {
   // アドブロックが検出された場合のみ実行されます
   showAdblockModal();
});
```

`checkAdblock()`: awaitが必要で、アドブロックが検出された場合はtrue、
そうでない場合はfalseを返します

```js theme={null}
// アドブロックを確認
const hasAdblock = await reviq.checkAdblock();
if (hasAdblock) {
   showAdblockModal();
}
```
