Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

captcha loader initial commit

Blue Mouse4b5b03fec60e
diff --git a/captcha-loader.js b/captcha-loader.js
index e69de29bb..813bbe2b9 100644
--- a/captcha-loader.js
+++ b/captcha-loader.js
@@ -0,0 +1,31 @@
+(() => {
+ const CAPTCHA_SELECTOR = '.swecaptcha'
+ const CAPTCHA_IFRAME_URL = './index.html'
+
+ const renderCaptcha = (container) => {
+ const captchaFrame = document.createElement('iframe')
+
+ captchaFrame.src = CAPTCHA_IFRAME_URL
+ captchaFrame.title = 'Swetrix Captcha'
+
+ container.appendChild(captchaFrame)
+ }
+
+ const main = () => {
+ const containers = document.querySelectorAll(CAPTCHA_SELECTOR)
+
+ for (const container of containers) {
+ renderCaptcha(container)
+ }
+ }
+
+ const log = (status, text) => {
+ console[status](`[Swetrix Captcha] ${text}`)
+ }
+
+ if ('swecaptcha' in window) {
+ log('warn', 'Captcha is already loaded.')
+ }
+
+ document.addEventListener('DOMContentLoaded', main)
+})