Skip to content
This repository was archived by the owner on Aug 29, 2024. It is now read-only.

Commit 9f361b4

Browse files
committed
feat: optinal split config
1 parent c24de0e commit 9f361b4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/main.tsx

+12-3
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,24 @@ export const NewCaptcha = ({
5050
el: HTMLElement,
5151
options: {
5252
sitekey: string; // https://mini.nyacap.com/widget?sitekey=demo
53+
instance?: string;
5354
theme?: "light" | "dark";
5455
callback?: (key: string) => void;
5556
"expired-callback"?: () => void;
5657
"error-callback"?: () => void;
5758
},
5859
) => {
59-
const parsedSiteKey = new URL(options.sitekey);
60-
const instance = parsedSiteKey.origin;
61-
const siteKey = parsedSiteKey.searchParams.get("sitekey");
60+
let instance, siteKey;
61+
62+
// 两种配置方式:分别指定 instance 和 siteKey ,或合并到一起
63+
if (options.instance) {
64+
instance = options.instance;
65+
siteKey = options.sitekey;
66+
} else {
67+
const parsedSiteKey = new URL(options.sitekey);
68+
instance = parsedSiteKey.origin;
69+
siteKey = parsedSiteKey.searchParams.get("sitekey");
70+
}
6271

6372
if (siteKey === null) {
6473
throw new Error("未定义 sitekey");

0 commit comments

Comments
 (0)