Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fionera committed Nov 15, 2023
1 parent 9f47e13 commit 72f2e0b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
16 changes: 8 additions & 8 deletions web/src/challange/challanger.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as loader from "./loader.js";
*
* @return {Promise<object>}
*/
async function getChallenge() {
async function getChallenge(){
const resp = await fetch("/cdn-cgi/challenge-platform/challenge");
return await resp.json();
}
Expand All @@ -20,30 +20,30 @@ async function getChallenge() {
*
* @return {Promise<void>}
*/
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);
}

}
18 changes: 9 additions & 9 deletions web/src/challange/challanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {isCanvasSupported, isNotHeadless, isUsualBrowserBasedOnUa} from "./fing
* @param {AlgorithmIdentifier} method
* @return {Promise<string>}
*/
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("");
Expand All @@ -23,13 +23,13 @@ async function nativeHash(data, method) {
* @param {object} challenge
* @return {Promise<void>}
*/
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;
}
}
Expand All @@ -45,7 +45,7 @@ async function challengePOW(challenge) {
*
* @return {Promise<string>}
*/
async function challengeFingerprinting() {
async function challengeFingerprinting(){
const usualUa = isUsualBrowserBasedOnUa();
if (!usualUa) return "ua";

Expand All @@ -63,14 +63,14 @@ async function challengeFingerprinting() {
*
* @return {Promise<void>}
*/
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:
Expand All @@ -80,4 +80,4 @@ export function getChallengeSolver(challengeType) {
default:
throw new Error(`Unknown challenge type: ${challengeType}`);
}
}
}
6 changes: 3 additions & 3 deletions web/src/challange/fingerprinting.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @return {boolean}
*/
export function isUsualBrowserBasedOnUa() {
export function isUsualBrowserBasedOnUa(){
const ua = navigator.userAgent;
const isUsualBrowser = ua.includes("Chrome")
|| ua.includes("Firefox")
Expand All @@ -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
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions web/src/challange/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", `<code>${error}</code>`)
errors.insertAdjacentHTML("beforeend", `<code>${error}</code>`);
}

export function setChallengeInfo(text) {
export function setChallengeInfo(text){
const captcha = /** @type {HTMLDivElement} */ (document.querySelector(".captcha"));
captcha.innerText = text;
}
Expand All @@ -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"));
Expand All @@ -36,7 +36,7 @@ export function stop(failed = false) {
? cross.style.display = "block"
: checkmark.style.display = "block";

if (failed) {
if (failed){
return;
}

Expand All @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions web/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 72f2e0b

Please sign in to comment.