diff --git a/templates/user/auth/captcha.tmpl b/templates/user/auth/captcha.tmpl index 4360e02b7a9..2e2e9c80806 100644 --- a/templates/user/auth/captcha.tmpl +++ b/templates/user/auth/captcha.tmpl @@ -1,5 +1,5 @@ {{if .EnableCaptcha}}{{if eq .CaptchaType "image"}} -
+
{{.Captcha.CreateHTML}}
diff --git a/web_src/js/features/captcha.ts b/web_src/js/features/captcha.ts index 8a15c7ddc40..225c453ead7 100644 --- a/web_src/js/features/captcha.ts +++ b/web_src/js/features/captcha.ts @@ -1,6 +1,19 @@ import {isDarkTheme} from '../utils.ts'; +import {registerGlobalInitFunc} from '../modules/observer.ts'; export async function initCaptcha() { + registerGlobalInitFunc('initImageCaptcha', (el: HTMLElement) => { + const a = el.querySelector('a')!; + a.removeAttribute('href'); // remove generated href="javascript:" + const img = el.querySelector('img')!; + img.removeAttribute('onclick'); // remove generated onclick="...." and use our own event listener + img.addEventListener('click', () => { + const url = new URL(img.src); + url.searchParams.set('reload', String(Date.now())); + img.src = url.href; + }); + }); + const captchaEl = document.querySelector('#captcha'); if (!captchaEl) return;