xref: /plugin/captcha/script.js (revision f469e1e35809446d05cb365abf11ae98dcf3719c)
1jQuery(() => {
2    const wrappers = document.querySelectorAll('.plugin__captcha_wrapper');
3
4    wrappers.forEach((wrap) => {
5        /**
6         * Autofill and hide the whole CAPTCHA stuff in the simple JS mode
7         */
8        const code = wrap.querySelector('.plugin__captcha_code');
9        if (code) {
10            const box = wrap.querySelector('input[type=text]');
11            if (box) {
12                box.value = code.textContent.replace(/([^A-Z])+/g, '');
13            }
14            wrap.style.display = 'none';
15        }
16
17        /**
18         * Add a HTML5 player for the audio version of the CAPTCHA
19         */
20        const audiolink = wrap.querySelector('a.audiolink');
21        if (audiolink) {
22            const audio = document.createElement('audio');
23            audio.src = audiolink.getAttribute('href');
24            wrap.appendChild(audio);
25            audiolink.addEventListener('click', (e) => {
26                audio.play();
27                e.preventDefault();
28                e.stopPropagation();
29            });
30        }
31    });
32});
33