mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-08 05:03:39 +08:00
removed the window.navigator.online check as it is not trustable
This commit is contained in:
parent
71663fc277
commit
18245f84a9
1 changed files with 90 additions and 95 deletions
|
|
@ -1791,105 +1791,100 @@ export async function finish(difficultyFailed = false) {
|
|||
// `checking <i class="fas fa-spin fa-fw fa-circle-notch"></i>`
|
||||
// );
|
||||
}
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue