@cunpingtai/webad-react-ad-scripts 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -34,13 +34,15 @@ export function AdvertisingProvider({ children }: React.PropsWithChildren) {
34
34
 
35
35
  `pageKey` 只在真实路由切换时变化。不要传随机数、时间戳、Tab 状态或窗口宽度。
36
36
 
37
+ 本地开发环境不会显示广告。`localhost`、`*.localhost`、`127.0.0.1` 和 `::1` 不会请求中央配置。
38
+
37
39
  ## 后台配置
38
40
 
39
41
  打开 `https://a1.yumeref.com/admin`,编辑对应站点:
40
42
 
41
43
  - Social Bar、Popunder、Smartlink 每站各配置一个;
42
44
  - Banner 和 Native Banner 可以添加多个;
43
- - 每个页面广告位使用唯一名称,例如 `home-top`、`article-middle`、`sidebar-sticky`;
45
+ - 当前统一使用三个 Banner 名称:`placement-728x90`、`placement-320x50`、`placement-300x250`;Native Banner 使用 `placement-native`;
44
46
  - Banner 填脚本地址、广告 Key、宽度和高度;
45
47
  - Native Banner 填脚本地址和 Container ID。
46
48
 
@@ -57,8 +59,9 @@ import {
57
59
  AdsterraSocialBar,
58
60
  } from "@cunpingtai/webad-react-ad-scripts";
59
61
 
60
- <AdsterraBanner placement="home-top" />
61
- <AdsterraNativeBanner placement="article-middle" />
62
+ <AdsterraBanner placement="placement-728x90" />
63
+ <AdsterraBanner placement="placement-300x250" />
64
+ <AdsterraNativeBanner placement="placement-native" />
62
65
 
63
66
  <AdsterraSmartlink className="download-button">
64
67
  继续下载
@@ -68,7 +71,7 @@ import {
68
71
  <AdsterraPopunder />
69
72
  ```
70
73
 
71
- Banner 和 Native Banner 还支持 `className`、`style`。组件找不到对应配置、类型不匹配或当前策略不允许时会返回 `null`。
74
+ 这些是后台广告位名称,不是自动识别的尺寸参数;后台配置的尺寸必须与名称对应。同一页面中的同一个 `placement` 只加载一次。Banner 和 Native Banner 还支持 `className`、`style`。组件找不到对应配置、类型不匹配或当前策略不允许时会返回 `null`。
72
75
 
73
76
  ## 策略
74
77
 
package/dist/index.js CHANGED
@@ -15003,6 +15003,13 @@ function AdsProvider({
15003
15003
  mounted = false;
15004
15004
  };
15005
15005
  }
15006
+ if (isLocalHostname(window.location.hostname)) {
15007
+ setPlan(null);
15008
+ emit({ state: "disabled", mode: "none" });
15009
+ return () => {
15010
+ mounted = false;
15011
+ };
15012
+ }
15006
15013
  const load = async () => {
15007
15014
  setPlan(null);
15008
15015
  emit({ state: "loading-config" });
@@ -15067,6 +15074,10 @@ function AdsProvider({
15067
15074
  }, [nonce, plan, providerId, validatedPageKey]);
15068
15075
  return /* @__PURE__ */ jsx(AdsContext.Provider, { value: context, children });
15069
15076
  }
15077
+ function isLocalHostname(hostname3) {
15078
+ const normalized = hostname3.toLowerCase();
15079
+ return normalized === "localhost" || normalized.endsWith(".localhost") || normalized === "127.0.0.1" || normalized === "[::1]" || normalized === "::1";
15080
+ }
15070
15081
 
15071
15082
  // src/AdsterraBanner.tsx
15072
15083
  import { useEffect as useEffect2, useRef as useRef2 } from "react";