> ## 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();
}
```
