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

# Desktop Apps

> 仅需几行代码，即可在您的 Electron 应用中投放广告 Serve ads in your Electron app with a few lines of code

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

### 安装 Installation

安装rev-utils库，为您的 Electron 应用添加完整的广告支持。我们可能会不定期更新该包。
Install the rev-utils library to augment your Electron setup with full
compatibility for ads. We may occassionally update the package.

```sh theme={null}
npm i -D rev-utils@https://r2.reviq.app/rev-utils-v1.0.3.tgz
```

### 使用方法 Usage

使用`new BrowserWindow`创建新窗口后，将窗口对象和`electron`全局变量传入 `setupRevUtils`。
After creating window with `new BrowserWindow`, pass in the window and
`electron` global into `setupRevUtils`

```js main.js theme={null}
const { setupRevUtils } = require("rev-utils");

// 注意：此处引用的是electron全局变量！ Note the import of the global electron here!
const electron = require("electron");
// 您可以从该模块对象中解构所需的引用 You can destructure your imports from this module object
const { BrowserWindow } = electron;

const myWindow = new BrowserWindow();

setupRevUtils(myWindow, electron);
```

<Info>
  `setupRevUtils`在底层调用了窗口的两个函数：
  -`setupLinkHandler`：用于打开广告（同时拦截恶意行为！）
  -`setUserAgent`：用于移除User Agent字符串中的非标准部分，这些非标准内容可能触发无效流量（IVT）检测。<Tooltip tip="IVT 检测服务商会检查多种信号，包括非标准的User Agent，这些信号可能被误判为自动化流量"> \[?] </Tooltip>
  Under the hood, `setupRevUtils` calls two functions on the window -
  `setupLinkHandler` to open ads (and block malicious behavior!) -
  `setUserAgent`, which removes non-standard portions of the User Agent string
  which may trigger IVT (invalid traffic).{" "}

  <Tooltip
    tip="IVT vendors check many
signals, including non-standard user agents, which they may erroneously flag
as automated traffic"
  >
    {" "}

    \[?]{" "}
  </Tooltip>
</Info>
