跳转到主要内容
大约40%的网络用户使用广告拦截工具,这会显著降低广告收入。我们提供了一套Adblock API,让您能够提示使用广告拦截的用户来支持网站。 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. 该API作为独立模块提供,只需在页面中额外引入一个script标签即可启用。该模块设计轻量、加载迅速,gzip压缩后体积不足0.3kB,且无任何外部依赖。 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.

启用Adblock API模块 Enable Wrapper Adblock API

将以下Adblock API模块代码添加到网页的<head>标签中。我们为其添加了id,方便您识别其用途 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 :)
<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>

使用Adblock API Using the Adblock API

注意:这些函数不应通过命令队列(reviq.push(cmd))调用。Adblock API 模块加载完成后,这些函数即可立即使用。 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.
假设您有一个名为showAdblockModal的函数,用于向用户显示弹窗,提示其关闭广告拦截。 Suppose you have some function showAdblockModal that shows a modal asking users to disable adblock. reviq.onAdblock(cb): 检测到广告拦截时,执行回调函数cb runs a callback cb if adblock is detected
reviq.onAdblock(() => {
  // 仅在检测到广告拦截时执行 This only runs if adblock is detected
  showAdblockModal();
});
checkAdblock():需配合await使用,检测到广告拦截时返回true,否则返回false must be awaited and returns true if adblock is detected, false otherwise
// 检测广告拦截 Check for adblock
const hasAdblock = await reviq.checkAdblock();
if (hasAdblock) {
  showAdblockModal();
}