You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

captcha.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {isDarkTheme} from '../utils.js';
  2. export async function initCaptcha() {
  3. const captchaEl = document.querySelector('#captcha');
  4. if (!captchaEl) return;
  5. const siteKey = captchaEl.getAttribute('data-sitekey');
  6. const isDark = isDarkTheme();
  7. const params = {
  8. sitekey: siteKey,
  9. theme: isDark ? 'dark' : 'light',
  10. };
  11. switch (captchaEl.getAttribute('data-captcha-type')) {
  12. case 'g-recaptcha': {
  13. if (window.grecaptcha) {
  14. window.grecaptcha.ready(() => {
  15. window.grecaptcha.render(captchaEl, params);
  16. });
  17. }
  18. break;
  19. }
  20. case 'cf-turnstile': {
  21. if (window.turnstile) {
  22. window.turnstile.render(captchaEl, params);
  23. }
  24. break;
  25. }
  26. case 'h-captcha': {
  27. if (window.hcaptcha) {
  28. window.hcaptcha.render(captchaEl, params);
  29. }
  30. break;
  31. }
  32. case 'm-captcha': {
  33. const {default: mCaptcha} = await import(/* webpackChunkName: "mcaptcha-vanilla-glue" */'@mcaptcha/vanilla-glue');
  34. mCaptcha.INPUT_NAME = 'm-captcha-response';
  35. const instanceURL = captchaEl.getAttribute('data-instance-url');
  36. mCaptcha.default({
  37. siteKey: {
  38. instanceUrl: new URL(instanceURL),
  39. key: siteKey,
  40. },
  41. });
  42. break;
  43. }
  44. default:
  45. }
  46. }