mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-10 07:36:09 +08:00
moved account to a module. part of #495
This commit is contained in:
parent
806846e55b
commit
27fff39cc3
15 changed files with 1143 additions and 1151 deletions
|
@ -90,7 +90,6 @@ const refactoredSrc = [
|
|||
"./src/js/cloud-functions.js",
|
||||
"./src/js/misc.js",
|
||||
"./src/js/layouts.js",
|
||||
"./src/js/result-filters.js",
|
||||
"./src/js/sound.js",
|
||||
"./src/js/theme-colors.js",
|
||||
"./src/js/chart-controller.js",
|
||||
|
@ -108,11 +107,15 @@ const refactoredSrc = [
|
|||
"./src/js/settings.js",
|
||||
|
||||
"./src/js/account/all-time-stats.js",
|
||||
"./src/js/account/pb-tables.js",
|
||||
"./src/js/account/result-filters.js",
|
||||
"./src/js/account/verification-controller.js",
|
||||
"./src/js/account.js",
|
||||
|
||||
"./src/js/elements/monkey.js",
|
||||
"./src/js/elements/notifications.js",
|
||||
"./src/js/elements/leaderboards.js",
|
||||
"./src/js/elements/account-icon.js",
|
||||
"./src/js/elements/account-button.js",
|
||||
"./src/js/elements/loader.js",
|
||||
"./src/js/elements/sign-out-button.js",
|
||||
|
||||
|
@ -160,7 +163,6 @@ const refactoredSrc = [
|
|||
//the order of files is important
|
||||
const globalSrc = [
|
||||
"./src/js/global-dependencies.js",
|
||||
"./src/js/account.js",
|
||||
"./src/js/script.js",
|
||||
"./src/js/exports.js",
|
||||
];
|
||||
|
|
|
@ -1,4 +1,18 @@
|
|||
import * as Notifications from "./notifications";
|
||||
import * as UpdateConfig from "./config";
|
||||
import * as AccountButton from "./account-button";
|
||||
import * as Account from "./account";
|
||||
import * as CommandlineLists from "./commandline-lists";
|
||||
import * as VerificationController from "./verification-controller";
|
||||
import * as Misc from "./misc";
|
||||
import * as Settings from "./settings";
|
||||
import * as ChallengeController from "./challenge-controller";
|
||||
import Config from "./config";
|
||||
import * as CloudFunctions from "./cloud-functions";
|
||||
import * as AllTimeStats from "./all-time-stats";
|
||||
import * as DB from "./db";
|
||||
import * as TestLogic from "./test-logic";
|
||||
import * as UI from "./ui";
|
||||
|
||||
var gmailProvider = new firebase.auth.GoogleAuthProvider();
|
||||
|
||||
|
@ -17,7 +31,7 @@ export function signIn() {
|
|||
.auth()
|
||||
.signInWithEmailAndPassword(email, password)
|
||||
.then((e) => {
|
||||
// changePage("test");
|
||||
// UI.changePage("test");
|
||||
})
|
||||
.catch(function (error) {
|
||||
Notifications.add(error.message, -1);
|
||||
|
@ -34,7 +48,7 @@ export function signIn() {
|
|||
.auth()
|
||||
.signInWithEmailAndPassword(email, password)
|
||||
.then((e) => {
|
||||
// changePage("test");
|
||||
// UI.changePage("test");
|
||||
})
|
||||
.catch(function (error) {
|
||||
Notifications.add(error.message, -1);
|
||||
|
@ -96,19 +110,255 @@ export function signOut() {
|
|||
.signOut()
|
||||
.then(function () {
|
||||
Notifications.add("Signed out", 0, 2);
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
}, 1000);
|
||||
|
||||
//TODO Bring this back when possible
|
||||
|
||||
// AllTimeStats.clear();
|
||||
// Settings.hideAccountSection();
|
||||
// AccountIcon.update();
|
||||
// changePage("login");
|
||||
// DB.setSnapshot(null);
|
||||
AllTimeStats.clear();
|
||||
Settings.hideAccountSection();
|
||||
AccountButton.update();
|
||||
UI.changePage("login");
|
||||
DB.setSnapshot(null);
|
||||
})
|
||||
.catch(function (error) {
|
||||
Notifications.add(error.message, -1);
|
||||
});
|
||||
}
|
||||
|
||||
function signUp() {
|
||||
$(".pageLogin .register .button").addClass("disabled");
|
||||
$(".pageLogin .preloader").removeClass("hidden");
|
||||
let nname = $(".pageLogin .register input")[0].value;
|
||||
let email = $(".pageLogin .register input")[1].value;
|
||||
let password = $(".pageLogin .register input")[2].value;
|
||||
let passwordVerify = $(".pageLogin .register input")[3].value;
|
||||
|
||||
if (password != passwordVerify) {
|
||||
Notifications.add("Passwords do not match", 0, 3);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
CloudFunctions.namecheck({ name: nname }).then((d) => {
|
||||
if (d.data.resultCode === -1) {
|
||||
Notifications.add("Name unavailable", -1);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
return;
|
||||
} else if (d.data.resultCode === -2) {
|
||||
Notifications.add(
|
||||
"Name cannot contain special characters or contain more than 14 characters. Can include _ . and -",
|
||||
-1
|
||||
);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
return;
|
||||
} else if (d.data.resultCode === 1) {
|
||||
firebase
|
||||
.auth()
|
||||
.createUserWithEmailAndPassword(email, password)
|
||||
.then((user) => {
|
||||
// Account has been created here.
|
||||
// dontCheckUserName = true;
|
||||
let usr = user.user;
|
||||
usr
|
||||
.updateProfile({
|
||||
displayName: nname,
|
||||
})
|
||||
.then(async function () {
|
||||
// Update successful.
|
||||
await firebase
|
||||
.firestore()
|
||||
.collection("users")
|
||||
.doc(usr.uid)
|
||||
.set({ name: nname }, { merge: true });
|
||||
CloudFunctions.reserveName({ name: nname, uid: usr.uid }).catch(
|
||||
(e) => {
|
||||
console.error("Could not reserve name " + e);
|
||||
throw "Could not reserve name";
|
||||
}
|
||||
);
|
||||
usr.sendEmailVerification();
|
||||
AllTimeStats.clear();
|
||||
Notifications.add("Account created", 1, 3);
|
||||
$("#menu .icon-button.account .text").text(nname);
|
||||
try {
|
||||
firebase.analytics().logEvent("accountCreated", usr.uid);
|
||||
} catch (e) {
|
||||
console.log("Analytics unavailable");
|
||||
}
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
DB.setSnapshot({
|
||||
results: [],
|
||||
personalBests: {},
|
||||
tags: [],
|
||||
globalStats: {
|
||||
time: undefined,
|
||||
started: undefined,
|
||||
completed: undefined,
|
||||
},
|
||||
});
|
||||
if (TestLogic.notSignedInLastResult !== null) {
|
||||
TestLogic.setNotSignedInUid(usr.uid);
|
||||
CloudFunctions.testCompleted({
|
||||
uid: usr.uid,
|
||||
obj: TestLogic.notSignedInLastResult,
|
||||
});
|
||||
DB.getSnapshot().results.push(TestLogic.notSignedInLastResult);
|
||||
}
|
||||
UI.changePage("account");
|
||||
usr.sendEmailVerification();
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
})
|
||||
.catch(function (error) {
|
||||
// An error happened.
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
console.error(error);
|
||||
usr
|
||||
.delete()
|
||||
.then(function () {
|
||||
// User deleted.
|
||||
Notifications.add(
|
||||
"Account not created. " + error.message,
|
||||
-1
|
||||
);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
})
|
||||
.catch(function (error) {
|
||||
// An error happened.
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
Notifications.add(
|
||||
"Something went wrong. " + error.message,
|
||||
-1
|
||||
);
|
||||
console.error(error);
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(function (error) {
|
||||
// Handle Errors here.
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
Notifications.add(error.message, -1);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
});
|
||||
} else {
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
Notifications.add(
|
||||
"Something went wrong when checking name: " + d.data.message,
|
||||
-1
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(".pageLogin #forgotPasswordButton").click((e) => {
|
||||
let email = prompt("Email address");
|
||||
if (email) {
|
||||
firebase
|
||||
.auth()
|
||||
.sendPasswordResetEmail(email)
|
||||
.then(function () {
|
||||
// Email sent.
|
||||
Notifications.add("Email sent", 1, 2);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// An error happened.
|
||||
Notifications.add(error.message, -1);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(".pageLogin .login input").keyup((e) => {
|
||||
if (e.key == "Enter") {
|
||||
UpdateConfig.setChangedBeforeDb(false);
|
||||
signIn();
|
||||
}
|
||||
});
|
||||
|
||||
$(".pageLogin .login .button.signIn").click((e) => {
|
||||
UpdateConfig.setChangedBeforeDb(false);
|
||||
signIn();
|
||||
});
|
||||
|
||||
$(".pageLogin .login .button.signInWithGoogle").click((e) => {
|
||||
UpdateConfig.setChangedBeforeDb(false);
|
||||
signInWithGoogle();
|
||||
});
|
||||
|
||||
$(".signOut").click((e) => {
|
||||
signOut();
|
||||
});
|
||||
|
||||
firebase.auth().onAuthStateChanged(function (user) {
|
||||
if (user) {
|
||||
// User is signed in.
|
||||
$(".pageAccount .content p.accountVerificatinNotice").remove();
|
||||
if (user.emailVerified === false) {
|
||||
$(".pageAccount .content").prepend(
|
||||
`<p class="accountVerificatinNotice" style="text-align:center">Your account is not verified. Click <a onClick="sendVerificationEmail()">here</a> to resend the verification email.`
|
||||
);
|
||||
}
|
||||
AccountButton.update();
|
||||
AccountButton.loading(true);
|
||||
Account.getDataAndInit();
|
||||
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;
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
$("#menu .icon-button.account .text").text(displayName);
|
||||
|
||||
// showFavouriteThemesAtTheTop();
|
||||
CommandlineLists.updateThemeCommands();
|
||||
|
||||
let text = "Account created on " + user.metadata.creationTime;
|
||||
|
||||
const date1 = new Date(user.metadata.creationTime);
|
||||
const date2 = new Date();
|
||||
const diffTime = Math.abs(date2 - date1);
|
||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
||||
|
||||
text += ` (${diffDays} day${diffDays != 1 ? "s" : ""} ago)`;
|
||||
|
||||
$(".pageAccount .group.createdDate").text(text);
|
||||
|
||||
if (VerificationController.data !== null) {
|
||||
VerificationController.verify(user);
|
||||
}
|
||||
}
|
||||
let theme = Misc.findGetParameter("customTheme");
|
||||
if (theme !== null) {
|
||||
try {
|
||||
theme = theme.split(",");
|
||||
UpdateConfig.setCustomThemeColors(theme);
|
||||
Notifications.add("Custom theme applied.", 1);
|
||||
} catch (e) {
|
||||
Notifications.add(
|
||||
"Something went wrong. Reverting to default custom colors.",
|
||||
0
|
||||
);
|
||||
UpdateConfig.setCustomThemeColors(Config.defaultConfig.customThemeColors);
|
||||
}
|
||||
UpdateConfig.setCustomTheme(true);
|
||||
Settings.setCustomThemeInputs();
|
||||
}
|
||||
if (/challenge_.+/g.test(window.location.pathname)) {
|
||||
Notifications.add("Loading challenge", 0);
|
||||
let challengeName = window.location.pathname.split("_")[1];
|
||||
setTimeout(() => {
|
||||
ChallengeController.setup(challengeName);
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
$(".pageLogin .register input").keyup((e) => {
|
||||
if ($(".pageLogin .register .button").hasClass("disabled")) return;
|
||||
if (e.key == "Enter") {
|
||||
signUp();
|
||||
}
|
||||
});
|
||||
|
||||
$(".pageLogin .register .button").click((e) => {
|
||||
if ($(".pageLogin .register .button").hasClass("disabled")) return;
|
||||
signUp();
|
||||
});
|
||||
|
|
|
@ -1,208 +1,25 @@
|
|||
// let dontCheckUserName = false;
|
||||
import * as DB from "./db";
|
||||
import * as Misc from "./misc";
|
||||
import * as CloudFunctions from "./cloud-functions";
|
||||
import * as Notifications from "./notifications";
|
||||
import * as ResultFilters from "./result-filters";
|
||||
import * as ThemeColors from "./theme-colors";
|
||||
import * as ChartController from "./chart-controller";
|
||||
import Config, * as UpdateConfig from "./config";
|
||||
import * as AccountButton from "./account-button";
|
||||
import * as TestLogic from "./test-logic";
|
||||
import * as PaceCaret from "./pace-caret";
|
||||
import * as TagController from "./tag-controller";
|
||||
import * as UI from "./ui";
|
||||
import * as CommandlineLists from "./commandline-lists";
|
||||
import * as MiniResultChart from "./mini-result-chart";
|
||||
import * as ResultTagsPopup from "./result-tags-popup";
|
||||
import * as Settings from "./settings";
|
||||
import * as ThemePicker from "./theme-picker";
|
||||
import * as AllTimeStats from "./all-time-stats";
|
||||
import * as PbTables from "./pb-tables";
|
||||
|
||||
function signUp() {
|
||||
$(".pageLogin .register .button").addClass("disabled");
|
||||
$(".pageLogin .preloader").removeClass("hidden");
|
||||
let nname = $(".pageLogin .register input")[0].value;
|
||||
let email = $(".pageLogin .register input")[1].value;
|
||||
let password = $(".pageLogin .register input")[2].value;
|
||||
let passwordVerify = $(".pageLogin .register input")[3].value;
|
||||
|
||||
if (password != passwordVerify) {
|
||||
Notifications.add("Passwords do not match", 0, 3);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
CloudFunctions.namecheck({ name: nname }).then((d) => {
|
||||
if (d.data.resultCode === -1) {
|
||||
Notifications.add("Name unavailable", -1);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
return;
|
||||
} else if (d.data.resultCode === -2) {
|
||||
Notifications.add(
|
||||
"Name cannot contain special characters or contain more than 14 characters. Can include _ . and -",
|
||||
-1
|
||||
);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
return;
|
||||
} else if (d.data.resultCode === 1) {
|
||||
firebase
|
||||
.auth()
|
||||
.createUserWithEmailAndPassword(email, password)
|
||||
.then((user) => {
|
||||
// Account has been created here.
|
||||
// dontCheckUserName = true;
|
||||
let usr = user.user;
|
||||
usr
|
||||
.updateProfile({
|
||||
displayName: nname,
|
||||
})
|
||||
.then(async function () {
|
||||
// Update successful.
|
||||
await firebase
|
||||
.firestore()
|
||||
.collection("users")
|
||||
.doc(usr.uid)
|
||||
.set({ name: nname }, { merge: true });
|
||||
CloudFunctions.reserveName({ name: nname, uid: usr.uid }).catch(
|
||||
(e) => {
|
||||
console.error("Could not reserve name " + e);
|
||||
throw "Could not reserve name";
|
||||
}
|
||||
);
|
||||
usr.sendEmailVerification();
|
||||
AllTimeStats.clear();
|
||||
Notifications.add("Account created", 1, 3);
|
||||
$("#menu .icon-button.account .text").text(nname);
|
||||
try {
|
||||
firebase.analytics().logEvent("accountCreated", usr.uid);
|
||||
} catch (e) {
|
||||
console.log("Analytics unavailable");
|
||||
}
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
DB.setSnapshot({
|
||||
results: [],
|
||||
personalBests: {},
|
||||
tags: [],
|
||||
globalStats: {
|
||||
time: undefined,
|
||||
started: undefined,
|
||||
completed: undefined,
|
||||
},
|
||||
});
|
||||
if (TestLogic.notSignedInLastResult !== null) {
|
||||
TestLogic.setNotSignedInUid(usr.uid);
|
||||
CloudFunctions.testCompleted({
|
||||
uid: usr.uid,
|
||||
obj: TestLogic.notSignedInLastResult,
|
||||
});
|
||||
DB.getSnapshot().results.push(TestLogic.notSignedInLastResult);
|
||||
}
|
||||
changePage("account");
|
||||
usr.sendEmailVerification();
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
})
|
||||
.catch(function (error) {
|
||||
// An error happened.
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
console.error(error);
|
||||
usr
|
||||
.delete()
|
||||
.then(function () {
|
||||
// User deleted.
|
||||
Notifications.add(
|
||||
"Account not created. " + error.message,
|
||||
-1
|
||||
);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
})
|
||||
.catch(function (error) {
|
||||
// An error happened.
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
Notifications.add(
|
||||
"Something went wrong. " + error.message,
|
||||
-1
|
||||
);
|
||||
console.error(error);
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(function (error) {
|
||||
// Handle Errors here.
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
Notifications.add(error.message, -1);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
});
|
||||
} else {
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
Notifications.add(
|
||||
"Something went wrong when checking name: " + d.data.message,
|
||||
-1
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
firebase.auth().onAuthStateChanged(function (user) {
|
||||
if (user) {
|
||||
// User is signed in.
|
||||
$(".pageAccount .content p.accountVerificatinNotice").remove();
|
||||
if (user.emailVerified === false) {
|
||||
$(".pageAccount .content").prepend(
|
||||
`<p class="accountVerificatinNotice" style="text-align:center">Your account is not verified. Click <a onClick="sendVerificationEmail()">here</a> to resend the verification email.`
|
||||
);
|
||||
}
|
||||
AccountButton.update();
|
||||
AccountButton.loading(true);
|
||||
getAccountDataAndInit();
|
||||
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;
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
$("#menu .icon-button.account .text").text(displayName);
|
||||
|
||||
// showFavouriteThemesAtTheTop();
|
||||
CommandlineLists.updateThemeCommands();
|
||||
|
||||
let text = "Account created on " + user.metadata.creationTime;
|
||||
|
||||
const date1 = new Date(user.metadata.creationTime);
|
||||
const date2 = new Date();
|
||||
const diffTime = Math.abs(date2 - date1);
|
||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
||||
|
||||
text += ` (${diffDays} day${diffDays != 1 ? "s" : ""} ago)`;
|
||||
|
||||
$(".pageAccount .group.createdDate").text(text);
|
||||
|
||||
if (verifyUserWhenLoggedIn !== null) {
|
||||
Notifications.add("Verifying", 0, 3);
|
||||
verifyUserWhenLoggedIn.uid = user.uid;
|
||||
CloudFunctions.verifyUser(verifyUserWhenLoggedIn).then((data) => {
|
||||
if (data.data.status === 1) {
|
||||
Notifications.add(data.data.message, 1);
|
||||
DB.getSnapshot().discordId = data.data.did;
|
||||
Settings.updateDiscordSection();
|
||||
} else {
|
||||
Notifications.add(data.data.message, -1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
let theme = Misc.findGetParameter("customTheme");
|
||||
if (theme !== null) {
|
||||
try {
|
||||
theme = theme.split(",");
|
||||
UpdateConfig.setCustomThemeColors(theme);
|
||||
Notifications.add("Custom theme applied.", 1);
|
||||
} catch (e) {
|
||||
Notifications.add(
|
||||
"Something went wrong. Reverting to default custom colors.",
|
||||
0
|
||||
);
|
||||
UpdateConfig.setCustomThemeColors(Config.defaultConfig.customThemeColors);
|
||||
}
|
||||
UpdateConfig.setCustomTheme(true);
|
||||
Settings.setCustomThemeInputs();
|
||||
}
|
||||
if (/challenge_.+/g.test(window.location.pathname)) {
|
||||
Notifications.add("Loading challenge", 0);
|
||||
let challengeName = window.location.pathname.split("_")[1];
|
||||
setTimeout(() => {
|
||||
ChallengeController.setup(challengeName);
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
function getAccountDataAndInit() {
|
||||
export function getDataAndInit() {
|
||||
DB.initSnapshot()
|
||||
.then(async (e) => {
|
||||
let snap = DB.getSnapshot();
|
||||
|
@ -311,7 +128,7 @@ function getAccountDataAndInit() {
|
|||
$(".pageLogin").hasClass("active") ||
|
||||
window.location.pathname === "/account"
|
||||
) {
|
||||
changePage("account");
|
||||
UI.changePage("account");
|
||||
}
|
||||
ThemePicker.refreshButtons();
|
||||
AccountButton.loading(false);
|
||||
|
@ -333,562 +150,6 @@ function getAccountDataAndInit() {
|
|||
});
|
||||
}
|
||||
|
||||
$(document).on("click", ".pageAccount .miniResultChartButton", (event) => {
|
||||
console.log("updating");
|
||||
let filteredId = $(event.currentTarget).attr("filteredResultsId");
|
||||
if (filteredId === undefined) return;
|
||||
MiniResultChart.updateData(filteredResults[filteredId].chartData);
|
||||
MiniResultChart.show();
|
||||
MiniResultChart.updatePosition(
|
||||
event.pageX - $(".pageAccount .miniResultChartWrapper").outerWidth(),
|
||||
event.pageY + 30
|
||||
);
|
||||
});
|
||||
|
||||
Misc.getLanguageList().then((languages) => {
|
||||
languages.forEach((language) => {
|
||||
$(
|
||||
".pageAccount .content .filterButtons .buttonsAndTitle.languages .buttons"
|
||||
).append(
|
||||
`<div class="button" filter="${language}">${language.replace(
|
||||
"_",
|
||||
" "
|
||||
)}</div>`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
$(
|
||||
".pageAccount .content .filterButtons .buttonsAndTitle.funbox .buttons"
|
||||
).append(`<div class="button" filter="none">none</div>`);
|
||||
Misc.getFunboxList().then((funboxModes) => {
|
||||
funboxModes.forEach((funbox) => {
|
||||
$(
|
||||
".pageAccount .content .filterButtons .buttonsAndTitle.funbox .buttons"
|
||||
).append(
|
||||
`<div class="button" filter="${funbox.name}">${funbox.name.replace(
|
||||
/_/g,
|
||||
" "
|
||||
)}</div>`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function toggleFilter(group, filter) {
|
||||
try {
|
||||
if (group === "date") {
|
||||
Object.keys(ResultFilters.getGroup("date")).forEach((date) => {
|
||||
ResultFilters.setFilter("date", date, false);
|
||||
});
|
||||
}
|
||||
ResultFilters.toggleFilter(group, filter);
|
||||
ResultFilters.save();
|
||||
} catch (e) {
|
||||
Notifications.add(
|
||||
"Something went wrong toggling filter. Reverting to defaults",
|
||||
0
|
||||
);
|
||||
console.log("toggling filter error");
|
||||
console.error(e);
|
||||
ResultFilters.reset();
|
||||
showActiveFilters();
|
||||
}
|
||||
}
|
||||
|
||||
function showActiveFilters() {
|
||||
let aboveChartDisplay = {};
|
||||
Object.keys(ResultFilters.getFilters()).forEach((group) => {
|
||||
aboveChartDisplay[group] = {
|
||||
all: true,
|
||||
array: [],
|
||||
};
|
||||
Object.keys(ResultFilters.getGroup(group)).forEach((filter) => {
|
||||
if (ResultFilters.getFilter(group, filter)) {
|
||||
aboveChartDisplay[group].array.push(filter);
|
||||
} else {
|
||||
aboveChartDisplay[group].all = false;
|
||||
}
|
||||
let buttonEl;
|
||||
if (group === "date") {
|
||||
buttonEl = $(
|
||||
`.pageAccount .group.topFilters .filterGroup[group="${group}"] .button[filter="${filter}"]`
|
||||
);
|
||||
} else {
|
||||
buttonEl = $(
|
||||
`.pageAccount .group.filterButtons .filterGroup[group="${group}"] .button[filter="${filter}"]`
|
||||
);
|
||||
}
|
||||
if (ResultFilters.getFilter(group, filter)) {
|
||||
buttonEl.addClass("active");
|
||||
} else {
|
||||
buttonEl.removeClass("active");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function addText(group) {
|
||||
let ret = "";
|
||||
ret += "<div class='group'>";
|
||||
if (group == "difficulty") {
|
||||
ret += `<span aria-label="Difficulty" data-balloon-pos="up"><i class="fas fa-fw fa-star"></i>`;
|
||||
} else if (group == "mode") {
|
||||
ret += `<span aria-label="Mode" data-balloon-pos="up"><i class="fas fa-fw fa-bars"></i>`;
|
||||
} else if (group == "punctuation") {
|
||||
ret += `<span aria-label="Punctuation" data-balloon-pos="up"><span class="punc" style="font-weight: 900;
|
||||
width: 1.25rem;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
letter-spacing: -.1rem;">!?</span>`;
|
||||
} else if (group == "numbers") {
|
||||
ret += `<span aria-label="Numbers" data-balloon-pos="up"><span class="numbers" style="font-weight: 900;
|
||||
width: 1.25rem;
|
||||
text-align: center;
|
||||
margin-right: .1rem;
|
||||
display: inline-block;
|
||||
letter-spacing: -.1rem;">15</span>`;
|
||||
} else if (group == "words") {
|
||||
ret += `<span aria-label="Words" data-balloon-pos="up"><i class="fas fa-fw fa-font"></i>`;
|
||||
} else if (group == "time") {
|
||||
ret += `<span aria-label="Time" data-balloon-pos="up"><i class="fas fa-fw fa-clock"></i>`;
|
||||
} else if (group == "date") {
|
||||
ret += `<span aria-label="Date" data-balloon-pos="up"><i class="fas fa-fw fa-calendar"></i>`;
|
||||
} else if (group == "tags") {
|
||||
ret += `<span aria-label="Tags" data-balloon-pos="up"><i class="fas fa-fw fa-tags"></i>`;
|
||||
} else if (group == "language") {
|
||||
ret += `<span aria-label="Language" data-balloon-pos="up"><i class="fas fa-fw fa-globe-americas"></i>`;
|
||||
} else if (group == "funbox") {
|
||||
ret += `<span aria-label="Funbox" data-balloon-pos="up"><i class="fas fa-fw fa-gamepad"></i>`;
|
||||
}
|
||||
if (aboveChartDisplay[group].all) {
|
||||
ret += "all";
|
||||
} else {
|
||||
if (group === "tags") {
|
||||
ret += aboveChartDisplay.tags.array
|
||||
.map((id) => {
|
||||
if (id == "none") return id;
|
||||
let name = DB.getSnapshot().tags.filter((t) => t.id == id)[0];
|
||||
if (name !== undefined) {
|
||||
return DB.getSnapshot().tags.filter((t) => t.id == id)[0].name;
|
||||
}
|
||||
})
|
||||
.join(", ");
|
||||
} else {
|
||||
ret += aboveChartDisplay[group].array.join(", ").replace(/_/g, " ");
|
||||
}
|
||||
}
|
||||
ret += "</span></div>";
|
||||
return ret;
|
||||
}
|
||||
|
||||
let chartString = "";
|
||||
|
||||
//date
|
||||
chartString += addText("date");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//mode
|
||||
chartString += addText("mode");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//time
|
||||
if (aboveChartDisplay.mode.array.includes("time")) {
|
||||
chartString += addText("time");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
}
|
||||
|
||||
//words
|
||||
if (aboveChartDisplay.mode.array.includes("words")) {
|
||||
chartString += addText("words");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
}
|
||||
|
||||
//diff
|
||||
chartString += addText("difficulty");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//punc
|
||||
chartString += addText("punctuation");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//numbers
|
||||
chartString += addText("numbers");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//language
|
||||
chartString += addText("language");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//funbox
|
||||
chartString += addText("funbox");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//tags
|
||||
chartString += addText("tags");
|
||||
|
||||
$(".pageAccount .group.chart .above").html(chartString);
|
||||
|
||||
refreshAccountPage();
|
||||
}
|
||||
|
||||
// function showChartPreloader() {
|
||||
// $(".pageAccount .group.chart .preloader").stop(true, true).animate(
|
||||
// {
|
||||
// opacity: 1,
|
||||
// },
|
||||
// 125
|
||||
// );
|
||||
// }
|
||||
|
||||
// function hideChartPreloader() {
|
||||
// $(".pageAccount .group.chart .preloader").stop(true, true).animate(
|
||||
// {
|
||||
// opacity: 0,
|
||||
// },
|
||||
// 125
|
||||
// );
|
||||
// }
|
||||
|
||||
$(".pageAccount .topFilters .button.allFilters").click((e) => {
|
||||
Object.keys(ResultFilters.getFilters()).forEach((group) => {
|
||||
Object.keys(ResultFilters.getGroup(group)).forEach((filter) => {
|
||||
if (group === "date") {
|
||||
ResultFilters.setFilter(group, filter, false);
|
||||
} else {
|
||||
ResultFilters.setFilter(group, filter, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
ResultFilters.setFilter("date", "all", true);
|
||||
showActiveFilters();
|
||||
ResultFilters.save();
|
||||
});
|
||||
|
||||
$(".pageAccount .topFilters .button.currentConfigFilter").click((e) => {
|
||||
Object.keys(ResultFilters.getFilters()).forEach((group) => {
|
||||
Object.keys(ResultFilters.getGroup(group)).forEach((filter) => {
|
||||
ResultFilters.setFilter(group, filter, false);
|
||||
});
|
||||
});
|
||||
|
||||
ResultFilters.setFilter("difficulty", Config.difficulty, true);
|
||||
ResultFilters.setFilter("mode", Config.mode, true);
|
||||
if (Config.mode === "time") {
|
||||
ResultFilters.setFilter("time", Config.time, true);
|
||||
} else if (Config.mode === "words") {
|
||||
ResultFilters.setFilter("words", Config.words, true);
|
||||
} else if (Config.mode === "quote") {
|
||||
Object.keys(ResultFilters.getGroup("quoteLength")).forEach((ql) => {
|
||||
ResultFilters.setFilter("quoteLength", ql, true);
|
||||
});
|
||||
}
|
||||
if (Config.punctuation) {
|
||||
ResultFilters.setFilter("punctuation", "on", true);
|
||||
} else {
|
||||
ResultFilters.setFilter("punctuation", "off", true);
|
||||
}
|
||||
if (Config.numbers) {
|
||||
ResultFilters.setFilter("numbers", "on", true);
|
||||
} else {
|
||||
ResultFilters.setFilter("numbers", "off", true);
|
||||
}
|
||||
if (Config.mode === "quote" && /english.*/.test(Config.language)) {
|
||||
ResultFilters.setFilter("language", "english", true);
|
||||
} else {
|
||||
ResultFilters.setFilter("language", Config.language, true);
|
||||
}
|
||||
ResultFilters.setFilter("funbox", true);
|
||||
ResultFilters.setFilter("tags", "none", true);
|
||||
DB.getSnapshot().tags.forEach((tag) => {
|
||||
if (tag.active === true) {
|
||||
ResultFilters.setFilter("tags", "none", false);
|
||||
ResultFilters.setFilter("tags", tag.id, true);
|
||||
}
|
||||
});
|
||||
|
||||
ResultFilters.setFilter("date", "all", true);
|
||||
showActiveFilters();
|
||||
ResultFilters.save();
|
||||
console.log(ResultFilters.getFilters());
|
||||
});
|
||||
|
||||
$(".pageAccount .topFilters .button.toggleAdvancedFilters").click((e) => {
|
||||
$(".pageAccount .filterButtons").slideToggle(250);
|
||||
$(".pageAccount .topFilters .button.toggleAdvancedFilters").toggleClass(
|
||||
"active"
|
||||
);
|
||||
});
|
||||
|
||||
$(
|
||||
".pageAccount .filterButtons .buttonsAndTitle .buttons, .pageAccount .group.topFilters .buttonsAndTitle.testDate .buttons"
|
||||
).click(".button", (e) => {
|
||||
const filter = $(e.target).attr("filter");
|
||||
const group = $(e.target).parents(".buttons").attr("group");
|
||||
if ($(e.target).hasClass("allFilters")) {
|
||||
Object.keys(ResultFilters.getFilters()).forEach((group) => {
|
||||
Object.keys(ResultFilters.getGroup(group)).forEach((filter) => {
|
||||
if (group === "date") {
|
||||
ResultFilters.setFilter(group, filter, false);
|
||||
} else {
|
||||
ResultFilters.setFilter(group, filter, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
ResultFilters.setFilter("date", "all", true);
|
||||
} else if ($(e.target).hasClass("noFilters")) {
|
||||
Object.keys(ResultFilters.getFilters()).forEach((group) => {
|
||||
if (group !== "date") {
|
||||
Object.keys(ResultFilters.getGroup(group)).forEach((filter) => {
|
||||
ResultFilters.setFilter(group, filter, false);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (e.shiftKey) {
|
||||
Object.keys(ResultFilters.getGroup(group)).forEach((filter) => {
|
||||
ResultFilters.setFilter(group, filter, false);
|
||||
});
|
||||
ResultFilters.setFilter(group, filter, true);
|
||||
} else {
|
||||
toggleFilter(group, filter);
|
||||
}
|
||||
}
|
||||
showActiveFilters();
|
||||
ResultFilters.save();
|
||||
});
|
||||
|
||||
function fillPbTables() {
|
||||
$(".pageAccount .timePbTable tbody").html(`
|
||||
<tr>
|
||||
<td>15</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>30</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>60</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>120</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
`);
|
||||
$(".pageAccount .wordsPbTable tbody").html(`
|
||||
<tr>
|
||||
<td>10</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>25</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>50</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>100</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
`);
|
||||
|
||||
const pb = DB.getSnapshot().personalBests;
|
||||
let pbData;
|
||||
let text;
|
||||
|
||||
text = "";
|
||||
try {
|
||||
pbData = pb.time[15].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>15</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>15</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
try {
|
||||
pbData = pb.time[30].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>30</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>30</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
try {
|
||||
pbData = pb.time[60].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>60</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>60</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
try {
|
||||
pbData = pb.time[120].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>120</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>120</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
$(".pageAccount .timePbTable tbody").html(text);
|
||||
|
||||
text = "";
|
||||
try {
|
||||
pbData = pb.words[10].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>10</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>10</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
try {
|
||||
pbData = pb.words[25].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>25</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>25</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
try {
|
||||
pbData = pb.words[50].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>50</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>50</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
try {
|
||||
pbData = pb.words[100].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>100</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>100</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
$(".pageAccount .wordsPbTable tbody").html(text);
|
||||
}
|
||||
|
||||
let filteredResults = [];
|
||||
let visibleTableLines = 0;
|
||||
|
||||
|
@ -1023,13 +284,13 @@ function loadMoreLines() {
|
|||
|
||||
let totalSecondsFiltered = 0;
|
||||
|
||||
function refreshAccountPage() {
|
||||
export function update() {
|
||||
function cont() {
|
||||
ThemeColors.update();
|
||||
ChartController.accountHistory.updateColors();
|
||||
ChartController.accountActivity.updateColors();
|
||||
AllTimeStats.update();
|
||||
fillPbTables();
|
||||
PbTables.update();
|
||||
|
||||
let chartData = [];
|
||||
let wpmChartData = [];
|
||||
|
@ -1210,7 +471,7 @@ function refreshAccountPage() {
|
|||
console.log(result);
|
||||
console.error(e);
|
||||
ResultFilters.reset();
|
||||
showActiveFilters();
|
||||
ResultFilters.updateActive();
|
||||
}
|
||||
|
||||
//filters done
|
||||
|
@ -1520,10 +781,10 @@ function refreshAccountPage() {
|
|||
} else if (DB.getSnapshot().results === undefined) {
|
||||
DB.getUserResults().then((d) => {
|
||||
if (d) {
|
||||
showActiveFilters();
|
||||
ResultFilters.updateActive();
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
changePage("");
|
||||
UI.changePage("");
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
|
@ -1546,56 +807,18 @@ $(".pageAccount .toggleChartStyle").click((e) => {
|
|||
UpdateConfig.toggleChartStyle();
|
||||
});
|
||||
|
||||
$(".pageLogin .register input").keyup((e) => {
|
||||
if ($(".pageLogin .register .button").hasClass("disabled")) return;
|
||||
if (e.key == "Enter") {
|
||||
signUp();
|
||||
}
|
||||
});
|
||||
|
||||
$(".pageLogin .register .button").click((e) => {
|
||||
if ($(".pageLogin .register .button").hasClass("disabled")) return;
|
||||
signUp();
|
||||
});
|
||||
|
||||
$(".pageLogin .login input").keyup((e) => {
|
||||
if (e.key == "Enter") {
|
||||
UpdateConfig.setChangedBeforeDb(false);
|
||||
AccountController.signIn();
|
||||
}
|
||||
});
|
||||
|
||||
$(".pageLogin .login .button.signIn").click((e) => {
|
||||
UpdateConfig.setChangedBeforeDb(false);
|
||||
AccountController.signIn();
|
||||
});
|
||||
|
||||
$(".pageLogin .login .button.signInWithGoogle").click((e) => {
|
||||
UpdateConfig.setChangedBeforeDb(false);
|
||||
AccountController.signInWithGoogle();
|
||||
});
|
||||
|
||||
$(".signOut").click((e) => {
|
||||
AccountController.signOut();
|
||||
});
|
||||
|
||||
$(".pageAccount .loadMoreButton").click((e) => {
|
||||
loadMoreLines();
|
||||
});
|
||||
|
||||
$(".pageLogin #forgotPasswordButton").click((e) => {
|
||||
let email = prompt("Email address");
|
||||
if (email) {
|
||||
firebase
|
||||
.auth()
|
||||
.sendPasswordResetEmail(email)
|
||||
.then(function () {
|
||||
// Email sent.
|
||||
Notifications.add("Email sent", 1, 2);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// An error happened.
|
||||
Notifications.add(error.message, -1);
|
||||
});
|
||||
}
|
||||
$(document).on("click", ".pageAccount .miniResultChartButton", (event) => {
|
||||
console.log("updating");
|
||||
let filteredId = $(event.currentTarget).attr("filteredResultsId");
|
||||
if (filteredId === undefined) return;
|
||||
MiniResultChart.updateData(filteredResults[filteredId].chartData);
|
||||
MiniResultChart.show();
|
||||
MiniResultChart.updatePosition(
|
||||
event.pageX - $(".pageAccount .miniResultChartWrapper").outerWidth(),
|
||||
event.pageY + 30
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as DB from "./db";
|
||||
|
||||
export function clear() {
|
||||
$(".pageAccount .globalTimeTyping .val").text(`-`);
|
||||
$(".pageAccount .globalTestsStarted .val").text(`-`);
|
||||
|
|
234
src/js/account/pb-tables.js
Normal file
234
src/js/account/pb-tables.js
Normal file
|
@ -0,0 +1,234 @@
|
|||
import * as DB from "./db";
|
||||
|
||||
export function update() {
|
||||
$(".pageAccount .timePbTable tbody").html(`
|
||||
<tr>
|
||||
<td>15</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>30</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>60</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>120</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
`);
|
||||
$(".pageAccount .wordsPbTable tbody").html(`
|
||||
<tr>
|
||||
<td>10</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>25</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>50</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>100</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
`);
|
||||
|
||||
const pb = DB.getSnapshot().personalBests;
|
||||
let pbData;
|
||||
let text;
|
||||
|
||||
text = "";
|
||||
try {
|
||||
pbData = pb.time[15].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>15</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>15</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
try {
|
||||
pbData = pb.time[30].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>30</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>30</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
try {
|
||||
pbData = pb.time[60].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>60</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>60</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
try {
|
||||
pbData = pb.time[120].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>120</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>120</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
$(".pageAccount .timePbTable tbody").html(text);
|
||||
|
||||
text = "";
|
||||
try {
|
||||
pbData = pb.words[10].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>10</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>10</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
try {
|
||||
pbData = pb.words[25].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>25</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>25</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
try {
|
||||
pbData = pb.words[50].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>50</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>50</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
try {
|
||||
pbData = pb.words[100].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
text += `<tr>
|
||||
<td>100</td>
|
||||
<td>${pbData.wpm}</td>
|
||||
<td>${pbData.raw === undefined ? "-" : pbData.raw}</td>
|
||||
<td>${pbData.acc === undefined ? "-" : pbData.acc + "%"}</td>
|
||||
<td>
|
||||
${pbData.consistency === undefined ? "-" : pbData.consistency + "%"}
|
||||
</td>
|
||||
</tr>`;
|
||||
} catch (e) {
|
||||
text += `<tr>
|
||||
<td>100</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>`;
|
||||
}
|
||||
$(".pageAccount .wordsPbTable tbody").html(text);
|
||||
}
|
452
src/js/account/result-filters.js
Normal file
452
src/js/account/result-filters.js
Normal file
|
@ -0,0 +1,452 @@
|
|||
import * as Misc from "./misc";
|
||||
import * as DB from "./db";
|
||||
import Config from "./config";
|
||||
import * as Notifications from "./notifications";
|
||||
import * as Account from "./account";
|
||||
import * as Funbox from "./funbox";
|
||||
|
||||
let defaultResultFilters = {
|
||||
difficulty: {
|
||||
normal: true,
|
||||
expert: true,
|
||||
master: true,
|
||||
},
|
||||
mode: {
|
||||
words: true,
|
||||
time: true,
|
||||
quote: true,
|
||||
custom: true,
|
||||
},
|
||||
words: {
|
||||
10: true,
|
||||
25: true,
|
||||
50: true,
|
||||
100: true,
|
||||
200: true,
|
||||
custom: true,
|
||||
},
|
||||
time: {
|
||||
15: true,
|
||||
30: true,
|
||||
60: true,
|
||||
120: true,
|
||||
custom: true,
|
||||
},
|
||||
quoteLength: {
|
||||
short: true,
|
||||
medium: true,
|
||||
long: true,
|
||||
thicc: true,
|
||||
},
|
||||
punctuation: {
|
||||
on: true,
|
||||
off: true,
|
||||
},
|
||||
numbers: {
|
||||
on: true,
|
||||
off: true,
|
||||
},
|
||||
date: {
|
||||
last_day: false,
|
||||
last_week: false,
|
||||
last_month: false,
|
||||
all: true,
|
||||
},
|
||||
tags: {
|
||||
none: true,
|
||||
},
|
||||
language: {},
|
||||
funbox: {
|
||||
none: true,
|
||||
},
|
||||
};
|
||||
|
||||
export let filters;
|
||||
|
||||
Promise.all([Misc.getLanguageList(), Misc.getFunboxList()]).then((values) => {
|
||||
let languages = values[0];
|
||||
let funboxModes = values[1];
|
||||
languages.forEach((language) => {
|
||||
defaultResultFilters.language[language] = true;
|
||||
});
|
||||
funboxModes.forEach((funbox) => {
|
||||
defaultResultFilters.funbox[funbox.name] = true;
|
||||
});
|
||||
filters = defaultResultFilters;
|
||||
});
|
||||
|
||||
export function getFilters() {
|
||||
return filters;
|
||||
}
|
||||
|
||||
export function getGroup(group) {
|
||||
return filters[group];
|
||||
}
|
||||
|
||||
// export function setFilter(group, filter, value) {
|
||||
// filters[group][filter] = value;
|
||||
// }
|
||||
|
||||
export function getFilter(group, filter) {
|
||||
return filters[group][filter];
|
||||
}
|
||||
|
||||
// export function toggleFilter(group, filter) {
|
||||
// filters[group][filter] = !filters[group][filter];
|
||||
// }
|
||||
|
||||
export function loadTags(tags) {
|
||||
tags.forEach((tag) => {
|
||||
defaultResultFilters[tag.id] = true;
|
||||
});
|
||||
}
|
||||
|
||||
export function save() {
|
||||
Misc.setCookie("resultFilters", JSON.stringify(filters), 365);
|
||||
}
|
||||
|
||||
export function load() {
|
||||
// let newTags = $.cookie("activeTags");
|
||||
try {
|
||||
let newResultFilters = Misc.getCookie("resultFilters");
|
||||
if (newResultFilters !== undefined && newResultFilters !== "") {
|
||||
filters = JSON.parse(newResultFilters);
|
||||
save();
|
||||
} else {
|
||||
filters = defaultResultFilters;
|
||||
save();
|
||||
}
|
||||
} catch {
|
||||
filters = defaultResultFilters;
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
export function reset() {
|
||||
filters = defaultResultFilters;
|
||||
save();
|
||||
}
|
||||
|
||||
load();
|
||||
|
||||
export function updateActive() {
|
||||
let aboveChartDisplay = {};
|
||||
Object.keys(getFilters()).forEach((group) => {
|
||||
aboveChartDisplay[group] = {
|
||||
all: true,
|
||||
array: [],
|
||||
};
|
||||
Object.keys(getGroup(group)).forEach((filter) => {
|
||||
if (getFilter(group, filter)) {
|
||||
aboveChartDisplay[group].array.push(filter);
|
||||
} else {
|
||||
aboveChartDisplay[group].all = false;
|
||||
}
|
||||
let buttonEl;
|
||||
if (group === "date") {
|
||||
buttonEl = $(
|
||||
`.pageAccount .group.topFilters .filterGroup[group="${group}"] .button[filter="${filter}"]`
|
||||
);
|
||||
} else {
|
||||
buttonEl = $(
|
||||
`.pageAccount .group.filterButtons .filterGroup[group="${group}"] .button[filter="${filter}"]`
|
||||
);
|
||||
}
|
||||
if (getFilter(group, filter)) {
|
||||
buttonEl.addClass("active");
|
||||
} else {
|
||||
buttonEl.removeClass("active");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function addText(group) {
|
||||
let ret = "";
|
||||
ret += "<div class='group'>";
|
||||
if (group == "difficulty") {
|
||||
ret += `<span aria-label="Difficulty" data-balloon-pos="up"><i class="fas fa-fw fa-star"></i>`;
|
||||
} else if (group == "mode") {
|
||||
ret += `<span aria-label="Mode" data-balloon-pos="up"><i class="fas fa-fw fa-bars"></i>`;
|
||||
} else if (group == "punctuation") {
|
||||
ret += `<span aria-label="Punctuation" data-balloon-pos="up"><span class="punc" style="font-weight: 900;
|
||||
width: 1.25rem;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
letter-spacing: -.1rem;">!?</span>`;
|
||||
} else if (group == "numbers") {
|
||||
ret += `<span aria-label="Numbers" data-balloon-pos="up"><span class="numbers" style="font-weight: 900;
|
||||
width: 1.25rem;
|
||||
text-align: center;
|
||||
margin-right: .1rem;
|
||||
display: inline-block;
|
||||
letter-spacing: -.1rem;">15</span>`;
|
||||
} else if (group == "words") {
|
||||
ret += `<span aria-label="Words" data-balloon-pos="up"><i class="fas fa-fw fa-font"></i>`;
|
||||
} else if (group == "time") {
|
||||
ret += `<span aria-label="Time" data-balloon-pos="up"><i class="fas fa-fw fa-clock"></i>`;
|
||||
} else if (group == "date") {
|
||||
ret += `<span aria-label="Date" data-balloon-pos="up"><i class="fas fa-fw fa-calendar"></i>`;
|
||||
} else if (group == "tags") {
|
||||
ret += `<span aria-label="Tags" data-balloon-pos="up"><i class="fas fa-fw fa-tags"></i>`;
|
||||
} else if (group == "language") {
|
||||
ret += `<span aria-label="Language" data-balloon-pos="up"><i class="fas fa-fw fa-globe-americas"></i>`;
|
||||
} else if (group == "funbox") {
|
||||
ret += `<span aria-label="Funbox" data-balloon-pos="up"><i class="fas fa-fw fa-gamepad"></i>`;
|
||||
}
|
||||
if (aboveChartDisplay[group].all) {
|
||||
ret += "all";
|
||||
} else {
|
||||
if (group === "tags") {
|
||||
ret += aboveChartDisplay.tags.array
|
||||
.map((id) => {
|
||||
if (id == "none") return id;
|
||||
let name = DB.getSnapshot().tags.filter((t) => t.id == id)[0];
|
||||
if (name !== undefined) {
|
||||
return DB.getSnapshot().tags.filter((t) => t.id == id)[0].name;
|
||||
}
|
||||
})
|
||||
.join(", ");
|
||||
} else {
|
||||
ret += aboveChartDisplay[group].array.join(", ").replace(/_/g, " ");
|
||||
}
|
||||
}
|
||||
ret += "</span></div>";
|
||||
return ret;
|
||||
}
|
||||
|
||||
let chartString = "";
|
||||
|
||||
//date
|
||||
chartString += addText("date");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//mode
|
||||
chartString += addText("mode");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//time
|
||||
if (aboveChartDisplay.mode.array.includes("time")) {
|
||||
chartString += addText("time");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
}
|
||||
|
||||
//words
|
||||
if (aboveChartDisplay.mode.array.includes("words")) {
|
||||
chartString += addText("words");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
}
|
||||
|
||||
//diff
|
||||
chartString += addText("difficulty");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//punc
|
||||
chartString += addText("punctuation");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//numbers
|
||||
chartString += addText("numbers");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//language
|
||||
chartString += addText("language");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//funbox
|
||||
chartString += addText("funbox");
|
||||
chartString += `<div class="spacer"></div>`;
|
||||
|
||||
//tags
|
||||
chartString += addText("tags");
|
||||
|
||||
$(".pageAccount .group.chart .above").html(chartString);
|
||||
|
||||
Account.update();
|
||||
}
|
||||
|
||||
export function toggle(group, filter) {
|
||||
try {
|
||||
if (group === "date") {
|
||||
Object.keys(getGroup("date")).forEach((date) => {
|
||||
filters["date"][date] = false;
|
||||
});
|
||||
}
|
||||
filters[group][filter] = !filters[group][filter];
|
||||
save();
|
||||
} catch (e) {
|
||||
Notifications.add(
|
||||
"Something went wrong toggling filter. Reverting to defaults",
|
||||
0
|
||||
);
|
||||
console.log("toggling filter error");
|
||||
console.error(e);
|
||||
reset();
|
||||
updateActive();
|
||||
}
|
||||
}
|
||||
|
||||
export function updateTags() {
|
||||
$(
|
||||
".pageAccount .content .filterButtons .buttonsAndTitle.tags .buttons"
|
||||
).empty();
|
||||
if (DB.getSnapshot().tags.length > 0) {
|
||||
$(".pageAccount .content .filterButtons .buttonsAndTitle.tags").removeClass(
|
||||
"hidden"
|
||||
);
|
||||
$(
|
||||
".pageAccount .content .filterButtons .buttonsAndTitle.tags .buttons"
|
||||
).append(`<div class="button" filter="none">no tag</div>`);
|
||||
DB.getSnapshot().tags.forEach((tag) => {
|
||||
$(
|
||||
".pageAccount .content .filterButtons .buttonsAndTitle.tags .buttons"
|
||||
).append(`<div class="button" filter="${tag.id}">${tag.name}</div>`);
|
||||
});
|
||||
} else {
|
||||
$(".pageAccount .content .filterButtons .buttonsAndTitle.tags").addClass(
|
||||
"hidden"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$(
|
||||
".pageAccount .filterButtons .buttonsAndTitle .buttons, .pageAccount .group.topFilters .buttonsAndTitle.testDate .buttons"
|
||||
).click(".button", (e) => {
|
||||
const filter = $(e.target).attr("filter");
|
||||
const group = $(e.target).parents(".buttons").attr("group");
|
||||
if ($(e.target).hasClass("allFilters")) {
|
||||
Object.keys(getFilters()).forEach((group) => {
|
||||
Object.keys(getGroup(group)).forEach((filter) => {
|
||||
if (group === "date") {
|
||||
filters[group][filter] = false;
|
||||
} else {
|
||||
filters[group][filter] = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
filters["date"]["all"] = true;
|
||||
} else if ($(e.target).hasClass("noFilters")) {
|
||||
Object.keys(getFilters()).forEach((group) => {
|
||||
if (group !== "date") {
|
||||
Object.keys(getGroup(group)).forEach((filter) => {
|
||||
filters[group][filter] = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (e.shiftKey) {
|
||||
Object.keys(getGroup(group)).forEach((filter) => {
|
||||
filters[group][filter] = false;
|
||||
});
|
||||
filters[group][filter] = true;
|
||||
} else {
|
||||
filters[group][filter] = !filters[group][filter];
|
||||
}
|
||||
}
|
||||
updateActive();
|
||||
save();
|
||||
});
|
||||
|
||||
$(".pageAccount .topFilters .button.allFilters").click((e) => {
|
||||
Object.keys(getFilters()).forEach((group) => {
|
||||
Object.keys(getGroup(group)).forEach((filter) => {
|
||||
if (group === "date") {
|
||||
filters[group][filter] = false;
|
||||
} else {
|
||||
filters[group][filter] = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
filters["date"]["all"] = true;
|
||||
updateActive();
|
||||
save();
|
||||
});
|
||||
|
||||
$(".pageAccount .topFilters .button.currentConfigFilter").click((e) => {
|
||||
Object.keys(getFilters()).forEach((group) => {
|
||||
Object.keys(getGroup(group)).forEach((filter) => {
|
||||
filters[group][filter] = false;
|
||||
});
|
||||
});
|
||||
|
||||
filters["difficulty"][Config.difficulty] = true;
|
||||
filters["mode"][Config.mode] = true;
|
||||
if (Config.mode === "time") {
|
||||
filters["time"][Config.time] = true;
|
||||
} else if (Config.mode === "words") {
|
||||
filters["words"][Config.words] = true;
|
||||
} else if (Config.mode === "quote") {
|
||||
Object.keys(getGroup("quoteLength")).forEach((ql) => {
|
||||
filters["quoteLength"][ql] = true;
|
||||
});
|
||||
}
|
||||
if (Config.punctuation) {
|
||||
filters["punctuation"]["on"] = true;
|
||||
} else {
|
||||
filters["punctuation"]["off"] = true;
|
||||
}
|
||||
if (Config.numbers) {
|
||||
filters["numbers"]["on"] = true;
|
||||
} else {
|
||||
filters["numbers"]["off"] = true;
|
||||
}
|
||||
if (Config.mode === "quote" && /english.*/.test(Config.language)) {
|
||||
filters["language"]["english"] = true;
|
||||
} else {
|
||||
filters["language"][Config.language] = true;
|
||||
}
|
||||
|
||||
if (Funbox.active === "none") {
|
||||
filters.funbox.none = true;
|
||||
} else {
|
||||
filters.funbox[Funbox.active] = true;
|
||||
}
|
||||
|
||||
filters["tags"]["none"] = true;
|
||||
DB.getSnapshot().tags.forEach((tag) => {
|
||||
if (tag.active === true) {
|
||||
filters["tags"]["none"] = false;
|
||||
filters["tags"][tag.id] = true;
|
||||
}
|
||||
});
|
||||
|
||||
filters["date"]["all"] = true;
|
||||
updateActive();
|
||||
save();
|
||||
console.log(getFilters());
|
||||
});
|
||||
|
||||
$(".pageAccount .topFilters .button.toggleAdvancedFilters").click((e) => {
|
||||
$(".pageAccount .filterButtons").slideToggle(250);
|
||||
$(".pageAccount .topFilters .button.toggleAdvancedFilters").toggleClass(
|
||||
"active"
|
||||
);
|
||||
});
|
||||
|
||||
Misc.getLanguageList().then((languages) => {
|
||||
languages.forEach((language) => {
|
||||
$(
|
||||
".pageAccount .content .filterButtons .buttonsAndTitle.languages .buttons"
|
||||
).append(
|
||||
`<div class="button" filter="${language}">${language.replace(
|
||||
"_",
|
||||
" "
|
||||
)}</div>`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
$(
|
||||
".pageAccount .content .filterButtons .buttonsAndTitle.funbox .buttons"
|
||||
).append(`<div class="button" filter="none">none</div>`);
|
||||
Misc.getFunboxList().then((funboxModes) => {
|
||||
funboxModes.forEach((funbox) => {
|
||||
$(
|
||||
".pageAccount .content .filterButtons .buttonsAndTitle.funbox .buttons"
|
||||
).append(
|
||||
`<div class="button" filter="${funbox.name}">${funbox.name.replace(
|
||||
/_/g,
|
||||
" "
|
||||
)}</div>`
|
||||
);
|
||||
});
|
||||
});
|
23
src/js/account/verification-controller.js
Normal file
23
src/js/account/verification-controller.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
import * as CloudFunctions from "./cloud-functions";
|
||||
import * as Notifications from "./notifications";
|
||||
import * as Settings from "./settings";
|
||||
import * as DB from "./db";
|
||||
|
||||
export let data = null;
|
||||
export function set(val) {
|
||||
data = val;
|
||||
}
|
||||
|
||||
export function verify(user) {
|
||||
Notifications.add("Verifying", 0, 3);
|
||||
data.uid = user.uid;
|
||||
CloudFunctions.verifyUser(data).then((data) => {
|
||||
if (data.data.status === 1) {
|
||||
Notifications.add(data.data.message, 1);
|
||||
DB.getSnapshot().discordId = data.data.did;
|
||||
Settings.updateDiscordSection();
|
||||
} else {
|
||||
Notifications.add(data.data.message, -1);
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import { loadTags } from "./result-filters";
|
||||
import * as AccountButton from "./account-icon";
|
||||
import * as AccountButton from "./account-button";
|
||||
import * as CloudFunctions from "./cloud-functions";
|
||||
import * as Notifications from "./notifications";
|
||||
|
||||
|
|
|
@ -10,3 +10,5 @@ global.snapshot = DB.getSnapshot;
|
|||
global.config = Config;
|
||||
// global.addnotif = Notifications.add;
|
||||
global.link = AccountController.linkWithGoogle;
|
||||
|
||||
global.filters = ResultFilters.filters;
|
||||
|
|
|
@ -24,7 +24,7 @@ import * as Caret from "./caret";
|
|||
import * as ManualRestart from "./manual-restart-tracker";
|
||||
import Config, * as UpdateConfig from "./config";
|
||||
import * as Focus from "./focus";
|
||||
import * as AccountButton from "./account-icon";
|
||||
import * as AccountButton from "./account-button";
|
||||
import * as TestUI from "./test-ui";
|
||||
import * as Keymap from "./keymap";
|
||||
import "./caps-warning";
|
||||
|
@ -52,3 +52,6 @@ import * as ThemePicker from "./theme-picker";
|
|||
import "./custom-theme-popup";
|
||||
import "./import-settings-popup";
|
||||
import * as AllTimeStats from "./all-time-stats";
|
||||
import * as PbTables from "./pb-tables";
|
||||
import * as Account from "./account";
|
||||
import * as VerificationController from "./verification-controller";
|
||||
|
|
|
@ -1,149 +0,0 @@
|
|||
import * as Misc from "./misc";
|
||||
import * as DB from "./db";
|
||||
|
||||
let defaultResultFilters = {
|
||||
difficulty: {
|
||||
normal: true,
|
||||
expert: true,
|
||||
master: true,
|
||||
},
|
||||
mode: {
|
||||
words: true,
|
||||
time: true,
|
||||
quote: true,
|
||||
custom: true,
|
||||
},
|
||||
words: {
|
||||
10: true,
|
||||
25: true,
|
||||
50: true,
|
||||
100: true,
|
||||
200: true,
|
||||
custom: true,
|
||||
},
|
||||
time: {
|
||||
15: true,
|
||||
30: true,
|
||||
60: true,
|
||||
120: true,
|
||||
custom: true,
|
||||
},
|
||||
quoteLength: {
|
||||
short: true,
|
||||
medium: true,
|
||||
long: true,
|
||||
thicc: true,
|
||||
},
|
||||
punctuation: {
|
||||
on: true,
|
||||
off: true,
|
||||
},
|
||||
numbers: {
|
||||
on: true,
|
||||
off: true,
|
||||
},
|
||||
date: {
|
||||
last_day: false,
|
||||
last_week: false,
|
||||
last_month: false,
|
||||
all: true,
|
||||
},
|
||||
tags: {
|
||||
none: true,
|
||||
},
|
||||
language: {},
|
||||
funbox: {
|
||||
none: true,
|
||||
},
|
||||
};
|
||||
|
||||
let filters = defaultResultFilters;
|
||||
|
||||
Misc.getLanguageList().then((languages) => {
|
||||
languages.forEach((language) => {
|
||||
defaultResultFilters.language[language] = true;
|
||||
});
|
||||
});
|
||||
|
||||
Misc.getFunboxList().then((funboxModes) => {
|
||||
funboxModes.forEach((funbox) => {
|
||||
defaultResultFilters.funbox[funbox.name] = true;
|
||||
});
|
||||
});
|
||||
|
||||
export function getFilters() {
|
||||
return filters;
|
||||
}
|
||||
|
||||
export function getGroup(group) {
|
||||
return filters[group];
|
||||
}
|
||||
|
||||
export function setFilter(group, filter, value) {
|
||||
filters[group][filter] = value;
|
||||
}
|
||||
|
||||
export function getFilter(group, filter) {
|
||||
return filters[group][filter];
|
||||
}
|
||||
|
||||
export function toggleFilter(group, filter) {
|
||||
filters[group][filter] = !filters[group][filter];
|
||||
}
|
||||
|
||||
export function loadTags(tags) {
|
||||
tags.forEach((tag) => {
|
||||
defaultResultFilters.tags[tag.id] = true;
|
||||
});
|
||||
}
|
||||
|
||||
export function save() {
|
||||
Misc.setCookie("resultFilters", JSON.stringify(filters), 365);
|
||||
}
|
||||
|
||||
export function load() {
|
||||
// let newTags = $.cookie("activeTags");
|
||||
try {
|
||||
let newResultFilters = Misc.getCookie("resultFilters");
|
||||
if (newResultFilters !== undefined && newResultFilters !== "") {
|
||||
filters = JSON.parse(newResultFilters);
|
||||
save();
|
||||
} else {
|
||||
filters = defaultResultFilters;
|
||||
save();
|
||||
}
|
||||
} catch {
|
||||
filters = defaultResultFilters;
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
export function reset() {
|
||||
filters = defaultResultFilters;
|
||||
save();
|
||||
}
|
||||
|
||||
load();
|
||||
|
||||
export function updateTags() {
|
||||
$(
|
||||
".pageAccount .content .filterButtons .buttonsAndTitle.tags .buttons"
|
||||
).empty();
|
||||
if (DB.getSnapshot().tags.length > 0) {
|
||||
$(".pageAccount .content .filterButtons .buttonsAndTitle.tags").removeClass(
|
||||
"hidden"
|
||||
);
|
||||
$(
|
||||
".pageAccount .content .filterButtons .buttonsAndTitle.tags .buttons"
|
||||
).append(`<div class="button" filter="none">no tag</div>`);
|
||||
DB.getSnapshot().tags.forEach((tag) => {
|
||||
$(
|
||||
".pageAccount .content .filterButtons .buttonsAndTitle.tags .buttons"
|
||||
).append(`<div class="button" filter="${tag.id}">${tag.name}</div>`);
|
||||
});
|
||||
} else {
|
||||
$(".pageAccount .content .filterButtons .buttonsAndTitle.tags").addClass(
|
||||
"hidden"
|
||||
);
|
||||
}
|
||||
}
|
177
src/js/script.js
177
src/js/script.js
|
@ -1,7 +1,6 @@
|
|||
//test timer
|
||||
|
||||
//ui
|
||||
let verifyUserWhenLoggedIn = null;
|
||||
|
||||
///
|
||||
|
||||
|
@ -19,108 +18,19 @@ let verifyUserWhenLoggedIn = null;
|
|||
};
|
||||
})(window.history);
|
||||
|
||||
function changePage(page) {
|
||||
if (UI.pageTransition) {
|
||||
return;
|
||||
}
|
||||
let activePage = $(".page.active");
|
||||
$(".page").removeClass("active");
|
||||
$("#wordsInput").focusout();
|
||||
if (page == "test" || page == "") {
|
||||
UI.setPageTransition(true);
|
||||
UI.swapElements(
|
||||
activePage,
|
||||
$(".page.pageTest"),
|
||||
250,
|
||||
() => {
|
||||
UI.setPageTransition(false);
|
||||
TestUI.focusWords();
|
||||
$(".page.pageTest").addClass("active");
|
||||
history.pushState("/", null, "/");
|
||||
},
|
||||
() => {
|
||||
TestConfig.show();
|
||||
}
|
||||
);
|
||||
SignOutButton.hide();
|
||||
// restartCount = 0;
|
||||
// incompleteTestSeconds = 0;
|
||||
TestStats.resetIncomplete();
|
||||
ManualRestart.set();
|
||||
TestLogic.restart();
|
||||
} else if (page == "about") {
|
||||
UI.setPageTransition(true);
|
||||
TestLogic.restart();
|
||||
UI.swapElements(activePage, $(".page.pageAbout"), 250, () => {
|
||||
UI.setPageTransition(false);
|
||||
history.pushState("about", null, "about");
|
||||
$(".page.pageAbout").addClass("active");
|
||||
});
|
||||
TestConfig.hide();
|
||||
SignOutButton.hide();
|
||||
} else if (page == "settings") {
|
||||
UI.setPageTransition(true);
|
||||
TestLogic.restart();
|
||||
UI.swapElements(activePage, $(".page.pageSettings"), 250, () => {
|
||||
UI.setPageTransition(false);
|
||||
history.pushState("settings", null, "settings");
|
||||
$(".page.pageSettings").addClass("active");
|
||||
});
|
||||
Settings.update();
|
||||
TestConfig.hide();
|
||||
SignOutButton.hide();
|
||||
} else if (page == "account") {
|
||||
if (!firebase.auth().currentUser) {
|
||||
changePage("login");
|
||||
} else {
|
||||
UI.setPageTransition(true);
|
||||
TestLogic.restart();
|
||||
UI.swapElements(
|
||||
activePage,
|
||||
$(".page.pageAccount"),
|
||||
250,
|
||||
() => {
|
||||
UI.setPageTransition(false);
|
||||
history.pushState("account", null, "account");
|
||||
$(".page.pageAccount").addClass("active");
|
||||
},
|
||||
() => {
|
||||
SignOutButton.show();
|
||||
}
|
||||
);
|
||||
refreshAccountPage();
|
||||
TestConfig.hide();
|
||||
}
|
||||
} else if (page == "login") {
|
||||
if (firebase.auth().currentUser != null) {
|
||||
changePage("account");
|
||||
} else {
|
||||
UI.setPageTransition(true);
|
||||
TestLogic.restart();
|
||||
UI.swapElements(activePage, $(".page.pageLogin"), 250, () => {
|
||||
UI.setPageTransition(false);
|
||||
history.pushState("login", null, "login");
|
||||
$(".page.pageLogin").addClass("active");
|
||||
});
|
||||
TestConfig.hide();
|
||||
SignOutButton.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(window).on("popstate", (e) => {
|
||||
let state = e.originalEvent.state;
|
||||
if (state == "" || state == "/") {
|
||||
// show test
|
||||
changePage("test");
|
||||
UI.changePage("test");
|
||||
} else if (state == "about") {
|
||||
// show about
|
||||
changePage("about");
|
||||
UI.changePage("about");
|
||||
} else if (state == "account" || state == "login") {
|
||||
if (firebase.auth().currentUser) {
|
||||
changePage("account");
|
||||
UI.changePage("account");
|
||||
} else {
|
||||
changePage("login");
|
||||
UI.changePage("login");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -289,63 +199,8 @@ function handleTab(event) {
|
|||
}
|
||||
}
|
||||
} else if (Config.quickTab) {
|
||||
changePage("test");
|
||||
UI.changePage("test");
|
||||
}
|
||||
|
||||
// } else if (
|
||||
// !event.ctrlKey &&
|
||||
// (
|
||||
// (!event.shiftKey && !TestLogic.hasTab) ||
|
||||
// (event.shiftKey && TestLogic.hasTab) ||
|
||||
// TestUI.resultVisible
|
||||
// ) &&
|
||||
// Config.quickTab &&
|
||||
// !$(".pageLogin").hasClass("active") &&
|
||||
// !resultCalculating &&
|
||||
// $("#commandLineWrapper").hasClass("hidden") &&
|
||||
// $("#simplePopupWrapper").hasClass("hidden")
|
||||
// ) {
|
||||
// event.preventDefault();
|
||||
// if ($(".pageTest").hasClass("active")) {
|
||||
// if (
|
||||
// (Config.mode === "words" && Config.words < 1000) ||
|
||||
// (Config.mode === "time" && Config.time < 3600) ||
|
||||
// Config.mode === "quote" ||
|
||||
// (Config.mode === "custom" &&
|
||||
// CustomText.isWordRandom &&
|
||||
// CustomText.word < 1000) ||
|
||||
// (Config.mode === "custom" &&
|
||||
// CustomText.isTimeRandom &&
|
||||
// CustomText.time < 3600) ||
|
||||
// (Config.mode === "custom" &&
|
||||
// !CustomText.isWordRandom &&
|
||||
// CustomText.text.length < 1000)
|
||||
// ) {
|
||||
// if (TestLogic.active) {
|
||||
// let testNow = performance.now();
|
||||
// let testSeconds = Misc.roundTo2((testNow - testStart) / 1000);
|
||||
// let afkseconds = keypressPerSecond.filter(
|
||||
// (x) => x.count == 0 && x.mod == 0
|
||||
// ).length;
|
||||
// incompleteTestSeconds += testSeconds - afkseconds;
|
||||
// restartCount++;
|
||||
// }
|
||||
// TestLogic.restart();
|
||||
// } else {
|
||||
// Notifications.add("Quick restart disabled for long tests", 0);
|
||||
// }
|
||||
// } else {
|
||||
// changePage("test");
|
||||
// }
|
||||
// } else if (
|
||||
// !Config.quickTab &&
|
||||
// TestLogic.hasTab &&
|
||||
// event.shiftKey &&
|
||||
// !TestUI.resultVisible
|
||||
// ) {
|
||||
// event.preventDefault();
|
||||
// $("#restartTestButton").focus();
|
||||
// }
|
||||
}
|
||||
|
||||
function handleBackspace(event) {
|
||||
|
@ -969,7 +824,6 @@ function handleAlpha(event) {
|
|||
ManualRestart.set();
|
||||
UpdateConfig.loadFromCookie();
|
||||
Misc.getReleasesFromGitHub();
|
||||
// getPatreonNames();
|
||||
|
||||
let mappedRoutes = {
|
||||
"/": "pageTest",
|
||||
|
@ -1011,10 +865,10 @@ $(document).ready(() => {
|
|||
if (fragment.has("access_token")) {
|
||||
const accessToken = fragment.get("access_token");
|
||||
const tokenType = fragment.get("token_type");
|
||||
verifyUserWhenLoggedIn = {
|
||||
VerificationController.set({
|
||||
accessToken: accessToken,
|
||||
tokenType: tokenType,
|
||||
};
|
||||
});
|
||||
history.replaceState("/", null, "/");
|
||||
}
|
||||
} else if (window.location.pathname === "/account") {
|
||||
|
@ -1024,23 +878,8 @@ $(document).ready(() => {
|
|||
// }
|
||||
} else if (window.location.pathname !== "/") {
|
||||
let page = window.location.pathname.replace("/", "");
|
||||
changePage(page);
|
||||
UI.changePage(page);
|
||||
}
|
||||
});
|
||||
Settings.settingsFillPromise.then(Settings.update);
|
||||
});
|
||||
|
||||
//TODO move after account is a module
|
||||
$(document).on("click", "#top .logo", (e) => {
|
||||
changePage("test");
|
||||
});
|
||||
|
||||
$(document).on("click", "#top #menu .icon-button", (e) => {
|
||||
if ($(e.currentTarget).hasClass("leaderboards")) {
|
||||
Leaderboards.show();
|
||||
} else {
|
||||
const href = $(e.currentTarget).attr("href");
|
||||
ManualRestart.set();
|
||||
changePage(href.replace("/", ""));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -22,7 +22,7 @@ import * as QuoteSearchPopup from "./quote-search-popup";
|
|||
import * as PbCrown from "./pb-crown";
|
||||
import * as TestTimer from "./test-timer";
|
||||
import * as OutOfFocus from "./out-of-focus";
|
||||
import * as AccountButton from "./account-icon";
|
||||
import * as AccountButton from "./account-button";
|
||||
import * as DB from "./db";
|
||||
import * as ThemeColors from "./theme-colors";
|
||||
import * as CloudFunctions from "./cloud-functions";
|
||||
|
|
111
src/js/ui.js
111
src/js/ui.js
|
@ -6,6 +6,14 @@ import * as TestLogic from "./test-logic";
|
|||
import * as CustomText from "./custom-text";
|
||||
import * as CommandlineLists from "./commandline-lists";
|
||||
import * as Commandline from "./commandline";
|
||||
import * as TestUI from "./test-ui";
|
||||
import * as TestConfig from "./test-config";
|
||||
import * as SignOutButton from "./sign-out-button";
|
||||
import * as TestStats from "./test-stats";
|
||||
import * as ManualRestart from "./manual-restart-tracker";
|
||||
import * as Settings from "./settings";
|
||||
import * as Account from "./account";
|
||||
import * as Leaderboards from "./leaderboards";
|
||||
|
||||
export let pageTransition = false;
|
||||
|
||||
|
@ -99,6 +107,95 @@ export function swapElements(
|
|||
}
|
||||
}
|
||||
|
||||
export function changePage(page) {
|
||||
if (pageTransition) {
|
||||
return;
|
||||
}
|
||||
let activePage = $(".page.active");
|
||||
$(".page").removeClass("active");
|
||||
$("#wordsInput").focusout();
|
||||
if (page == "test" || page == "") {
|
||||
setPageTransition(true);
|
||||
swapElements(
|
||||
activePage,
|
||||
$(".page.pageTest"),
|
||||
250,
|
||||
() => {
|
||||
setPageTransition(false);
|
||||
TestUI.focusWords();
|
||||
$(".page.pageTest").addClass("active");
|
||||
history.pushState("/", null, "/");
|
||||
},
|
||||
() => {
|
||||
TestConfig.show();
|
||||
}
|
||||
);
|
||||
SignOutButton.hide();
|
||||
// restartCount = 0;
|
||||
// incompleteTestSeconds = 0;
|
||||
TestStats.resetIncomplete();
|
||||
ManualRestart.set();
|
||||
TestLogic.restart();
|
||||
} else if (page == "about") {
|
||||
setPageTransition(true);
|
||||
TestLogic.restart();
|
||||
swapElements(activePage, $(".page.pageAbout"), 250, () => {
|
||||
setPageTransition(false);
|
||||
history.pushState("about", null, "about");
|
||||
$(".page.pageAbout").addClass("active");
|
||||
});
|
||||
TestConfig.hide();
|
||||
SignOutButton.hide();
|
||||
} else if (page == "settings") {
|
||||
setPageTransition(true);
|
||||
TestLogic.restart();
|
||||
swapElements(activePage, $(".page.pageSettings"), 250, () => {
|
||||
setPageTransition(false);
|
||||
history.pushState("settings", null, "settings");
|
||||
$(".page.pageSettings").addClass("active");
|
||||
});
|
||||
Settings.update();
|
||||
TestConfig.hide();
|
||||
SignOutButton.hide();
|
||||
} else if (page == "account") {
|
||||
if (!firebase.auth().currentUser) {
|
||||
changePage("login");
|
||||
} else {
|
||||
setPageTransition(true);
|
||||
TestLogic.restart();
|
||||
swapElements(
|
||||
activePage,
|
||||
$(".page.pageAccount"),
|
||||
250,
|
||||
() => {
|
||||
setPageTransition(false);
|
||||
history.pushState("account", null, "account");
|
||||
$(".page.pageAccount").addClass("active");
|
||||
},
|
||||
() => {
|
||||
SignOutButton.show();
|
||||
}
|
||||
);
|
||||
Account.update();
|
||||
TestConfig.hide();
|
||||
}
|
||||
} else if (page == "login") {
|
||||
if (firebase.auth().currentUser != null) {
|
||||
changePage("account");
|
||||
} else {
|
||||
setPageTransition(true);
|
||||
TestLogic.restart();
|
||||
swapElements(activePage, $(".page.pageLogin"), 250, () => {
|
||||
setPageTransition(false);
|
||||
history.pushState("login", null, "login");
|
||||
$(".page.pageLogin").addClass("active");
|
||||
});
|
||||
TestConfig.hide();
|
||||
SignOutButton.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (firebase.app().options.projectId === "monkey-type-dev-67af4") {
|
||||
$("#top .logo .bottom").text("monkey-dev");
|
||||
$("head title").text("Monkey Dev");
|
||||
|
@ -191,3 +288,17 @@ window.addEventListener("beforeunload", (event) => {
|
|||
$(window).resize(() => {
|
||||
Caret.updatePosition();
|
||||
});
|
||||
|
||||
$(document).on("click", "#top .logo", (e) => {
|
||||
changePage("test");
|
||||
});
|
||||
|
||||
$(document).on("click", "#top #menu .icon-button", (e) => {
|
||||
if ($(e.currentTarget).hasClass("leaderboards")) {
|
||||
Leaderboards.show();
|
||||
} else {
|
||||
const href = $(e.currentTarget).attr("href");
|
||||
ManualRestart.set();
|
||||
changePage(href.replace("/", ""));
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue