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!

removed automatic captcha

Blue Mouse541d9e46b8af
diff --git a/.prettierrc.js b/.prettierrc.js
new file mode 100644
index 000000000..bd6302ddd
--- /dev/null
+++ b/.prettierrc.js
@@ -0,0 +1,13 @@
+module.exports = {
+ printWidth: 120, // max 120 chars in line, code is easy to read
+ useTabs: false, // use spaces instead of tabs
+ tabWidth: 2, // "visual width" of of the "tab"
+ trailingComma: 'all', // add trailing commas in objects, arrays, etc.
+ semi: false, // Only add semicolons at the beginning of lines that may introduce ASI failures
+ singleQuote: true, // '' for stings instead of ""
+ bracketSpacing: true, // import { some } ... instead of import {some} ...
+ arrowParens: 'always', // braces even for single param in arrow functions (a) => { }
+ jsxSingleQuote: true, // '' for react props
+ bracketSameLine: false, // pretty JSX
+ endOfLine: 'lf', // 'lf' for linux, 'crlf' for windows, we need to use 'lf' for git
+}
diff --git a/src/captcha-loader.ts b/src/captcha-loader.ts
index c66a9d83b..a48fef41c 100644
--- a/src/captcha-loader.ts
+++ b/src/captcha-loader.ts
@@ -17,9 +17,7 @@ enum LOG_ACTIONS {
info = 'info',
}
-const DUMMY_PIDS = [
- 'AP00000000000', 'MP00000000000', 'FAIL000000000',
-]
+const DUMMY_PIDS = ['AP00000000000', 'FAIL000000000']
const isValidPID = (pid: string) => DUMMY_PIDS.includes(pid) || PID_REGEX.test(pid)
@@ -37,9 +35,11 @@ const log = (status: LOG_ACTIONS, text: string) => {
}
const appendParamsToURL = (url: string, params: any) => {
- const queryString = Object.keys(params).map((key) => {
- return `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`
- }).join('&')
+ const queryString = Object.keys(params)
+ .map((key) => {
+ return `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`
+ })
+ .join('&')
return `${url}?${queryString}`
}
@@ -79,9 +79,7 @@ const postMessageCallback = (pmEvent: MessageEvent) => {
return
}
- const {
- type, cid, event,
- } = data
+ const { type, cid, event } = data
if (type !== MESSAGE_IDENTIFIER) {
return
@@ -132,7 +130,7 @@ const postMessageCallback = (pmEvent: MessageEvent) => {
break
}
-
+
case 'manualStarted': {
const frame = document.getElementById(getFrameID(cid))
@@ -166,9 +164,10 @@ const generateCaptchaFrame = (params: any) => {
const captchaFrame = document.createElement('iframe')
captchaFrame.id = getFrameID(params.cid)
- captchaFrame.src = theme === 'dark'
- ? appendParamsToURL(DARK_CAPTCHA_IFRAME_URL, params)
- : appendParamsToURL(LIGHT_CAPTCHA_IFRAME_URL, params)
+ captchaFrame.src =
+ theme === 'dark'
+ ? appendParamsToURL(DARK_CAPTCHA_IFRAME_URL, params)
+ : appendParamsToURL(LIGHT_CAPTCHA_IFRAME_URL, params)
captchaFrame.style.height = FRAME_HEIGHT_MAPPING.default
captchaFrame.title = 'Swetrix Captcha'
captchaFrame.style.border = 'none'
diff --git a/src/captcha.ts b/src/captcha.ts
index 87bc812f9..ff0c105d0 100644
--- a/src/captcha.ts
+++ b/src/captcha.ts
@@ -9,9 +9,8 @@ let TOKEN = ''
let HASH = ''
const ENDPOINTS = {
- VERIFY: '/verify',
GENERATE: '/generate',
- VERIFY_MANUAL: '/verify-manual',
+ VERIFY: '/verify',
}
enum IFRAME_MESSAGE_TYPES {
@@ -32,13 +31,16 @@ enum ACTION {
let activeAction: ACTION = ACTION.checkbox
const sendMessageToLoader = (event: IFRAME_MESSAGE_TYPES, data = {}) => {
- window.parent.postMessage({
- event,
- type: MSG_IDENTIFIER,
- // @ts-ignore
- cid: window.__SWETRIX_CAPTCHA_ID,
- ...data,
- }, '*')
+ window.parent.postMessage(
+ {
+ event,
+ type: MSG_IDENTIFIER,
+ // @ts-ignore
+ cid: window.__SWETRIX_CAPTCHA_ID,
+ ...data,
+ },
+ '*',
+ )
}
/**
@@ -132,35 +134,9 @@ const generateCaptcha = async () => {
pid: window.__SWETRIX_PROJECT_ID,
}),
})
-
- if (!response.ok) {
- throw ''
- }
-
- const data = await response.json()
- return data
- } catch (e) {
- sendMessageToLoader(IFRAME_MESSAGE_TYPES.FAILURE)
- activateAction(ACTION.failure)
- return {}
- }
-}
-
-const verify = async () => {
- try {
- const response = await fetch(`${API_URL}${ENDPOINTS.VERIFY}`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- // @ts-ignore
- pid: window.__SWETRIX_PROJECT_ID,
- }),
- })
if (!response.ok) {
- return {}
+ throw ''
}
const data = await response.json()
@@ -199,7 +175,7 @@ document.addEventListener('DOMContentLoaded', () => {
let response
try {
- response = await fetch(`${API_URL}${ENDPOINTS.VERIFY_MANUAL}`, {
+ response = await fetch(`${API_URL}${ENDPOINTS.VERIFY}`, {
method: 'POST',
body: JSON.stringify({
hash: HASH,
@@ -261,24 +237,9 @@ document.addEventListener('DOMContentLoaded', () => {
activateAction(ACTION.loading)
- try {
- const { token } = await verify()
-
- if (!token) {
- throw ''
- }
-
- TOKEN = token
- sendMessageToLoader(IFRAME_MESSAGE_TYPES.SUCCESS, { token })
- setLifetimeTimeout()
- activateAction(ACTION.completed)
- return
- } catch (e) {
- const { data, hash } = await generateCaptcha()
+ const { data, hash } = await generateCaptcha()
- HASH = hash
- enableManualChallenge(data)
- return
- }
+ HASH = hash
+ enableManualChallenge(data)
})
})
diff --git a/src/pages/test.html b/src/pages/test.html
index ba07171db..e1ef6846f 100644
--- a/src/pages/test.html
+++ b/src/pages/test.html
@@ -25,7 +25,7 @@
<input type="text" name="name" value="name">
<input type="text" name="email" value="email">
<input type="number" name="number" value="number">
- <div class="swecaptcha" data-project-id="MP00000000000" data-theme="light"></div>
+ <div class="swecaptcha" data-project-id="AP00000000000" data-theme="light"></div>
<input type="submit" value="Submit">
</form>
</body>