From 18245f84a938fbc7a96f9d5e33e092724d812d5c Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 1 Sep 2021 00:01:36 +0100 Subject: [PATCH] removed the window.navigator.online check as it is not trustable --- src/js/test/test-logic.js | 185 +++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 95 deletions(-) diff --git a/src/js/test/test-logic.js b/src/js/test/test-logic.js index 35f2bd264..e1adc1582 100644 --- a/src/js/test/test-logic.js +++ b/src/js/test/test-logic.js @@ -1791,105 +1791,100 @@ export async function finish(difficultyFailed = false) { // `checking ` // ); } - if (!window.navigator.onLine) { - AccountButton.loading(false); - Notifications.add("You are offline. Result not saved.", -1); - } else { - completedEvent.challenge = ChallengeContoller.verify( - completedEvent - ); - completedEvent.hash = objecthash(completedEvent); - axiosInstance - .post("/results/add", { - result: completedEvent, - }) - .then((response) => { - AccountButton.loading(false); + completedEvent.challenge = ChallengeContoller.verify( + completedEvent + ); + completedEvent.hash = objecthash(completedEvent); + axiosInstance + .post("/results/add", { + result: completedEvent, + }) + .then((response) => { + AccountButton.loading(false); - if (response.status !== 200) { - Notifications.add( - "Result not saved. " + response.data.message, - -1 - ); - } else { - completedEvent._id = response.data.insertedId; - // TODO bring back after leaderboard fixed - // TestLeaderboards.check(completedEvent); - if (response.data.isPb) { - completedEvent.isPb = true; - } - if ( - DB.getSnapshot() !== null && - DB.getSnapshot().results !== undefined - ) { - DB.getSnapshot().results.unshift(completedEvent); - if (DB.getSnapshot().globalStats.time == undefined) { - DB.getSnapshot().globalStats.time = - testtime + - completedEvent.incompleteTestSeconds - - afkseconds; - } else { - DB.getSnapshot().globalStats.time += - testtime + - completedEvent.incompleteTestSeconds - - afkseconds; - } - if (DB.getSnapshot().globalStats.started == undefined) { - DB.getSnapshot().globalStats.started = - TestStats.restartCount + 1; - } else { - DB.getSnapshot().globalStats.started += - TestStats.restartCount + 1; - } - if (DB.getSnapshot().globalStats.completed == undefined) { - DB.getSnapshot().globalStats.completed = 1; - } else { - DB.getSnapshot().globalStats.completed += 1; - } - } - try { - firebase - .analytics() - .logEvent("testCompleted", completedEvent); - } catch (e) { - console.log("Analytics unavailable"); - } - - if (response.data.isPb) { - //new pb - PbCrown.show(); - $("#result .stats .wpm .crown").attr( - "aria-label", - "+" + Misc.roundTo2(pbDiff) - ); - DB.saveLocalPB( - Config.mode, - mode2, - Config.punctuation, - Config.language, - Config.difficulty, - stats.wpm, - stats.acc, - stats.wpmRaw, - consistency - ); + if (response.status !== 200) { + Notifications.add( + "Result not saved. " + response.data.message, + -1 + ); + } else { + completedEvent._id = response.data.insertedId; + // TODO bring back after leaderboard fixed + // TestLeaderboards.check(completedEvent); + if (response.data.isPb) { + completedEvent.isPb = true; + } + if ( + DB.getSnapshot() !== null && + DB.getSnapshot().results !== undefined + ) { + DB.getSnapshot().results.unshift(completedEvent); + if (DB.getSnapshot().globalStats.time == undefined) { + DB.getSnapshot().globalStats.time = + testtime + + completedEvent.incompleteTestSeconds - + afkseconds; } else { - PbCrown.hide(); - // if (localPb) { - // Notifications.add( - // "Local PB data is out of sync! Refresh the page to resync it or contact Miodec on Discord.", - // 15000 - // ); - // } + DB.getSnapshot().globalStats.time += + testtime + + completedEvent.incompleteTestSeconds - + afkseconds; + } + if (DB.getSnapshot().globalStats.started == undefined) { + DB.getSnapshot().globalStats.started = + TestStats.restartCount + 1; + } else { + DB.getSnapshot().globalStats.started += + TestStats.restartCount + 1; + } + if (DB.getSnapshot().globalStats.completed == undefined) { + DB.getSnapshot().globalStats.completed = 1; + } else { + DB.getSnapshot().globalStats.completed += 1; } } - }) - .catch((e) => { - AccountButton.loading(false); - let msg = e?.response?.data?.message ?? e.message; - Notifications.add("Failed to save result: " + msg, -1); - }); - } + try { + firebase + .analytics() + .logEvent("testCompleted", completedEvent); + } catch (e) { + console.log("Analytics unavailable"); + } + + if (response.data.isPb) { + //new pb + PbCrown.show(); + $("#result .stats .wpm .crown").attr( + "aria-label", + "+" + Misc.roundTo2(pbDiff) + ); + DB.saveLocalPB( + Config.mode, + mode2, + Config.punctuation, + Config.language, + Config.difficulty, + stats.wpm, + stats.acc, + stats.wpmRaw, + consistency + ); + } else { + PbCrown.hide(); + // if (localPb) { + // Notifications.add( + // "Local PB data is out of sync! Refresh the page to resync it or contact Miodec on Discord.", + // 15000 + // ); + // } + } + } + }) + .catch((e) => { + AccountButton.loading(false); + let msg = e?.response?.data?.message ?? e.message; + Notifications.add("Failed to save result: " + msg, -1); + }); }); }); } else {