2020-07-03 08:35:45 +08:00
|
|
|
$(".pageLogin .register input").keyup((e) => {
|
2020-05-10 09:04:05 +08:00
|
|
|
if (e.key == "Enter") {
|
2020-05-15 11:09:00 +08:00
|
|
|
signUp();
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-05-15 03:32:19 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageLogin .register .button").click((e) => {
|
|
|
|
signUp();
|
|
|
|
});
|
2020-05-10 09:04:05 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageLogin .login input").keyup((e) => {
|
2020-05-15 11:09:00 +08:00
|
|
|
if (e.key == "Enter") {
|
|
|
|
signIn();
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-05-13 03:40:16 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageLogin .login .button").click((e) => {
|
2020-05-15 11:09:00 +08:00
|
|
|
signIn();
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-05-15 03:32:19 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".signOut").click((e) => {
|
2020-05-15 11:09:00 +08:00
|
|
|
signOut();
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-05-15 11:09:00 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageAccount .loadMoreButton").click((e) => {
|
2020-05-30 07:21:39 +08:00
|
|
|
loadMoreLines();
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-05-30 07:21:39 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageLogin #forgotPasswordButton").click((e) => {
|
2020-06-10 01:02:03 +08:00
|
|
|
let email = prompt("Email address");
|
2020-07-03 08:35:45 +08:00
|
|
|
if (email) {
|
|
|
|
firebase
|
|
|
|
.auth()
|
|
|
|
.sendPasswordResetEmail(email)
|
|
|
|
.then(function () {
|
|
|
|
// Email sent.
|
|
|
|
showNotification("Email sent", 2000);
|
|
|
|
})
|
|
|
|
.catch(function (error) {
|
|
|
|
// An error happened.
|
|
|
|
showNotification(error.message, 5000);
|
|
|
|
});
|
2020-06-10 01:02:03 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-06-10 01:02:03 +08:00
|
|
|
|
2020-05-15 11:09:00 +08:00
|
|
|
function showSignOutButton() {
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".signOut").removeClass("hidden").css("opacity", 1);
|
2020-05-15 11:09:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function hideSignOutButton() {
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".signOut").css("opacity", 0).addClass("hidden");
|
2020-05-15 11:09:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function signIn() {
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageLogin .preloader").removeClass("hidden");
|
2020-05-15 11:09:00 +08:00
|
|
|
let email = $(".pageLogin .login input")[0].value;
|
|
|
|
let password = $(".pageLogin .login input")[1].value;
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if ($(".pageLogin .login #rememberMe input").prop("checked")) {
|
2020-06-10 01:02:03 +08:00
|
|
|
//remember me
|
2020-07-03 08:35:45 +08:00
|
|
|
firebase
|
|
|
|
.auth()
|
|
|
|
.setPersistence(firebase.auth.Auth.Persistence.LOCAL)
|
|
|
|
.then(function () {
|
|
|
|
return firebase
|
|
|
|
.auth()
|
|
|
|
.signInWithEmailAndPassword(email, password)
|
|
|
|
.then((e) => {
|
|
|
|
changePage("test");
|
|
|
|
})
|
|
|
|
.catch(function (error) {
|
|
|
|
showNotification(error.message, 5000);
|
|
|
|
$(".pageLogin .preloader").addClass("hidden");
|
|
|
|
});
|
2020-06-10 01:02:03 +08:00
|
|
|
});
|
2020-07-03 08:35:45 +08:00
|
|
|
} else {
|
2020-06-10 01:02:03 +08:00
|
|
|
//dont remember
|
2020-07-03 08:35:45 +08:00
|
|
|
firebase
|
|
|
|
.auth()
|
|
|
|
.setPersistence(firebase.auth.Auth.Persistence.SESSION)
|
|
|
|
.then(function () {
|
|
|
|
return firebase
|
|
|
|
.auth()
|
|
|
|
.signInWithEmailAndPassword(email, password)
|
|
|
|
.then((e) => {
|
|
|
|
changePage("test");
|
|
|
|
})
|
|
|
|
.catch(function (error) {
|
|
|
|
showNotification(error.message, 5000);
|
|
|
|
$(".pageLogin .preloader").addClass("hidden");
|
|
|
|
});
|
2020-06-10 01:02:03 +08:00
|
|
|
});
|
|
|
|
}
|
2020-05-15 11:09:00 +08:00
|
|
|
}
|
2020-05-10 09:04:05 +08:00
|
|
|
|
2020-06-28 22:27:52 +08:00
|
|
|
let dontCheckUserName = false;
|
|
|
|
|
2020-05-15 11:09:00 +08:00
|
|
|
function signUp() {
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageLogin .preloader").removeClass("hidden");
|
2020-06-06 23:48:22 +08:00
|
|
|
let nname = $(".pageLogin .register input")[0].value;
|
2020-05-15 11:09:00 +08:00
|
|
|
let email = $(".pageLogin .register input")[1].value;
|
|
|
|
let password = $(".pageLogin .register input")[2].value;
|
|
|
|
let passwordVerify = $(".pageLogin .register input")[3].value;
|
2020-05-10 09:04:05 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
const namecheck = firebase.functions().httpsCallable("checkNameAvailability");
|
2020-05-10 01:39:23 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
namecheck({ name: nname }).then((d) => {
|
|
|
|
if (d.data === -1) {
|
2020-06-06 23:48:22 +08:00
|
|
|
showNotification("Name unavailable", 3000);
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageLogin .preloader").addClass("hidden");
|
2020-06-06 23:48:22 +08:00
|
|
|
return;
|
2020-07-03 08:35:45 +08:00
|
|
|
} else if (d.data === -2) {
|
|
|
|
showNotification(
|
|
|
|
"Name cannot contain special characters or contain more than 12 characters. Can include _ . and -",
|
|
|
|
8000
|
|
|
|
);
|
|
|
|
$(".pageLogin .preloader").addClass("hidden");
|
2020-06-22 06:00:33 +08:00
|
|
|
return;
|
2020-07-03 08:35:45 +08:00
|
|
|
} else if (d.data === 1) {
|
2020-06-06 23:48:22 +08:00
|
|
|
if (password != passwordVerify) {
|
|
|
|
showNotification("Passwords do not match", 3000);
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageLogin .preloader").addClass("hidden");
|
2020-06-06 23:48:22 +08:00
|
|
|
return;
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
firebase
|
|
|
|
.auth()
|
|
|
|
.createUserWithEmailAndPassword(email, password)
|
|
|
|
.then((user) => {
|
|
|
|
// Account has been created here.
|
|
|
|
dontCheckUserName = true;
|
|
|
|
let usr = user.user;
|
|
|
|
usr
|
|
|
|
.updateProfile({
|
|
|
|
displayName: nname,
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
// Update successful.
|
2020-07-04 20:08:37 +08:00
|
|
|
firebase
|
|
|
|
.firestore()
|
|
|
|
.collection("users")
|
|
|
|
.doc(usr.uid)
|
|
|
|
.set({ name: nname }, { merge: true });
|
2020-07-03 08:35:45 +08:00
|
|
|
showNotification("Account created", 2000);
|
|
|
|
$("#menu .icon-button.account .text").text(nname);
|
|
|
|
try {
|
|
|
|
firebase.analytics().logEvent("accountCreated", usr.uid);
|
|
|
|
} catch (e) {
|
|
|
|
console.log("Analytics unavailable");
|
|
|
|
}
|
|
|
|
$(".pageLogin .preloader").addClass("hidden");
|
|
|
|
changePage("account");
|
|
|
|
})
|
|
|
|
.catch(function (error) {
|
|
|
|
// An error happened.
|
2020-07-04 20:08:37 +08:00
|
|
|
console.error(error);
|
2020-07-03 08:35:45 +08:00
|
|
|
usr
|
|
|
|
.delete()
|
|
|
|
.then(function () {
|
|
|
|
// User deleted.
|
2020-07-04 20:08:37 +08:00
|
|
|
showNotification("An error occured", 2000);
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageLogin .preloader").addClass("hidden");
|
|
|
|
})
|
|
|
|
.catch(function (error) {
|
|
|
|
// An error happened.
|
|
|
|
$(".pageLogin .preloader").addClass("hidden");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(function (error) {
|
|
|
|
// Handle Errors here.
|
|
|
|
var errorCode = error.code;
|
|
|
|
var errorMessage = error.message;
|
|
|
|
showNotification(errorMessage, 5000);
|
|
|
|
$(".pageLogin .preloader").addClass("hidden");
|
2020-06-06 23:48:22 +08:00
|
|
|
});
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-05-15 11:09:00 +08:00
|
|
|
}
|
2020-05-10 06:33:48 +08:00
|
|
|
|
|
|
|
function signOut() {
|
2020-07-03 08:35:45 +08:00
|
|
|
firebase
|
|
|
|
.auth()
|
|
|
|
.signOut()
|
|
|
|
.then(function () {
|
|
|
|
showNotification("Signed out", 2000);
|
|
|
|
updateAccountLoginButton();
|
|
|
|
changePage("login");
|
|
|
|
dbSnapshot = null;
|
|
|
|
})
|
|
|
|
.catch(function (error) {
|
|
|
|
showNotification(error.message, 5000);
|
|
|
|
});
|
2020-05-10 06:33:48 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
firebase.auth().onAuthStateChanged(function (user) {
|
2020-05-10 09:04:05 +08:00
|
|
|
if (user) {
|
|
|
|
// User is signed in.
|
2020-06-09 03:01:04 +08:00
|
|
|
updateAccountLoginButton();
|
2020-06-09 03:35:50 +08:00
|
|
|
accountIconLoading(true);
|
2020-07-03 08:35:45 +08:00
|
|
|
db_getUserSnapshot().then((e) => {
|
|
|
|
console.log("DB snapshot ready");
|
2020-06-09 03:35:50 +08:00
|
|
|
accountIconLoading(false);
|
2020-06-12 05:31:06 +08:00
|
|
|
updateFilterTags();
|
2020-06-24 00:46:18 +08:00
|
|
|
updateCommandsTagsList();
|
2020-06-24 01:17:08 +08:00
|
|
|
loadActiveTagsFromCookie();
|
2020-06-24 07:55:15 +08:00
|
|
|
updateResultEditTagsPanelButtons();
|
2020-07-03 08:35:45 +08:00
|
|
|
config.resultFilters.forEach((filter) => {
|
|
|
|
if (filter.substring(0, 4) === "tag_" && filter !== "tag_notag") {
|
2020-06-24 07:55:15 +08:00
|
|
|
toggleFilterButton(filter);
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-06-27 08:23:42 +08:00
|
|
|
refreshTagsSettingsSection();
|
2020-07-07 23:39:48 +08:00
|
|
|
updateDiscordSettingsSection();
|
2020-07-03 08:35:45 +08:00
|
|
|
if (cookieConfig === null) {
|
2020-06-28 06:45:24 +08:00
|
|
|
applyConfig(dbSnapshot.config);
|
|
|
|
// showNotification('Applying db config',3000);
|
|
|
|
updateSettingsPage();
|
|
|
|
saveConfigToCookie();
|
2020-07-04 20:08:37 +08:00
|
|
|
} else if (dbSnapshot.config !== undefined) {
|
2020-06-28 06:45:24 +08:00
|
|
|
let configsDifferent = false;
|
2020-07-03 08:35:45 +08:00
|
|
|
Object.keys(config).forEach((key) => {
|
|
|
|
if (!configsDifferent) {
|
|
|
|
try {
|
|
|
|
if (key !== "resultFilters") {
|
2020-07-03 09:59:57 +08:00
|
|
|
if (Array.isArray(config[key])) {
|
|
|
|
config[key].forEach((arrval, index) => {
|
|
|
|
if (arrval != dbSnapshot.config[key][index])
|
|
|
|
configsDifferent = true;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (config[key] != dbSnapshot.config[key])
|
|
|
|
configsDifferent = true;
|
|
|
|
}
|
2020-06-28 21:51:48 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
} catch (e) {
|
2020-07-03 09:59:57 +08:00
|
|
|
console.log(e);
|
2020-06-28 21:51:48 +08:00
|
|
|
configsDifferent = true;
|
|
|
|
}
|
2020-06-28 06:45:24 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
|
|
|
if (configsDifferent) {
|
2020-06-28 06:45:24 +08:00
|
|
|
applyConfig(dbSnapshot.config);
|
|
|
|
// showNotification('Applying db config',3000);
|
|
|
|
updateSettingsPage();
|
|
|
|
saveConfigToCookie();
|
|
|
|
}
|
|
|
|
}
|
2020-06-09 03:01:04 +08:00
|
|
|
});
|
2020-05-10 09:04:05 +08:00
|
|
|
var displayName = user.displayName;
|
|
|
|
var email = user.email;
|
|
|
|
var emailVerified = user.emailVerified;
|
|
|
|
var photoURL = user.photoURL;
|
|
|
|
var isAnonymous = user.isAnonymous;
|
|
|
|
var uid = user.uid;
|
|
|
|
var providerData = user.providerData;
|
2020-06-09 02:51:13 +08:00
|
|
|
// showNotification('Signed in', 1000);
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageLogin .preloader").addClass("hidden");
|
|
|
|
if (!dontCheckUserName) verifyUsername();
|
2020-07-03 01:39:24 +08:00
|
|
|
$("#menu .icon-button.account .text").text(displayName);
|
2020-05-10 09:04:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var resultHistoryChart = new Chart($(".pageAccount #resultHistoryChart"), {
|
2020-05-20 07:11:57 +08:00
|
|
|
animationSteps: 60,
|
2020-07-03 08:35:45 +08:00
|
|
|
type: "line",
|
2020-05-10 09:04:05 +08:00
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{
|
2020-05-20 07:11:57 +08:00
|
|
|
label: "wpm",
|
2020-05-10 09:04:05 +08:00
|
|
|
fill: false,
|
|
|
|
data: [],
|
2020-07-03 08:35:45 +08:00
|
|
|
borderColor: "#f44336",
|
2020-05-10 09:04:05 +08:00
|
|
|
borderWidth: 2,
|
|
|
|
// trendlineLinear: {
|
|
|
|
// style: "rgba(244,67,54,.25)",
|
|
|
|
// lineStyle: "solid",
|
|
|
|
// width: 1
|
|
|
|
// }
|
2020-05-27 00:51:48 +08:00
|
|
|
trendlineLinear: {
|
|
|
|
style: "rgba(255,105,180, .8)",
|
|
|
|
lineStyle: "dotted",
|
2020-07-03 08:35:45 +08:00
|
|
|
width: 4,
|
|
|
|
},
|
2020-05-10 09:04:05 +08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
options: {
|
2020-05-12 07:59:12 +08:00
|
|
|
tooltips: {
|
2020-05-20 07:11:57 +08:00
|
|
|
// Disable the on-canvas tooltip
|
|
|
|
enabled: true,
|
2020-05-12 07:59:12 +08:00
|
|
|
titleFontFamily: "Roboto Mono",
|
2020-05-20 07:11:57 +08:00
|
|
|
bodyFontFamily: "Roboto Mono",
|
|
|
|
intersect: false,
|
2020-07-03 08:35:45 +08:00
|
|
|
custom: function (tooltip) {
|
2020-05-20 07:11:57 +08:00
|
|
|
if (!tooltip) return;
|
|
|
|
// disable displaying the color box;
|
|
|
|
tooltip.displayColors = false;
|
2020-07-03 08:35:45 +08:00
|
|
|
},
|
|
|
|
callbacks: {
|
|
|
|
// HERE YOU CUSTOMIZE THE LABELS
|
|
|
|
title: function () {
|
2020-05-20 07:11:57 +08:00
|
|
|
return;
|
|
|
|
},
|
2020-07-03 08:35:45 +08:00
|
|
|
beforeLabel: function (tooltipItem, data) {
|
|
|
|
let resultData =
|
|
|
|
data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
|
|
|
|
let label =
|
|
|
|
`${data.datasets[tooltipItem.datasetIndex].label}: ${
|
|
|
|
tooltipItem.yLabel
|
|
|
|
}` +
|
|
|
|
"\n" +
|
|
|
|
`acc: ${resultData.acc}` +
|
|
|
|
"\n\n" +
|
|
|
|
`mode: ${resultData.mode} `;
|
|
|
|
|
|
|
|
if (resultData.mode == "time") {
|
2020-05-20 07:11:57 +08:00
|
|
|
label += resultData.mode2;
|
2020-07-03 08:35:45 +08:00
|
|
|
} else if (resultData.mode == "words") {
|
2020-05-20 07:11:57 +08:00
|
|
|
label += resultData.mode2;
|
|
|
|
}
|
|
|
|
|
2020-05-29 22:58:01 +08:00
|
|
|
let diff = resultData.difficulty;
|
2020-07-03 08:35:45 +08:00
|
|
|
if (diff == undefined) {
|
|
|
|
diff = "normal";
|
2020-05-29 22:58:01 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
label += "\n" + `difficulty: ${diff}`;
|
|
|
|
|
|
|
|
label +=
|
|
|
|
"\n" +
|
|
|
|
`punctuation: ${resultData.punctuation}` +
|
|
|
|
"\n" +
|
|
|
|
`language: ${resultData.language}` +
|
|
|
|
"\n\n" +
|
|
|
|
`date: ${moment(resultData.timestamp).format("DD MMM YYYY HH:mm")}`;
|
|
|
|
|
2020-05-20 07:11:57 +08:00
|
|
|
return label;
|
|
|
|
},
|
2020-07-03 08:35:45 +08:00
|
|
|
label: function (tooltipItem, data) {
|
|
|
|
return;
|
2020-05-20 07:11:57 +08:00
|
|
|
},
|
2020-07-03 08:35:45 +08:00
|
|
|
afterLabel: function (tooltipItem, data) {
|
2020-05-20 07:11:57 +08:00
|
|
|
return;
|
|
|
|
},
|
2020-07-03 08:35:45 +08:00
|
|
|
},
|
2020-05-20 07:11:57 +08:00
|
|
|
},
|
|
|
|
animation: {
|
2020-07-03 08:35:45 +08:00
|
|
|
duration: 250,
|
2020-05-12 07:59:12 +08:00
|
|
|
},
|
2020-05-10 09:04:05 +08:00
|
|
|
legend: {
|
2020-05-27 02:59:26 +08:00
|
|
|
display: false,
|
2020-05-10 09:04:05 +08:00
|
|
|
labels: {
|
2020-05-12 07:59:12 +08:00
|
|
|
fontFamily: "Roboto Mono",
|
2020-07-03 08:35:45 +08:00
|
|
|
fontColor: "#ffffff",
|
|
|
|
},
|
2020-05-10 09:04:05 +08:00
|
|
|
},
|
|
|
|
responsive: true,
|
|
|
|
// maintainAspectRatio: false,
|
|
|
|
// tooltips: {
|
|
|
|
// mode: 'index',
|
|
|
|
// intersect: false,
|
|
|
|
// },
|
|
|
|
hover: {
|
2020-07-03 08:35:45 +08:00
|
|
|
mode: "nearest",
|
|
|
|
intersect: true,
|
2020-05-10 09:04:05 +08:00
|
|
|
},
|
|
|
|
scales: {
|
2020-07-03 08:35:45 +08:00
|
|
|
xAxes: [
|
|
|
|
{
|
|
|
|
ticks: {
|
|
|
|
fontFamily: "Roboto Mono",
|
|
|
|
},
|
|
|
|
type: "time",
|
|
|
|
bounds: "ticks",
|
|
|
|
distribution: "series",
|
|
|
|
display: false,
|
|
|
|
scaleLabel: {
|
|
|
|
display: true,
|
|
|
|
labelString: "Date",
|
|
|
|
},
|
2020-05-12 07:59:12 +08:00
|
|
|
},
|
2020-07-03 08:35:45 +08:00
|
|
|
],
|
|
|
|
yAxes: [
|
|
|
|
{
|
|
|
|
ticks: {
|
|
|
|
fontFamily: "Roboto Mono",
|
|
|
|
beginAtZero: true,
|
|
|
|
},
|
2020-05-10 09:04:05 +08:00
|
|
|
display: true,
|
2020-07-03 08:35:45 +08:00
|
|
|
scaleLabel: {
|
|
|
|
display: false,
|
|
|
|
labelString: "Words per Minute",
|
|
|
|
},
|
2020-05-10 09:04:05 +08:00
|
|
|
},
|
2020-07-03 08:35:45 +08:00
|
|
|
],
|
2020-05-27 00:51:48 +08:00
|
|
|
},
|
2020-07-03 08:35:45 +08:00
|
|
|
},
|
2020-05-10 09:04:05 +08:00
|
|
|
});
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
Object.keys(words).forEach((language) => {
|
|
|
|
$(".pageAccount .content .filterButtons .buttons.languages").append(
|
|
|
|
`<div class="button" filter="${language}">${language.replace(
|
|
|
|
"_",
|
|
|
|
" "
|
|
|
|
)}</div>`
|
|
|
|
);
|
2020-07-09 21:03:21 +08:00
|
|
|
if (language === "english_expanded") {
|
|
|
|
$(".pageAccount .content .filterButtons .buttons.languages").append(
|
|
|
|
`<div class="button" filter="english_10k">english 10k</div>`
|
|
|
|
);
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-05-20 07:11:57 +08:00
|
|
|
|
2020-05-21 23:22:03 +08:00
|
|
|
let activeFilters = ["all"];
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(document).ready((e) => {
|
2020-05-21 23:22:03 +08:00
|
|
|
activeFilters = config.resultFilters;
|
2020-05-31 22:05:41 +08:00
|
|
|
// console.log(activeFilters);
|
2020-07-03 08:35:45 +08:00
|
|
|
if (activeFilters.includes("all")) {
|
|
|
|
toggleFilterButton("all");
|
|
|
|
} else {
|
|
|
|
activeFilters.forEach((filter) => {
|
2020-05-25 04:58:13 +08:00
|
|
|
toggleFilterButton(filter);
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-05-25 04:58:13 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-05-21 23:22:03 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function updateFilterTags() {
|
2020-06-12 05:31:06 +08:00
|
|
|
$(".pageAccount .content .filterButtons .buttons.tags").empty();
|
2020-07-03 08:35:45 +08:00
|
|
|
if (dbSnapshot.tags.length > 0) {
|
|
|
|
$(".pageAccount .content .filterButtons .buttonsAndTitle.tags").removeClass(
|
|
|
|
"hidden"
|
|
|
|
);
|
|
|
|
if (config.resultFilters.includes("tag_notag")) {
|
|
|
|
$(".pageAccount .content .filterButtons .buttons.tags").append(
|
|
|
|
`<div class="button active" filter="tag_notag">no tag</div>`
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$(".pageAccount .content .filterButtons .buttons.tags").append(
|
|
|
|
`<div class="button" filter="tag_notag">no tag</div>`
|
|
|
|
);
|
2020-06-12 05:31:06 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
dbSnapshot.tags.forEach((tag) => {
|
|
|
|
if (config.resultFilters.includes("tag_" + tag.name)) {
|
|
|
|
$(".pageAccount .content .filterButtons .buttons.tags").append(
|
|
|
|
`<div class="button active" filter="tag_${tag.id}">${tag.name}</div>`
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$(".pageAccount .content .filterButtons .buttons.tags").append(
|
|
|
|
`<div class="button" filter="tag_${tag.id}">${tag.name}</div>`
|
|
|
|
);
|
2020-06-12 05:31:06 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$(".pageAccount .content .filterButtons .buttonsAndTitle.tags").addClass(
|
|
|
|
"hidden"
|
|
|
|
);
|
2020-06-12 05:31:06 +08:00
|
|
|
}
|
|
|
|
updateActiveFilters();
|
|
|
|
}
|
2020-05-20 07:11:57 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function toggleFilterButton(filter) {
|
|
|
|
const element = $(
|
|
|
|
`.pageAccount .content .filterButtons .button[filter=${filter}]`
|
|
|
|
);
|
|
|
|
if (element.hasClass("active")) {
|
2020-05-20 07:11:57 +08:00
|
|
|
//disable that filter
|
2020-07-03 08:35:45 +08:00
|
|
|
|
|
|
|
if (filter == "all" || filter == "none") {
|
2020-05-20 07:11:57 +08:00
|
|
|
return;
|
2020-07-03 08:35:45 +08:00
|
|
|
} else if (filter == "mode_words") {
|
2020-05-25 04:58:13 +08:00
|
|
|
// $.each($(`.pageAccount .content .filterButtons .buttons.wordsFilter .button`),(index,obj)=>{
|
|
|
|
// let f = $(obj).attr('filter')
|
|
|
|
// disableFilterButton(f)
|
|
|
|
// })
|
2020-07-03 08:35:45 +08:00
|
|
|
} else if (filter == "mode_time") {
|
2020-05-25 04:58:13 +08:00
|
|
|
// $.each($(`.pageAccount .content .filterButtons .buttons.timeFilter .button`),(index,obj)=>{
|
|
|
|
// let f = $(obj).attr('filter')
|
|
|
|
// disableFilterButton(f)
|
|
|
|
// })
|
2020-07-03 08:35:45 +08:00
|
|
|
} else if (filter == "punc_off") {
|
2020-05-25 04:58:13 +08:00
|
|
|
enableFilterButton("punc_on");
|
2020-07-03 08:35:45 +08:00
|
|
|
} else if (filter == "punc_on") {
|
2020-05-25 04:58:13 +08:00
|
|
|
enableFilterButton("punc_off");
|
2020-05-20 07:11:57 +08:00
|
|
|
}
|
|
|
|
disableFilterButton(filter);
|
2020-07-03 08:35:45 +08:00
|
|
|
disableFilterButton("all");
|
|
|
|
} else {
|
2020-05-20 07:11:57 +08:00
|
|
|
//enable that filter
|
2020-07-03 08:35:45 +08:00
|
|
|
disableFilterButton("none");
|
|
|
|
|
|
|
|
if (filter == "all") {
|
|
|
|
$.each(
|
|
|
|
$(`.pageAccount .content .filterButtons .button`),
|
|
|
|
(index, obj) => {
|
|
|
|
let f = $(obj).attr("filter");
|
|
|
|
if (f != "none") {
|
|
|
|
enableFilterButton(f);
|
|
|
|
}
|
2020-05-20 07:11:57 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
);
|
|
|
|
} else if (filter == "none") {
|
|
|
|
disableFilterButton("all");
|
|
|
|
$.each(
|
|
|
|
$(`.pageAccount .content .filterButtons .button`),
|
|
|
|
(index, obj) => {
|
|
|
|
let f = $(obj).attr("filter");
|
|
|
|
if (f != "none") {
|
|
|
|
disableFilterButton(f);
|
|
|
|
}
|
2020-05-20 07:11:57 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
);
|
2020-05-20 07:11:57 +08:00
|
|
|
}
|
2020-05-25 04:58:13 +08:00
|
|
|
// else if(filter == "mode_words"){
|
|
|
|
// $.each($(`.pageAccount .content .filterButtons .buttons.wordsFilter .button`),(index,obj)=>{
|
|
|
|
// let f = $(obj).attr('filter');
|
|
|
|
// enableFilterButton(f);
|
|
|
|
// })
|
|
|
|
// }else if(filter == "mode_time"){
|
|
|
|
// $.each($(`.pageAccount .content .filterButtons .buttons.timeFilter .button`),(index,obj)=>{
|
|
|
|
// let f = $(obj).attr('filter');
|
|
|
|
// enableFilterButton(f);
|
|
|
|
// })
|
|
|
|
// }else if(['10','25','50','100','200'].includes(filter)){
|
|
|
|
// enableFilterButton('words');
|
|
|
|
// }else if(['15','30','60','120'].includes(filter)){
|
|
|
|
// enableFilterButton('time');
|
|
|
|
// }
|
2020-05-20 07:11:57 +08:00
|
|
|
|
|
|
|
enableFilterButton(filter);
|
|
|
|
}
|
|
|
|
updateActiveFilters();
|
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function disableFilterButton(filter) {
|
|
|
|
const element = $(
|
|
|
|
`.pageAccount .content .filterButtons .button[filter=${filter}]`
|
|
|
|
);
|
|
|
|
element.removeClass("active");
|
2020-05-20 07:11:57 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function enableFilterButton(filter) {
|
|
|
|
const element = $(
|
|
|
|
`.pageAccount .content .filterButtons .button[filter=${filter}]`
|
|
|
|
);
|
|
|
|
element.addClass("active");
|
2020-05-20 07:11:57 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function updateActiveFilters() {
|
2020-05-20 07:11:57 +08:00
|
|
|
activeFilters = [];
|
2020-07-03 08:35:45 +08:00
|
|
|
$.each($(".pageAccount .filterButtons .button"), (i, obj) => {
|
|
|
|
if ($(obj).hasClass("active")) {
|
|
|
|
activeFilters.push($(obj).attr("filter"));
|
2020-05-20 07:11:57 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-05-20 07:11:57 +08:00
|
|
|
refreshAccountPage();
|
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function showChartPreloader() {
|
|
|
|
$(".pageAccount .group.chart .preloader").stop(true, true).animate(
|
|
|
|
{
|
|
|
|
opacity: 1,
|
|
|
|
},
|
|
|
|
125
|
|
|
|
);
|
2020-05-25 04:58:13 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function hideChartPreloader() {
|
|
|
|
$(".pageAccount .group.chart .preloader").stop(true, true).animate(
|
|
|
|
{
|
|
|
|
opacity: 0,
|
|
|
|
},
|
|
|
|
125
|
|
|
|
);
|
2020-05-25 04:58:13 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageAccount .filterButtons").click(".button", (e) => {
|
|
|
|
const filter = $(e.target).attr("filter");
|
2020-05-21 23:22:03 +08:00
|
|
|
toggleFilterButton(filter);
|
|
|
|
config.resultFilters = activeFilters;
|
|
|
|
saveConfigToCookie();
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-05-12 07:59:12 +08:00
|
|
|
|
2020-05-30 07:21:39 +08:00
|
|
|
let filteredResults = [];
|
|
|
|
let visibleTableLines = 0;
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function loadMoreLines() {
|
|
|
|
if (filteredResults == [] || filteredResults.length == 0) return;
|
|
|
|
for (let i = visibleTableLines; i < visibleTableLines + 10; i++) {
|
2020-05-30 07:21:39 +08:00
|
|
|
result = filteredResults[i];
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result == undefined) continue;
|
|
|
|
let withpunc = "";
|
2020-06-24 07:56:55 +08:00
|
|
|
// if (result.punctuation) {
|
|
|
|
// withpunc = '<br>punctuation';
|
|
|
|
// }
|
|
|
|
// if (result.blindMode) {
|
|
|
|
// withpunc = '<br>blind';
|
|
|
|
// }
|
2020-05-30 07:21:39 +08:00
|
|
|
let diff = result.difficulty;
|
2020-07-03 08:35:45 +08:00
|
|
|
if (diff == undefined) {
|
|
|
|
diff = "normal";
|
2020-05-30 07:21:39 +08:00
|
|
|
}
|
2020-05-30 20:59:45 +08:00
|
|
|
|
|
|
|
let raw = result.rawWpm;
|
2020-07-03 08:35:45 +08:00
|
|
|
if (raw == undefined) {
|
|
|
|
raw = "-";
|
2020-05-30 20:59:45 +08:00
|
|
|
}
|
2020-06-24 07:55:15 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
let icons = `<span aria-label="${result.language.replace(
|
|
|
|
"_",
|
|
|
|
" "
|
|
|
|
)}" data-balloon-pos="up"><i class="fas fa-fw fa-globe-americas"></i></span>`;
|
2020-06-24 07:55:15 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if (diff === "normal") {
|
2020-06-24 07:55:15 +08:00
|
|
|
icons += `<span aria-label="${result.difficulty}" data-balloon-pos="up"><i class="far fa-fw fa-star"></i></span>`;
|
2020-07-03 08:35:45 +08:00
|
|
|
} else if (diff === "expert") {
|
2020-06-24 07:55:15 +08:00
|
|
|
icons += `<span aria-label="${result.difficulty}" data-balloon-pos="up"><i class="fas fa-fw fa-star-half-alt"></i></span>`;
|
2020-07-03 08:35:45 +08:00
|
|
|
} else if (diff === "master") {
|
2020-06-24 07:55:15 +08:00
|
|
|
icons += `<span aria-label="${result.difficulty}" data-balloon-pos="up"><i class="fas fa-fw fa-star"></i></span>`;
|
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.punctuation) {
|
2020-06-24 07:55:15 +08:00
|
|
|
icons += `<span aria-label="punctuation" data-balloon-pos="up"><i class="fas fa-fw fa-quote-right"></i></span>`;
|
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.blindMode) {
|
2020-06-24 07:55:15 +08:00
|
|
|
icons += `<span aria-label="blind mode" data-balloon-pos="up"><i class="fas fa-fw fa-eye-slash"></i></span>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
let tagNames = "";
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.tags !== undefined && result.tags.length > 0) {
|
|
|
|
result.tags.forEach((tag) => {
|
|
|
|
dbSnapshot.tags.forEach((snaptag) => {
|
|
|
|
if (tag === snaptag.id) {
|
2020-06-24 07:55:15 +08:00
|
|
|
tagNames += snaptag.name + ", ";
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
|
|
|
});
|
2020-06-24 07:55:15 +08:00
|
|
|
tagNames = tagNames.substring(0, tagNames.length - 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if(tagNames !== ""){
|
|
|
|
// icons += `<span aria-label="${tagNames}" data-balloon-pos="up"><i class="fas fa-fw fa-tag"></i></span>`;
|
|
|
|
// }
|
|
|
|
|
2020-07-01 01:08:17 +08:00
|
|
|
let restags;
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.tags === undefined) {
|
|
|
|
restags = "[]";
|
|
|
|
} else {
|
|
|
|
restags = JSON.stringify(result.tags);
|
2020-07-01 01:08:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
let tagIcons = `<span id="resultEditTags" resultId="${result.id}" tags='${restags}' style="opacity: .25"><i class="fas fa-fw fa-tag"></i></span>`;
|
2020-06-24 07:55:15 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if (tagNames !== "") {
|
|
|
|
if (result.tags !== undefined && result.tags.length > 1) {
|
2020-07-01 01:08:17 +08:00
|
|
|
tagIcons = `<span id="resultEditTags" resultId="${result.id}" tags='${restags}' aria-label="${tagNames}" data-balloon-pos="up"><i class="fas fa-fw fa-tags"></i></span>`;
|
2020-07-03 08:35:45 +08:00
|
|
|
} else {
|
2020-07-01 01:08:17 +08:00
|
|
|
tagIcons = `<span id="resultEditTags" resultId="${result.id}" tags='${restags}' aria-label="${tagNames}" data-balloon-pos="up"><i class="fas fa-fw fa-tag"></i></span>`;
|
2020-06-24 07:55:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 07:21:39 +08:00
|
|
|
$(".pageAccount .history table tbody").append(`
|
|
|
|
<tr>
|
2020-07-08 02:14:49 +08:00
|
|
|
<td>${result.wpm}</td>
|
|
|
|
<td>${raw}</td>
|
|
|
|
<td>${result.acc}%</td>
|
2020-05-30 07:21:39 +08:00
|
|
|
<td>${result.correctChars}</td>
|
|
|
|
<td>${result.incorrectChars}</td>
|
2020-05-31 02:22:11 +08:00
|
|
|
<td>${result.mode} ${result.mode2}${withpunc}</td>
|
2020-06-24 07:55:15 +08:00
|
|
|
<td class="infoIcons">${icons}</td>
|
|
|
|
<td>${tagIcons}</td>
|
2020-07-03 08:35:45 +08:00
|
|
|
<td>${moment(result.timestamp).format("DD MMM YYYY<br>HH:mm")}</td>
|
2020-05-30 07:21:39 +08:00
|
|
|
</tr>`);
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
visibleTableLines += 10;
|
2020-05-30 07:21:39 +08:00
|
|
|
}
|
|
|
|
|
2020-05-10 09:04:05 +08:00
|
|
|
function refreshAccountPage() {
|
2020-07-03 08:35:45 +08:00
|
|
|
function cont() {
|
2020-05-20 07:11:57 +08:00
|
|
|
let chartData = [];
|
2020-05-30 20:59:45 +08:00
|
|
|
visibleTableLines = 0;
|
2020-07-03 08:35:45 +08:00
|
|
|
|
2020-05-10 09:04:05 +08:00
|
|
|
let topWpm = 0;
|
2020-07-03 08:35:45 +08:00
|
|
|
let topMode = "";
|
2020-05-17 20:17:08 +08:00
|
|
|
let testRestarts = 0;
|
2020-05-20 03:27:08 +08:00
|
|
|
let totalWpm = 0;
|
2020-05-20 07:11:57 +08:00
|
|
|
let testCount = 0;
|
2020-05-10 09:04:05 +08:00
|
|
|
|
2020-05-30 04:27:24 +08:00
|
|
|
let last10 = 0;
|
2020-05-20 07:11:57 +08:00
|
|
|
let wpmLast10total = 0;
|
2020-05-30 04:27:24 +08:00
|
|
|
|
|
|
|
let totalAcc = 0;
|
|
|
|
let totalAcc10 = 0;
|
|
|
|
|
2020-05-30 05:37:52 +08:00
|
|
|
let rawWpm = {
|
|
|
|
total: 0,
|
|
|
|
count: 0,
|
|
|
|
last10Total: 0,
|
|
|
|
last10Count: 0,
|
2020-07-03 08:35:45 +08:00
|
|
|
max: 0,
|
|
|
|
};
|
2020-05-30 05:37:52 +08:00
|
|
|
|
2020-05-30 07:21:39 +08:00
|
|
|
let totalSeconds = 0;
|
|
|
|
let totalSecondsFiltered = 0;
|
2020-07-03 08:35:45 +08:00
|
|
|
|
2020-05-30 07:21:39 +08:00
|
|
|
let tableEl = "";
|
|
|
|
|
|
|
|
filteredResults = [];
|
2020-05-12 07:59:12 +08:00
|
|
|
$(".pageAccount .history table tbody").empty();
|
2020-07-03 08:35:45 +08:00
|
|
|
dbSnapshot.results.forEach((result) => {
|
2020-05-30 07:21:39 +08:00
|
|
|
let tt = 0;
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.testDuration == undefined) {
|
2020-06-05 07:01:05 +08:00
|
|
|
//test finished before testDuration field was introduced - estimate
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.mode == "time") {
|
2020-05-30 07:21:39 +08:00
|
|
|
tt = parseFloat(result.mode2);
|
2020-07-03 08:35:45 +08:00
|
|
|
} else if (result.mode == "words") {
|
|
|
|
tt = (parseFloat(result.mode2) / parseFloat(result.wpm)) * 60;
|
2020-05-30 07:21:39 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
} else {
|
2020-06-05 07:01:05 +08:00
|
|
|
tt = parseFloat(result.testDuration);
|
2020-05-30 07:21:39 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.incompleteTestSeconds != undefined) {
|
2020-06-09 01:58:18 +08:00
|
|
|
tt += result.incompleteTestSeconds;
|
2020-07-03 08:35:45 +08:00
|
|
|
} else if (result.restartCount != undefined && result.restartCount > 0) {
|
|
|
|
tt += (tt / 4) * result.restartCount;
|
2020-05-30 07:21:39 +08:00
|
|
|
}
|
|
|
|
totalSeconds += tt;
|
|
|
|
|
2020-05-25 04:58:13 +08:00
|
|
|
// console.log(result);
|
2020-05-20 07:11:57 +08:00
|
|
|
//apply filters
|
2020-05-29 22:58:01 +08:00
|
|
|
let resdiff = result.difficulty;
|
2020-07-03 08:35:45 +08:00
|
|
|
if (resdiff == undefined) {
|
2020-05-29 22:58:01 +08:00
|
|
|
resdiff = "normal";
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
if (!activeFilters.includes("difficulty_" + resdiff)) return;
|
|
|
|
if (!activeFilters.includes("mode_" + result.mode)) return;
|
|
|
|
if (result.mode == "time") {
|
2020-05-25 04:58:13 +08:00
|
|
|
let timefilter = "time_custom";
|
2020-07-03 08:35:45 +08:00
|
|
|
if ([15, 30, 60, 120].includes(parseInt(result.mode2))) {
|
|
|
|
timefilter = "time_" + result.mode2;
|
2020-05-25 04:58:13 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
if (!activeFilters.includes(timefilter)) return;
|
|
|
|
} else if (result.mode == "words") {
|
2020-05-25 04:58:13 +08:00
|
|
|
let wordfilter = "words_custom";
|
2020-07-03 08:35:45 +08:00
|
|
|
if ([10, 25, 50, 100, 200].includes(parseInt(result.mode2))) {
|
|
|
|
wordfilter = "words_" + result.mode2;
|
2020-05-25 04:58:13 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
if (!activeFilters.includes(wordfilter)) return;
|
2020-05-20 07:11:57 +08:00
|
|
|
}
|
2020-05-25 04:58:13 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if (!activeFilters.includes(result.language)) return;
|
2020-05-25 04:58:13 +08:00
|
|
|
|
|
|
|
let puncfilter = "punc_off";
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.punctuation) {
|
2020-05-25 04:58:13 +08:00
|
|
|
puncfilter = "punc_on";
|
2020-05-20 07:11:57 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
if (!activeFilters.includes(puncfilter)) return;
|
2020-05-20 07:11:57 +08:00
|
|
|
|
2020-06-15 01:19:12 +08:00
|
|
|
//check if the user has any tags defined
|
2020-07-03 08:35:45 +08:00
|
|
|
if (dbSnapshot.tags.length > 0) {
|
2020-06-15 01:19:12 +08:00
|
|
|
//check if that result has any tags
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.tags !== undefined && result.tags.length > 0) {
|
2020-06-12 05:31:06 +08:00
|
|
|
let found = false;
|
2020-07-03 08:35:45 +08:00
|
|
|
result.tags.forEach((tag) => {
|
2020-06-15 01:19:12 +08:00
|
|
|
//check if any of the tags inside the result are active
|
2020-07-03 08:35:45 +08:00
|
|
|
if (activeFilters.includes("tag_" + tag)) found = true;
|
2020-06-15 01:19:12 +08:00
|
|
|
//check if a tag doesnt exist and tag_notag is active
|
2020-07-03 08:35:45 +08:00
|
|
|
if (
|
|
|
|
!dbSnapshot.tags.map((t) => t.id).includes(tag) &&
|
|
|
|
activeFilters.includes("tag_notag")
|
|
|
|
)
|
|
|
|
found = true;
|
|
|
|
});
|
|
|
|
if (!found) return;
|
|
|
|
} else {
|
|
|
|
if (!activeFilters.includes("tag_notag")) return;
|
2020-06-12 05:31:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-22 07:43:38 +08:00
|
|
|
let timeSinceTest = Math.abs(result.timestamp - Date.now()) / 1000;
|
|
|
|
|
|
|
|
let datehide = true;
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if (
|
|
|
|
activeFilters.includes("date_all") ||
|
2020-06-22 07:43:38 +08:00
|
|
|
(activeFilters.includes("date_day") && timeSinceTest <= 86400) ||
|
|
|
|
(activeFilters.includes("date_week") && timeSinceTest <= 604800) ||
|
|
|
|
(activeFilters.includes("date_month") && timeSinceTest <= 18144000)
|
2020-07-03 08:35:45 +08:00
|
|
|
) {
|
2020-06-22 07:43:38 +08:00
|
|
|
datehide = false;
|
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if (datehide) return;
|
2020-06-22 07:43:38 +08:00
|
|
|
|
|
|
|
// if(
|
|
|
|
// (!activeFilters.includes("date_all")) &&
|
|
|
|
// (activeFilters.includes("date_day") && timeSinceTest > 86400) &&
|
|
|
|
// (activeFilters.includes("date_week") && timeSinceTest > 604800) &&
|
|
|
|
// (activeFilters.includes("date_month") && timeSinceTest > 18144000)
|
|
|
|
// ){
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
2020-05-30 07:21:39 +08:00
|
|
|
filteredResults.push(result);
|
|
|
|
|
|
|
|
//filters done
|
2020-06-22 07:43:38 +08:00
|
|
|
//=======================================
|
2020-05-30 07:21:39 +08:00
|
|
|
|
|
|
|
tt = 0;
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.timeDuration == null) {
|
2020-05-30 07:21:39 +08:00
|
|
|
//test finished before timeduration field was introduced - estimate
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.mode == "time") {
|
2020-05-30 07:21:39 +08:00
|
|
|
tt = parseFloat(result.mode2);
|
2020-07-03 08:35:45 +08:00
|
|
|
} else if (result.mode == "words") {
|
|
|
|
tt = (parseFloat(result.mode2) / parseFloat(result.wpm)) * 60;
|
2020-05-30 07:21:39 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
} else {
|
2020-05-30 07:21:39 +08:00
|
|
|
tt = parseFloat(result.timeDuration);
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.restartCount != null) {
|
|
|
|
tt += (tt / 4) * result.restartCount;
|
2020-05-30 07:21:39 +08:00
|
|
|
}
|
|
|
|
totalSecondsFiltered += tt;
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if (last10 < 10) {
|
2020-05-30 04:27:24 +08:00
|
|
|
last10++;
|
2020-05-20 07:11:57 +08:00
|
|
|
wpmLast10total += result.wpm;
|
2020-05-30 04:27:24 +08:00
|
|
|
totalAcc10 += result.acc;
|
2020-05-20 07:11:57 +08:00
|
|
|
}
|
|
|
|
testCount++;
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.rawWpm != null) {
|
|
|
|
if (rawWpm.last10Count < 10) {
|
2020-05-30 05:37:52 +08:00
|
|
|
rawWpm.last10Count++;
|
|
|
|
rawWpm.last10Total += result.rawWpm;
|
|
|
|
}
|
|
|
|
rawWpm.total += result.rawWpm;
|
|
|
|
rawWpm.count++;
|
2020-07-03 08:35:45 +08:00
|
|
|
if (result.rawWpm > rawWpm.max) {
|
2020-05-30 05:37:52 +08:00
|
|
|
rawWpm.max = result.rawWpm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 04:27:24 +08:00
|
|
|
totalAcc += result.acc;
|
2020-05-20 07:11:57 +08:00
|
|
|
|
2020-05-17 20:17:08 +08:00
|
|
|
if (result.restartCount != undefined) {
|
|
|
|
testRestarts += result.restartCount;
|
|
|
|
}
|
2020-05-30 07:21:39 +08:00
|
|
|
|
2020-05-20 07:11:57 +08:00
|
|
|
chartData.push({
|
|
|
|
x: result.timestamp,
|
|
|
|
y: result.wpm,
|
|
|
|
acc: result.acc,
|
|
|
|
mode: result.mode,
|
|
|
|
mode2: result.mode2,
|
|
|
|
punctuation: result.punctuation,
|
|
|
|
language: result.language,
|
2020-05-29 22:58:01 +08:00
|
|
|
timestamp: result.timestamp,
|
2020-07-03 08:35:45 +08:00
|
|
|
difficulty: result.difficulty,
|
2020-05-20 07:11:57 +08:00
|
|
|
});
|
2020-05-10 09:04:05 +08:00
|
|
|
|
|
|
|
if (result.wpm > topWpm) {
|
2020-05-11 23:29:18 +08:00
|
|
|
let puncsctring = result.punctuation ? ",<br>with punctuation" : "";
|
2020-05-10 09:04:05 +08:00
|
|
|
topWpm = result.wpm;
|
2020-05-11 07:07:36 +08:00
|
|
|
topMode = result.mode + " " + result.mode2 + puncsctring;
|
2020-05-10 09:04:05 +08:00
|
|
|
}
|
2020-05-20 03:27:08 +08:00
|
|
|
|
|
|
|
totalWpm += result.wpm;
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-05-30 07:21:39 +08:00
|
|
|
loadMoreLines();
|
2020-05-20 07:11:57 +08:00
|
|
|
////////
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
let mainColor = getComputedStyle(document.body)
|
|
|
|
.getPropertyValue("--main-color")
|
|
|
|
.replace(" ", "");
|
|
|
|
let subColor = getComputedStyle(document.body)
|
|
|
|
.getPropertyValue("--sub-color")
|
|
|
|
.replace(" ", "");
|
|
|
|
|
2020-05-12 07:59:12 +08:00
|
|
|
resultHistoryChart.options.scales.xAxes[0].ticks.minor.fontColor = subColor;
|
|
|
|
resultHistoryChart.options.scales.yAxes[0].ticks.minor.fontColor = subColor;
|
2020-05-20 07:11:57 +08:00
|
|
|
resultHistoryChart.data.datasets[0].borderColor = mainColor;
|
2020-05-12 07:59:12 +08:00
|
|
|
resultHistoryChart.options.legend.labels.fontColor = subColor;
|
2020-05-27 00:51:48 +08:00
|
|
|
resultHistoryChart.data.datasets[0].trendlineLinear.style = subColor;
|
2020-05-12 07:59:12 +08:00
|
|
|
|
2020-05-20 07:11:57 +08:00
|
|
|
resultHistoryChart.data.datasets[0].data = chartData;
|
2020-05-10 09:04:05 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if (chartData == [] || chartData.length == 0) {
|
|
|
|
$(".pageAccount .group.noDataError").removeClass("hidden");
|
|
|
|
$(".pageAccount .group.chart").addClass("hidden");
|
|
|
|
$(".pageAccount .group.history").addClass("hidden");
|
|
|
|
$(".pageAccount .triplegroup.stats").addClass("hidden");
|
|
|
|
} else {
|
|
|
|
$(".pageAccount .group.noDataError").addClass("hidden");
|
|
|
|
$(".pageAccount .group.chart").removeClass("hidden");
|
|
|
|
$(".pageAccount .group.history").removeClass("hidden");
|
|
|
|
$(".pageAccount .triplegroup.stats").removeClass("hidden");
|
2020-05-27 00:51:48 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageAccount .timeTotal .val").text(
|
|
|
|
moment
|
|
|
|
.utc(moment.duration(totalSeconds, "seconds").asMilliseconds())
|
|
|
|
.format("HH:mm:ss")
|
|
|
|
);
|
|
|
|
$(".pageAccount .timeTotalFiltered .val").text(
|
|
|
|
moment
|
|
|
|
.utc(moment.duration(totalSecondsFiltered, "seconds").asMilliseconds())
|
|
|
|
.format("HH:mm:ss")
|
|
|
|
);
|
2020-05-30 07:21:39 +08:00
|
|
|
|
2020-05-10 09:04:05 +08:00
|
|
|
$(".pageAccount .highestWpm .val").text(topWpm);
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageAccount .averageWpm .val").text(Math.round(totalWpm / testCount));
|
|
|
|
$(".pageAccount .averageWpm10 .val").text(
|
|
|
|
Math.round(wpmLast10total / last10)
|
|
|
|
);
|
2020-05-30 05:37:52 +08:00
|
|
|
|
|
|
|
$(".pageAccount .highestRaw .val").text(rawWpm.max);
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageAccount .averageRaw .val").text(
|
|
|
|
Math.round(rawWpm.total / rawWpm.count)
|
|
|
|
);
|
|
|
|
$(".pageAccount .averageRaw10 .val").text(
|
|
|
|
Math.round(rawWpm.last10Total / rawWpm.last10Count)
|
|
|
|
);
|
2020-05-30 05:37:52 +08:00
|
|
|
|
2020-05-11 07:07:36 +08:00
|
|
|
$(".pageAccount .highestWpm .mode").html(topMode);
|
2020-05-10 09:04:05 +08:00
|
|
|
$(".pageAccount .testsTaken .val").text(testCount);
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageAccount .avgAcc .val").text(Math.round(totalAcc / testCount) + "%");
|
|
|
|
$(".pageAccount .avgAcc10 .val").text(
|
|
|
|
Math.round(totalAcc10 / last10) + "%"
|
2020-05-20 07:11:57 +08:00
|
|
|
);
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(".pageAccount .testsStarted .val").text(`${testCount + testRestarts}`);
|
|
|
|
|
2020-05-20 07:11:57 +08:00
|
|
|
$(".pageAccount .testsCompleted .val").text(
|
2020-07-03 08:35:45 +08:00
|
|
|
`${testCount}(${Math.floor(
|
|
|
|
(testCount / (testCount + testRestarts)) * 100
|
|
|
|
)}%)`
|
2020-05-17 20:17:08 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
$(".pageAccount .avgRestart .val").text(
|
2020-07-03 08:35:45 +08:00
|
|
|
(testRestarts / testCount).toFixed(1)
|
2020-05-17 20:17:08 +08:00
|
|
|
);
|
|
|
|
|
2020-05-20 07:11:57 +08:00
|
|
|
// if(testCount == 0){
|
|
|
|
// $('.pageAccount .group.chart').fadeOut(125);
|
|
|
|
// $('.pageAccount .triplegroup.stats').fadeOut(125);
|
|
|
|
// $('.pageAccount .group.history').fadeOut(125);
|
|
|
|
// }else{
|
|
|
|
// $('.pageAccount .group.chart').fadeIn(125);
|
|
|
|
// $('.pageAccount .triplegroup.stats').fadeIn(125);
|
|
|
|
// $('.pageAccount .group.history').fadeIn(125);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// let favMode = testModes.words10;
|
|
|
|
// let favModeName = 'words10';
|
|
|
|
// $.each(testModes, (key, mode) => {
|
|
|
|
// if (mode.length > favMode.length) {
|
|
|
|
// favMode = mode;
|
|
|
|
// favModeName = key;
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// if (favModeName == 'words10' && testModes.words10.length == 0) {
|
2020-07-03 08:35:45 +08:00
|
|
|
// //new user
|
2020-05-20 07:11:57 +08:00
|
|
|
// $(".pageAccount .favouriteTest .val").text(`-`);
|
|
|
|
// } else {
|
|
|
|
// $(".pageAccount .favouriteTest .val").text(`${favModeName} (${Math.floor((favMode.length/testCount) * 100)}%)`);
|
|
|
|
// }
|
2020-05-10 09:04:05 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
if (resultHistoryChart.data.datasets[0].length > 0) {
|
2020-05-27 00:51:48 +08:00
|
|
|
resultHistoryChart.options.plugins.trendlineLinear = true;
|
2020-07-03 08:35:45 +08:00
|
|
|
} else {
|
2020-05-27 00:51:48 +08:00
|
|
|
resultHistoryChart.options.plugins.trendlineLinear = false;
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
|
|
|
|
resultHistoryChart.update({ duration: 0 });
|
|
|
|
|
2020-05-12 07:59:12 +08:00
|
|
|
swapElements($(".pageAccount .preloader"), $(".pageAccount .content"), 250);
|
|
|
|
}
|
2020-05-10 09:04:05 +08:00
|
|
|
|
2020-06-09 03:12:01 +08:00
|
|
|
if (dbSnapshot === null) {
|
2020-05-15 09:57:57 +08:00
|
|
|
// console.log('no db snap');
|
2020-06-08 09:24:50 +08:00
|
|
|
// db_getUserResults().then(data => {
|
|
|
|
// if(!data) return;
|
|
|
|
// dbSnapshot = data;
|
|
|
|
// cont();
|
|
|
|
// })
|
2020-05-12 07:59:12 +08:00
|
|
|
} else {
|
2020-05-15 09:57:57 +08:00
|
|
|
// console.log('using db snap');
|
2020-05-12 07:59:12 +08:00
|
|
|
cont();
|
|
|
|
}
|
2020-05-20 07:11:57 +08:00
|
|
|
}
|
2020-06-24 07:55:15 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function showResultEditTagsPanel() {
|
2020-06-24 07:55:15 +08:00
|
|
|
if ($("#resultEditTagsPanelWrapper").hasClass("hidden")) {
|
|
|
|
$("#resultEditTagsPanelWrapper")
|
2020-07-03 08:35:45 +08:00
|
|
|
.stop(true, true)
|
|
|
|
.css("opacity", 0)
|
|
|
|
.removeClass("hidden")
|
|
|
|
.animate({ opacity: 1 }, 125);
|
2020-06-24 07:55:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function hideResultEditTagsPanel() {
|
2020-06-24 07:55:15 +08:00
|
|
|
if (!$("#resultEditTagsPanelWrapper").hasClass("hidden")) {
|
|
|
|
$("#resultEditTagsPanelWrapper")
|
2020-07-03 08:35:45 +08:00
|
|
|
.stop(true, true)
|
|
|
|
.css("opacity", 1)
|
|
|
|
.animate(
|
2020-06-24 07:55:15 +08:00
|
|
|
{
|
2020-07-03 08:35:45 +08:00
|
|
|
opacity: 0,
|
|
|
|
},
|
|
|
|
100,
|
|
|
|
(e) => {
|
|
|
|
$("#resultEditTagsPanelWrapper").addClass("hidden");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-06-24 07:55:15 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(document).on("click", ".pageAccount .group.history #resultEditTags", (f) => {
|
|
|
|
if (dbSnapshot.tags.length > 0) {
|
|
|
|
let resultid = $(f.target).parents("span").attr("resultid");
|
|
|
|
let tags = $(f.target).parents("span").attr("tags");
|
|
|
|
$("#resultEditTagsPanel").attr("resultid", resultid);
|
|
|
|
$("#resultEditTagsPanel").attr("tags", tags);
|
2020-06-25 04:19:14 +08:00
|
|
|
updateActiveResultEditTagsPanelButtons(JSON.parse(tags));
|
|
|
|
showResultEditTagsPanel();
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-06-24 07:55:15 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(document).on("click", "#resultEditTagsPanelWrapper .button.tag", (f) => {
|
|
|
|
$(f.target).toggleClass("active");
|
|
|
|
});
|
2020-06-24 07:55:15 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$("#resultEditTagsPanelWrapper").click((e) => {
|
|
|
|
if ($(e.target).attr("id") === "resultEditTagsPanelWrapper") {
|
2020-06-24 07:55:15 +08:00
|
|
|
hideResultEditTagsPanel();
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-06-24 07:55:15 +08:00
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function updateResultEditTagsPanelButtons() {
|
2020-06-24 07:55:15 +08:00
|
|
|
$("#resultEditTagsPanel .buttons").empty();
|
2020-07-03 08:35:45 +08:00
|
|
|
dbSnapshot.tags.forEach((tag) => {
|
|
|
|
$("#resultEditTagsPanel .buttons").append(
|
|
|
|
`<div class="button tag" tagid="${tag.id}">${tag.name}</div>`
|
|
|
|
);
|
|
|
|
});
|
2020-06-24 07:55:15 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function updateActiveResultEditTagsPanelButtons(active) {
|
|
|
|
if (active === []) return;
|
|
|
|
$.each($("#resultEditTagsPanel .buttons .button"), (index, obj) => {
|
|
|
|
let tagid = $(obj).attr("tagid");
|
|
|
|
if (active.includes(tagid)) {
|
|
|
|
$(obj).addClass("active");
|
|
|
|
} else {
|
|
|
|
$(obj).removeClass("active");
|
2020-06-24 07:55:15 +08:00
|
|
|
}
|
|
|
|
// active.forEach(activetagid => {
|
|
|
|
// if(activetagid === tagid){
|
|
|
|
// $(obj).addClass('active');
|
|
|
|
// }else{
|
|
|
|
// $(obj).removeClass('active');
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$("#resultEditTagsPanel .confirmButton").click((f) => {
|
|
|
|
let resultid = $("#resultEditTagsPanel").attr("resultid");
|
|
|
|
let oldtags = JSON.parse($("#resultEditTagsPanel").attr("tags"));
|
2020-06-24 07:55:15 +08:00
|
|
|
|
|
|
|
let newtags = [];
|
2020-07-03 08:35:45 +08:00
|
|
|
$.each($("#resultEditTagsPanel .buttons .button"), (index, obj) => {
|
|
|
|
let tagid = $(obj).attr("tagid");
|
|
|
|
if ($(obj).hasClass("active")) {
|
2020-06-24 07:55:15 +08:00
|
|
|
newtags.push(tagid);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
showBackgroundLoader();
|
|
|
|
hideResultEditTagsPanel();
|
2020-07-03 08:35:45 +08:00
|
|
|
updateResultTags({
|
|
|
|
uid: firebase.auth().currentUser.uid,
|
|
|
|
tags: newtags,
|
|
|
|
resultid: resultid,
|
|
|
|
}).then((r) => {
|
2020-06-24 07:55:15 +08:00
|
|
|
hideBackgroundLoader();
|
2020-07-03 08:35:45 +08:00
|
|
|
if (r.data.resultCode === 1) {
|
|
|
|
showNotification("Tags updated", 1000);
|
|
|
|
dbSnapshot.results.forEach((result) => {
|
|
|
|
if (result.id === resultid) {
|
2020-06-24 07:55:15 +08:00
|
|
|
result.tags = newtags;
|
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
2020-06-24 07:55:15 +08:00
|
|
|
refreshAccountPage();
|
2020-07-03 08:35:45 +08:00
|
|
|
} else {
|
|
|
|
showNotification("Error updating tags", 3000);
|
2020-06-24 07:55:15 +08:00
|
|
|
}
|
|
|
|
});
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|