mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-27 04:15:18 +00:00
857d3d3df3
Update eslint and its plugins, enable more rules and fix their findings: 1. `unicorn/no-unsafe-string-replacement` found that uploading a file whose name contains `$&` inserted a broken markdown link, because `String#replace` expands such patterns in the replacement string 2. `@typescript-eslint/require-await` removes `async` from functions that never await 3. Plugin rules not covered by a preset are now listed explicitly --------- Co-authored-by: bircni <bircni@icloud.com>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import {isDarkTheme} from '../utils.ts';
|
|
|
|
export async function initCaptcha() {
|
|
const captchaEl = document.querySelector('#captcha');
|
|
if (!captchaEl) return;
|
|
|
|
const siteKey = captchaEl.getAttribute('data-sitekey')!;
|
|
const isDark = isDarkTheme();
|
|
|
|
const params = {
|
|
sitekey: siteKey,
|
|
theme: isDark ? 'dark' : 'light',
|
|
};
|
|
|
|
switch (captchaEl.getAttribute('data-captcha-type') ?? '') {
|
|
case 'g-recaptcha': {
|
|
if (window.grecaptcha) {
|
|
window.grecaptcha.ready(() => {
|
|
window.grecaptcha.render(captchaEl, params);
|
|
});
|
|
}
|
|
break;
|
|
}
|
|
case 'cf-turnstile': {
|
|
if (window.turnstile) {
|
|
window.turnstile.render(captchaEl, params);
|
|
}
|
|
break;
|
|
}
|
|
case 'h-captcha': {
|
|
if (window.hcaptcha) {
|
|
window.hcaptcha.render(captchaEl, params);
|
|
}
|
|
break;
|
|
}
|
|
case 'm-captcha': {
|
|
// ref: https://github.com/mCaptcha/glue/blob/master/packages/vanilla/README.md
|
|
// sample: https://github.com/mCaptcha/glue/blob/master/packages/vanilla/static/embeded.html
|
|
// @mcaptcha/vanilla-glue 0.1.0-rc2 auto-runs on module load, use the existing elements to render.
|
|
await import('@mcaptcha/vanilla-glue');
|
|
break;
|
|
}
|
|
default:
|
|
}
|
|
}
|