Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
🐛 修复 reCAPTCHA 反复加载的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
ocoke committed Apr 4, 2023
1 parent 565a809 commit 088b3c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
package-lock.json
dev/
.vscode/
.vscode/
.idea
10 changes: 9 additions & 1 deletion src/lib/recaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default async function recaptcha(siteKey, reload) {


// 载入 reCAPTCHA
if (window.DETALK_INIT && !window.DETALK_INIT.recaptchaLoaded) {
if (window.DETALK_INIT && !window.DETALK_INIT.recaptchaLoaded && !window.grecaptcha) {
let script = document.createElement('script');
script.src = 'https://www.recaptcha.net/recaptcha/api.js?render=' + siteKey || window.DETALK_RECAPTCHA_SITE_KEY;
script.async = true;
Expand All @@ -18,9 +18,17 @@ export default async function recaptcha(siteKey, reload) {
grecaptcha.ready(function() {
grecaptcha.execute(siteKey || window.DETALK_RECAPTCHA_SITE_KEY, {action: 'DetalkJS'}).then(function(token) {
window.DETALK_RECAPTCHA_TOKEN = token;
window.DETALK_INIT.recaptchaLoaded = true;
});
});
}
document.body.appendChild(script);
} else if (window.DETALK_INIT.recaptchaLoaded || window.grecaptcha) {
// 有 reCAPTCHA script, 直接执行
grecaptcha.ready(function() {
grecaptcha.execute(siteKey || window.DETALK_RECAPTCHA_SITE_KEY, {action: 'DetalkJS'}).then(function(token) {
window.DETALK_RECAPTCHA_TOKEN = token;
});
});
}
}

0 comments on commit 088b3c8

Please sign in to comment.