mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-02 12:00:10 +08:00
Merge branches 'master' and 'master' of https://github.com/Miodec/monkey-type
This commit is contained in:
commit
cc68868a1e
7 changed files with 148 additions and 119 deletions
|
@ -61,7 +61,6 @@ async function getAllUsers() {
|
|||
let ret = [];
|
||||
|
||||
async function getAll(nextPageToken) {
|
||||
|
||||
// List batch of users, 1000 at a time.
|
||||
let listUsersResult = await auth.listUsers(1000, nextPageToken);
|
||||
for (let i = 0; i < listUsersResult.users.length; i++) {
|
||||
|
@ -70,7 +69,7 @@ async function getAllUsers() {
|
|||
//if custom claim is undefined check, if its true then ignore
|
||||
|
||||
// if (loopuser === undefined || loopuser.customClaims === undefined || loopuser.customClaims['nameChecked'] === undefined) {
|
||||
ret.push(listUsersResult.users[i]);
|
||||
ret.push(listUsersResult.users[i]);
|
||||
// }
|
||||
|
||||
// console.log(loopuser.customClaims['asd']);
|
||||
|
@ -105,65 +104,67 @@ function isUsernameValid(name) {
|
|||
return /^[0-9a-zA-Z_.-]+$/.test(name);
|
||||
}
|
||||
|
||||
exports.reserveDisplayName = functions.https.onCall(async (request, response) => {
|
||||
let udata = await db.collection('users').doc(request.uid).get();
|
||||
udata = udata.data();
|
||||
if (request.name.toLowerCase() === udata.name.toLowerCase()) {
|
||||
db.collection('takenNames')
|
||||
.doc(request.name.toLowerCase())
|
||||
.set({
|
||||
taken: true
|
||||
}, { merge: true });
|
||||
exports.reserveDisplayName = functions.https.onCall(
|
||||
async (request, response) => {
|
||||
let udata = await db.collection("users").doc(request.uid).get();
|
||||
udata = udata.data();
|
||||
if (request.name.toLowerCase() === udata.name.toLowerCase()) {
|
||||
db.collection("takenNames").doc(request.name.toLowerCase()).set(
|
||||
{
|
||||
taken: true,
|
||||
},
|
||||
{ merge: true }
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
exports.clearName = functions.auth.user().onDelete((user) => {
|
||||
db.collection('takenNames')
|
||||
.doc(user.displayName.toLowerCase())
|
||||
.delete();
|
||||
db.collection('users')
|
||||
.doc(user.uid)
|
||||
.delete();
|
||||
db.collection("takenNames").doc(user.displayName.toLowerCase()).delete();
|
||||
db.collection("users").doc(user.uid).delete();
|
||||
});
|
||||
|
||||
exports.checkNameAvailability = functions.https.onCall(async (request, response) => {
|
||||
// 1 - available
|
||||
// -1 - unavailable (taken)
|
||||
// -2 - not valid name
|
||||
// -999 - unknown error
|
||||
try {
|
||||
if (!isUsernameValid(request.name)) return -2;
|
||||
exports.checkNameAvailability = functions.https.onCall(
|
||||
async (request, response) => {
|
||||
// 1 - available
|
||||
// -1 - unavailable (taken)
|
||||
// -2 - not valid name
|
||||
// -999 - unknown error
|
||||
try {
|
||||
if (!isUsernameValid(request.name)) return -2;
|
||||
|
||||
let takendata = await db.collection('takenNames')
|
||||
.doc(request.name.toLowerCase())
|
||||
.get();
|
||||
|
||||
takendata = takendata.data();
|
||||
let takendata = await db
|
||||
.collection("takenNames")
|
||||
.doc(request.name.toLowerCase())
|
||||
.get();
|
||||
|
||||
if (takendata !== undefined && takendata.taken) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
takendata = takendata.data();
|
||||
|
||||
if (takendata !== undefined && takendata.taken) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// return getAllNames().then((data) => {
|
||||
// let available = 1;
|
||||
// data.forEach((name) => {
|
||||
// try {
|
||||
// if (name.toLowerCase() === request.name.toLowerCase()) available = -1;
|
||||
// } catch (e) {
|
||||
// //
|
||||
// }
|
||||
// });
|
||||
// return available;
|
||||
// });
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
return -999;
|
||||
}
|
||||
|
||||
// return getAllNames().then((data) => {
|
||||
// let available = 1;
|
||||
// data.forEach((name) => {
|
||||
// try {
|
||||
// if (name.toLowerCase() === request.name.toLowerCase()) available = -1;
|
||||
// } catch (e) {
|
||||
// //
|
||||
// }
|
||||
// });
|
||||
// return available;
|
||||
// });
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
return -999;
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
// exports.changeName = functions.https.onCall((request, response) => {
|
||||
// exports.changeName = functions.https.onCall((request, response) => {
|
||||
// try {
|
||||
// if (!isUsernameValid(request.name)) {
|
||||
// console.warn(
|
||||
|
@ -337,7 +338,7 @@ function checkIfPB(uid, obj, userdata) {
|
|||
acc: obj.acc,
|
||||
raw: obj.rawWpm,
|
||||
timestamp: Date.now(),
|
||||
consistency: obj.consistency
|
||||
consistency: obj.consistency,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -362,7 +363,7 @@ function checkIfPB(uid, obj, userdata) {
|
|||
acc: obj.acc,
|
||||
raw: obj.rawWpm,
|
||||
timestamp: Date.now(),
|
||||
consistency: obj.consistency
|
||||
consistency: obj.consistency,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -413,7 +414,7 @@ function checkIfPB(uid, obj, userdata) {
|
|||
acc: obj.acc,
|
||||
raw: obj.rawWpm,
|
||||
timestamp: Date.now(),
|
||||
consistency: obj.consistency
|
||||
consistency: obj.consistency,
|
||||
});
|
||||
toUpdate = true;
|
||||
}
|
||||
|
@ -429,7 +430,7 @@ function checkIfPB(uid, obj, userdata) {
|
|||
acc: obj.acc,
|
||||
raw: obj.rawWpm,
|
||||
timestamp: Date.now(),
|
||||
consistency: obj.consistency
|
||||
consistency: obj.consistency,
|
||||
},
|
||||
];
|
||||
toUpdate = true;
|
||||
|
@ -573,7 +574,9 @@ exports.verifyUser = functions.https.onRequest(async (request, response) => {
|
|||
}
|
||||
request = request.body.data;
|
||||
if (request.uid == undefined) {
|
||||
response.status(200).send({ data: { status: -1, message: "Need to provide uid" } });
|
||||
response
|
||||
.status(200)
|
||||
.send({ data: { status: -1, message: "Need to provide uid" } });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
@ -585,20 +588,24 @@ exports.verifyUser = functions.https.onRequest(async (request, response) => {
|
|||
.then((res) => res.json())
|
||||
.then(async (res2) => {
|
||||
let did = res2.id;
|
||||
await db.collection('users').doc(request.uid).update({
|
||||
discordId: did
|
||||
})
|
||||
await db.collection("users").doc(request.uid).update({
|
||||
discordId: did,
|
||||
});
|
||||
await db.collection("bot-commands").add({
|
||||
command: "verify",
|
||||
arguments: [did,request.uid],
|
||||
arguments: [did, request.uid],
|
||||
executed: false,
|
||||
requestTimestamp: Date.now(),
|
||||
});
|
||||
response.status(200).send({ data: { status: 1, message: "Verified", did: did } });
|
||||
response
|
||||
.status(200)
|
||||
.send({ data: { status: 1, message: "Verified", did: did } });
|
||||
return;
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error('Something went wrong when trying to verify user ' + e.message);
|
||||
console.error(
|
||||
"Something went wrong when trying to verify user " + e.message
|
||||
);
|
||||
response.status(200).send({ data: { status: -1, message: e.message } });
|
||||
return;
|
||||
});
|
||||
|
@ -612,39 +619,52 @@ function incrementT60Bananas(uid, result, userData) {
|
|||
try {
|
||||
let best60;
|
||||
try {
|
||||
best60 = Math.max(...userData.personalBests.time[60].map(best => best.wpm));
|
||||
best60 = Math.max(
|
||||
...userData.personalBests.time[60].map((best) => best.wpm)
|
||||
);
|
||||
if (!Number.isFinite(best60)) {
|
||||
throw 'Not finite'
|
||||
throw "Not finite";
|
||||
}
|
||||
} catch (e) {
|
||||
best60 = undefined;
|
||||
}
|
||||
|
||||
|
||||
if (best60 != undefined && result.wpm < best60 - best60 * 0.25) {
|
||||
console.log('returning');
|
||||
console.log("returning");
|
||||
return;
|
||||
} else {
|
||||
//increment
|
||||
console.log('checking');
|
||||
db.collection(`users/${uid}/bananas`).doc('bananas').get().then(docRef => {
|
||||
let data = docRef.data();
|
||||
if (data === undefined) {
|
||||
//create doc
|
||||
db.collection(`users/${uid}/bananas`).doc('bananas')
|
||||
.set({
|
||||
t60bananas: 1,
|
||||
}, { merge: true });
|
||||
} else {
|
||||
//increment
|
||||
db.collection(`users/${uid}/bananas`).doc('bananas')
|
||||
.set({
|
||||
t60bananas: admin.firestore.FieldValue.increment(1),
|
||||
}, { merge: true });
|
||||
}
|
||||
})
|
||||
console.log("checking");
|
||||
db.collection(`users/${uid}/bananas`)
|
||||
.doc("bananas")
|
||||
.get()
|
||||
.then((docRef) => {
|
||||
let data = docRef.data();
|
||||
if (data === undefined) {
|
||||
//create doc
|
||||
db.collection(`users/${uid}/bananas`).doc("bananas").set(
|
||||
{
|
||||
t60bananas: 1,
|
||||
},
|
||||
{ merge: true }
|
||||
);
|
||||
} else {
|
||||
//increment
|
||||
db.collection(`users/${uid}/bananas`)
|
||||
.doc("bananas")
|
||||
.set(
|
||||
{
|
||||
t60bananas: admin.firestore.FieldValue.increment(1),
|
||||
},
|
||||
{ merge: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('something went wrong when trying to increment bananas ' + e.message);
|
||||
console.log(
|
||||
"something went wrong when trying to increment bananas " + e.message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1525,8 +1525,8 @@ key {
|
|||
flex-direction: row-reverse;
|
||||
}
|
||||
}
|
||||
&.withLigatures{
|
||||
letter{
|
||||
&.withLigatures {
|
||||
letter {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
|
@ -1808,9 +1808,9 @@ key {
|
|||
border-bottom: 2px solid var(--error-color);
|
||||
text-shadow: 1px 0px 0px var(--bg-color),
|
||||
// 2px 0px 0px var(--bg-color),
|
||||
-1px 0px 0px var(--bg-color),
|
||||
-1px 0px 0px var(--bg-color),
|
||||
// -2px 0px 0px var(--bg-color),
|
||||
0px 1px 0px var(--bg-color),
|
||||
0px 1px 0px var(--bg-color),
|
||||
1px 1px 0px var(--bg-color), -1px 1px 0px var(--bg-color);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<div id="backgroundLoader" style="display: none;"></div>
|
||||
<div id="backgroundLoader" style="display: none"></div>
|
||||
<div
|
||||
class="nameChangeMessage"
|
||||
style="
|
||||
|
@ -840,7 +840,7 @@
|
|||
</div>
|
||||
|
||||
<div class="config">
|
||||
<div style="display: grid; grid-auto-flow: column;">
|
||||
<div style="display: grid; grid-auto-flow: column">
|
||||
<div class="group punctuationMode">
|
||||
<!-- <div class="title">time</div> -->
|
||||
<div class="buttons">
|
||||
|
@ -916,7 +916,7 @@
|
|||
</div>
|
||||
<div
|
||||
class="signOut hidden"
|
||||
style="grid-column: 3/4; grid-row: 1/2;"
|
||||
style="grid-column: 3/4; grid-row: 1/2"
|
||||
tabindex="0"
|
||||
>
|
||||
<i class="fas fa-sign-out-alt"></i>
|
||||
|
@ -1171,7 +1171,7 @@
|
|||
<div class="group testType">
|
||||
<div class="top">test type</div>
|
||||
<div class="bottom">-</div>
|
||||
<div class="tags" style="margin-top: 0.5rem;">
|
||||
<div class="tags" style="margin-top: 0.5rem">
|
||||
<div class="top">tags</div>
|
||||
<div class="bottom">-</div>
|
||||
</div>
|
||||
|
@ -1238,7 +1238,7 @@
|
|||
class="icon-button"
|
||||
aria-label="Copy words list"
|
||||
data-balloon-pos="up"
|
||||
style="display: inline-block;"
|
||||
style="display: inline-block"
|
||||
>
|
||||
<i class="fas fa-copy"></i>
|
||||
</span>
|
||||
|
@ -1473,7 +1473,7 @@
|
|||
<a
|
||||
class="button"
|
||||
href="https://discord.com/api/oauth2/authorize?client_id=757704816532258856&redirect_uri=https%3A%2F%2Fmonkeytype.com%2Fverify&response_type=token&scope=identify"
|
||||
style="text-decoration: none;"
|
||||
style="text-decoration: none"
|
||||
>
|
||||
Verify with Discord
|
||||
</a>
|
||||
|
@ -2567,7 +2567,7 @@
|
|||
<div
|
||||
class="button"
|
||||
id="loadCustomColorsFromPreset"
|
||||
style="grid-column: 1/3;"
|
||||
style="grid-column: 1/3"
|
||||
>
|
||||
load from preset
|
||||
</div>
|
||||
|
@ -2748,7 +2748,7 @@
|
|||
|
||||
I've contacted Google to get this sorted out - don't worry, the site is safe."
|
||||
data-balloon-length="xlarge"
|
||||
style="text-align: center; margin-top: 1rem; grid-column: 1/3;"
|
||||
style="text-align: center; margin-top: 1rem; grid-column: 1/3"
|
||||
>
|
||||
Returning Chrome Users
|
||||
<br />
|
||||
|
@ -2785,7 +2785,7 @@
|
|||
</div>
|
||||
<div class="group">
|
||||
<div class="title">personal bests</div>
|
||||
<div style="display: grid; grid-auto-flow: column; gap: 1rem;">
|
||||
<div style="display: grid; grid-auto-flow: column; gap: 1rem">
|
||||
<div class="titleAndTable timePbTable">
|
||||
<table width="100%">
|
||||
<thead>
|
||||
|
@ -2874,7 +2874,7 @@
|
|||
>
|
||||
set filters to current settings
|
||||
</div> -->
|
||||
<div class="buttonsAndTitle" style="grid-column: 1/3;">
|
||||
<div class="buttonsAndTitle" style="grid-column: 1/3">
|
||||
<div class="title">filters</div>
|
||||
<div class="buttons">
|
||||
<div class="button allFilters">all</div>
|
||||
|
@ -2884,7 +2884,7 @@
|
|||
</div>
|
||||
<div
|
||||
class="buttonsAndTitle testDate"
|
||||
style="grid-column: 1/3; margin-top: 1rem;"
|
||||
style="grid-column: 1/3; margin-top: 1rem"
|
||||
>
|
||||
<!-- <div class="title">date</div> -->
|
||||
<div class="buttons filterGroup" group="date">
|
||||
|
@ -2895,8 +2895,8 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="group filterButtons" style="display: none;">
|
||||
<div class="buttonsAndTitle" style="grid-column: 1/3;">
|
||||
<div class="group filterButtons" style="display: none">
|
||||
<div class="buttonsAndTitle" style="grid-column: 1/3">
|
||||
<div class="title">advanced filters</div>
|
||||
<div class="buttons">
|
||||
<div class="button noFilters">clear filters</div>
|
||||
|
@ -2953,15 +2953,15 @@
|
|||
<div class="button" filter="off">off</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="buttonsAndTitle tags" style="grid-column: 1/3;">
|
||||
<div class="buttonsAndTitle tags" style="grid-column: 1/3">
|
||||
<div class="title">tags</div>
|
||||
<div class="buttons filterGroup" group="tags"></div>
|
||||
</div>
|
||||
<div class="buttonsAndTitle languages" style="grid-column: 1/3;">
|
||||
<div class="buttonsAndTitle languages" style="grid-column: 1/3">
|
||||
<div class="title">language</div>
|
||||
<div class="buttons filterGroup" group="language"></div>
|
||||
</div>
|
||||
<div class="buttonsAndTitle funbox" style="grid-column: 1/3;">
|
||||
<div class="buttonsAndTitle funbox" style="grid-column: 1/3">
|
||||
<div class="title">funbox</div>
|
||||
<div class="buttons filterGroup" group="funbox"></div>
|
||||
</div>
|
||||
|
@ -2974,7 +2974,7 @@
|
|||
<i class="fas fa-fw fa-spin fa-circle-notch"></i>
|
||||
</div> -->
|
||||
<div class="above"></div>
|
||||
<div class="chart" style="height: 400px;">
|
||||
<div class="chart" style="height: 400px">
|
||||
<canvas id="resultHistoryChart"></canvas>
|
||||
</div>
|
||||
<div class="below">
|
||||
|
@ -2992,7 +2992,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="group dailyActivityChart">
|
||||
<div class="chart" style="height: 200px;">
|
||||
<div class="chart" style="height: 200px">
|
||||
<canvas id="activityChart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1510,7 +1510,7 @@ if (Object.keys(layouts).length > 0) {
|
|||
id: "changeLayout" + capitalizeFirstLetter(layout),
|
||||
display: layout.replace(/_/g, " "),
|
||||
exec: () => {
|
||||
changeLayout(layout);
|
||||
changeSavedLayout(layout);
|
||||
restartTest();
|
||||
saveConfigToCookie();
|
||||
},
|
||||
|
|
|
@ -358,6 +358,7 @@ function activateFunbox(funbox, mode) {
|
|||
if (funbox !== "layoutfluid" || mode !== "script") {
|
||||
if (config.layout !== config.savedLayout) {
|
||||
changeLayout(config.savedLayout);
|
||||
settingsGroups.layout.updateButton();
|
||||
}
|
||||
}
|
||||
updateTestModesNotice();
|
||||
|
@ -4630,16 +4631,16 @@ $(document).keypress(function (event) {
|
|||
$(document).keydown((event) => {
|
||||
keypressStats.duration.current = performance.now();
|
||||
// if ($(".pageTest").hasClass("active")) {
|
||||
try {
|
||||
if (
|
||||
!config.capsLockBackspace &&
|
||||
event.originalEvent.getModifierState("CapsLock")
|
||||
) {
|
||||
showCapsWarning();
|
||||
} else {
|
||||
hideCapsWarning();
|
||||
}
|
||||
} catch (e) {}
|
||||
try {
|
||||
if (
|
||||
!config.capsLockBackspace &&
|
||||
event.originalEvent.getModifierState("CapsLock")
|
||||
) {
|
||||
showCapsWarning();
|
||||
} else {
|
||||
hideCapsWarning();
|
||||
}
|
||||
} catch (e) {}
|
||||
// }
|
||||
});
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ settingsGroups.capsLockBackspace = new SettingsGroup(
|
|||
"capsLockBackspace",
|
||||
setCapsLockBackspace
|
||||
);
|
||||
settingsGroups.layout = new SettingsGroup("layout", changeLayout);
|
||||
settingsGroups.layout = new SettingsGroup("layout", changeSavedLayout);
|
||||
settingsGroups.language = new SettingsGroup("language", changeLanguage);
|
||||
settingsGroups.fontSize = new SettingsGroup("fontSize", changeFontSize);
|
||||
settingsGroups.pageWidth = new SettingsGroup("pageWidth", setPageWidth);
|
||||
|
|
|
@ -167,7 +167,7 @@ function applyConfig(configObj) {
|
|||
changeWordCount(configObj.words, true);
|
||||
changeLanguage(configObj.language, true);
|
||||
setCapsLockBackspace(configObj.capsLockBackspace, true);
|
||||
changeLayout(configObj.savedLayout, true);
|
||||
changeSavedLayout(configObj.savedLayout, true);
|
||||
changeFontSize(configObj.fontSize, true);
|
||||
setFreedomMode(configObj.freedomMode, true);
|
||||
setCaretStyle(configObj.caretStyle, true);
|
||||
|
@ -1181,6 +1181,14 @@ function changeLayout(layout, nosave) {
|
|||
if (!nosave) saveConfigToCookie();
|
||||
}
|
||||
|
||||
function changeSavedLayout(layout, nosave) {
|
||||
if (layout == null || layout == undefined) {
|
||||
layout = "qwerty";
|
||||
}
|
||||
config.savedLayout = layout;
|
||||
changeLayout(layout, nosave);
|
||||
}
|
||||
|
||||
function changeKeymapMode(mode, nosave) {
|
||||
if (mode == null || mode == undefined) {
|
||||
mode = "off";
|
||||
|
|
Loading…
Reference in a new issue