/** * the site key for Google reCAPTCHA v3 */ const SITE_KEY = "6Ldxtt8UAAAAALvcRqWTlVOVIB7MmEWwN-zw_9fM" type token = string; interface GRecaptcha { ready(cb: Function): void; execute(siteKey: string, opts: { action: string }): Promise; } let gr: GRecaptcha | Promise /** * load reCAPTCHA */ const load = (): Promise => { // load script const script = document.createElement("script") script.src = `https://www.recaptcha.net/recaptcha/api.js?render=${SITE_KEY}` script.async = true document.body.appendChild(script) // add css const style = document.createElement("style") style.innerHTML = ".grecaptcha-badge { display: none !important; }" document.head.appendChild(style) return new Promise((resolve) => { script.onload = () => { const grecaptcha: GRecaptcha = window["grecaptcha"] grecaptcha.ready(() => resolve(grecaptcha)) } }) } export const init = () => { if (!gr) { gr = load() } return gr } export const execute = async (): Promise => { const captcha = await init() return captcha.execute(SITE_KEY, { action: "downloadmscz" }) }