From 72f2e0b761e0869e59a232e199b9422084c1fdb6 Mon Sep 17 00:00:00 2001 From: Fionera Date: Wed, 15 Nov 2023 05:02:30 +0100 Subject: [PATCH] lint fix --- web/src/challange/challanger.js | 16 ++++++++-------- web/src/challange/challanges.js | 18 +++++++++--------- web/src/challange/fingerprinting.js | 6 +++--- web/src/challange/loader.js | 14 +++++++------- web/src/main.js | 4 ++-- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/web/src/challange/challanger.js b/web/src/challange/challanger.js index 9394331..62caea2 100644 --- a/web/src/challange/challanger.js +++ b/web/src/challange/challanger.js @@ -10,7 +10,7 @@ import * as loader from "./loader.js"; * * @return {Promise} */ -async function getChallenge() { +async function getChallenge(){ const resp = await fetch("/cdn-cgi/challenge-platform/challenge"); return await resp.json(); } @@ -20,30 +20,30 @@ async function getChallenge() { * * @return {Promise} */ -export async function doChallenge() { +export async function doChallenge(){ loader.start(); let result; try { - loader.setChallengeInfo("Fetching challenge...") + loader.setChallengeInfo("Fetching challenge..."); const challenge = await getChallenge(); const {t} = challenge; const [name, solver] = getChallengeSolver(t); - loader.setChallengeInfo(name) + loader.setChallengeInfo(name); result = await solver(challenge); - if (!!result) { + if (!!result){ result = `Validation result: ${result}`; } - } catch (e) { + } + catch (e){ result = e.toString(); } loader.stop(!!result); - if (result) { + if (result){ loader.showError(result); } - } diff --git a/web/src/challange/challanges.js b/web/src/challange/challanges.js index be07640..60127ae 100644 --- a/web/src/challange/challanges.js +++ b/web/src/challange/challanges.js @@ -11,7 +11,7 @@ import {isCanvasSupported, isNotHeadless, isUsualBrowserBasedOnUa} from "./fing * @param {AlgorithmIdentifier} method * @return {Promise} */ -async function nativeHash(data, method) { +async function nativeHash(data, method){ const hashBuffer = await crypto.subtle.digest(method, new TextEncoder().encode(data)); const hashArray = Array.from(new Uint8Array(hashBuffer)); return hashArray.map(b => b.toString(16).padStart(2, "0")).join(""); @@ -23,13 +23,13 @@ async function nativeHash(data, method) { * @param {object} challenge * @return {Promise} */ -async function challengePOW(challenge) { +async function challengePOW(challenge){ let hash; let i; // eslint-disable-next-line no-constant-condition - for (i = 0; true; i++) { + for (i = 0; true; i++){ hash = await nativeHash(challenge.r + i.toString(), "sha-256"); - if (hash.startsWith("0000")) { + if (hash.startsWith("0000")){ break; } } @@ -45,7 +45,7 @@ async function challengePOW(challenge) { * * @return {Promise} */ -async function challengeFingerprinting() { +async function challengeFingerprinting(){ const usualUa = isUsualBrowserBasedOnUa(); if (!usualUa) return "ua"; @@ -63,14 +63,14 @@ async function challengeFingerprinting() { * * @return {Promise} */ -async function challengeNone() { +async function challengeNone(){ return new Promise((resolve) => { setTimeout(resolve, 3000); }); } -export function getChallengeSolver(challengeType) { - switch (challengeType) { +export function getChallengeSolver(challengeType){ + switch (challengeType){ case 0: return ["Please wait...", challengeNone]; case 1: @@ -80,4 +80,4 @@ export function getChallengeSolver(challengeType) { default: throw new Error(`Unknown challenge type: ${challengeType}`); } -} \ No newline at end of file +} diff --git a/web/src/challange/fingerprinting.js b/web/src/challange/fingerprinting.js index 14cd822..9201bbe 100644 --- a/web/src/challange/fingerprinting.js +++ b/web/src/challange/fingerprinting.js @@ -7,7 +7,7 @@ * * @return {boolean} */ -export function isUsualBrowserBasedOnUa() { +export function isUsualBrowserBasedOnUa(){ const ua = navigator.userAgent; const isUsualBrowser = ua.includes("Chrome") || ua.includes("Firefox") @@ -25,7 +25,7 @@ export function isUsualBrowserBasedOnUa() { * * @return {boolean} */ -export function isNotHeadless() { +export function isNotHeadless(){ const isHeadless = !!navigator.webdriver // @ts-ignore || !!window.chrome // @ts-ignore || !!navigator.callPhantom || !!navigator.__phantom @@ -39,7 +39,7 @@ export function isNotHeadless() { * * @return {boolean} */ -export function isCanvasSupported() { +export function isCanvasSupported(){ const canvas = document.createElement("canvas"); const gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); return !!gl; diff --git a/web/src/challange/loader.js b/web/src/challange/loader.js index cfa88a3..c2cbafa 100644 --- a/web/src/challange/loader.js +++ b/web/src/challange/loader.js @@ -5,17 +5,17 @@ /** * Start the countdown. */ -export function start() { +export function start(){ const loader = /** @type {HTMLDivElement} */ (document.querySelector(".circle-loader")); loader.style.visibility = "visible"; } -export function showError(error) { +export function showError(error){ const errors = /** @type {HTMLDivElement} */ (document.querySelector(".error-container")); - errors.insertAdjacentHTML("beforeend", `${error}`) + errors.insertAdjacentHTML("beforeend", `${error}`); } -export function setChallengeInfo(text) { +export function setChallengeInfo(text){ const captcha = /** @type {HTMLDivElement} */ (document.querySelector(".captcha")); captcha.innerText = text; } @@ -25,7 +25,7 @@ export function setChallengeInfo(text) { * * @param {boolean} [failed=false] */ -export function stop(failed = false) { +export function stop(failed = false){ const loader = /** @type {HTMLDivElement} */ (document.querySelector(".circle-loader")); const checkmark = /** @type {HTMLDivElement} */ (document.querySelector(".checkmark")); const cross = /** @type {HTMLDivElement} */ (document.querySelector(".cross")); @@ -36,7 +36,7 @@ export function stop(failed = false) { ? cross.style.display = "block" : checkmark.style.display = "block"; - if (failed) { + if (failed){ return; } @@ -45,7 +45,7 @@ export function stop(failed = false) { countdown--; setChallengeInfo(`Reloading in ${countdown}...`); - if (countdown === 0) { + if (countdown === 0){ clearInterval(interval); window.location.reload(); } diff --git a/web/src/main.js b/web/src/main.js index e8bebdd..863decf 100644 --- a/web/src/main.js +++ b/web/src/main.js @@ -3,8 +3,8 @@ import {doChallenge} from "./challange/challanger"; (() => { - window.addEventListener("DOMContentLoaded", async () => { - if (!navigator.cookieEnabled) { + window.addEventListener("DOMContentLoaded", async() => { + if (!navigator.cookieEnabled){ const noCookie = document.getElementById("no-cookie"); noCookie.style.display = "block"; return;