code.gitea.io/gitea@v1.21.7/web_src/js/features/captcha.js (about)

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