mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-11 22:23:32 +08:00
added quick challenge setup through a url
This commit is contained in:
parent
6602022039
commit
892c78fad0
5 changed files with 272 additions and 1 deletions
|
@ -294,6 +294,12 @@ firebase.auth().onAuthStateChanged(function (user) {
|
|||
setCustomThemeInputs();
|
||||
applyCustomThemeColors();
|
||||
}
|
||||
if (/challenge_.+/g.test(window.location.pathname)) {
|
||||
let challengeName = window.location.pathname.split("_")[1];
|
||||
setTimeout(() => {
|
||||
setupChallenge(challengeName);
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
function getAccountDataAndInit() {
|
||||
|
|
|
@ -84,6 +84,18 @@ export async function getLanguageList() {
|
|||
}
|
||||
}
|
||||
|
||||
let challengeList = null;
|
||||
export async function getChallengeList() {
|
||||
if (challengeList == null) {
|
||||
return $.getJSON("challenges/list.json", function (data) {
|
||||
challengeList = data;
|
||||
return challengeList;
|
||||
});
|
||||
} else {
|
||||
return challengeList;
|
||||
}
|
||||
}
|
||||
|
||||
let currentLanguage = null;
|
||||
|
||||
export function getCurrentLanguage() {
|
||||
|
|
|
@ -287,7 +287,7 @@ function copyResultToClipboard() {
|
|||
}
|
||||
}
|
||||
|
||||
function activateFunbox(funbox, mode) {
|
||||
async function activateFunbox(funbox, mode) {
|
||||
if (testActive || resultVisible) {
|
||||
Misc.showNotification(
|
||||
"You can only change the funbox before starting a test.",
|
||||
|
@ -314,6 +314,11 @@ function activateFunbox(funbox, mode) {
|
|||
$("#words").removeClass("nospace");
|
||||
}
|
||||
|
||||
if (mode === null || mode === undefined) {
|
||||
let list = await Misc.getFunboxList();
|
||||
mode = list.filter((f) => f.name === funbox)[0].type;
|
||||
}
|
||||
|
||||
if (mode === "style") {
|
||||
if (funbox != undefined) {
|
||||
$("#funBoxTheme").attr("href", `funbox/${funbox}.css`);
|
||||
|
@ -4983,6 +4988,74 @@ window.addEventListener("keydown", function (e) {
|
|||
}
|
||||
});
|
||||
|
||||
async function setupChallenge(challengeName) {
|
||||
let list = await Misc.getChallengeList();
|
||||
let challenge = list.filter((c) => c.name === challengeName)[0];
|
||||
let notitext;
|
||||
try {
|
||||
if (challenge === undefined) {
|
||||
throw "Challenge not found";
|
||||
}
|
||||
if (challenge.type === "customTime") {
|
||||
setTimeConfig(challenge.parameters[0], true);
|
||||
setMode("time", true);
|
||||
if (challenge.name === "englishMaster") {
|
||||
setLanguage("english_10k", true);
|
||||
setNumbers(true, true);
|
||||
setPunctuation(true, true);
|
||||
}
|
||||
}
|
||||
if (challenge.type === "customWords") {
|
||||
setWordCount(challenge.parameters[0], true);
|
||||
setMode("words", true);
|
||||
} else if (challenge.type === "customText") {
|
||||
customText = challenge.parameters[0];
|
||||
customTextIsRandom = challenge.parameters[1];
|
||||
customTextWordCount = challenge.parameters[2];
|
||||
setMode("custom", true);
|
||||
} else if (challenge.type === "script") {
|
||||
let scriptdata = await fetch("/challenges/" + challenge.parameters[0]);
|
||||
scriptdata = await scriptdata.text();
|
||||
customText = scriptdata.split(" ");
|
||||
customTextIsRandom = false;
|
||||
setMode("custom", true);
|
||||
if (challenge.parameters[1] != null) {
|
||||
setTheme(challenge.parameters[1]);
|
||||
}
|
||||
if (challenge.parameters[2] != null) {
|
||||
activateFunbox(challenge.parameters[2]);
|
||||
}
|
||||
} else if (challenge.type === "accuracy") {
|
||||
setTimeConfig(0, true);
|
||||
setMode("time", true);
|
||||
setDifficulty("master", true);
|
||||
} else if (challenge.type === "funbox") {
|
||||
activateFunbox(challenge.parameters[0]);
|
||||
if (challenge.parameters[1] === "words") {
|
||||
setWordCount(challenge.parameters[2], true);
|
||||
} else if (challenge.parameters[1] === "time") {
|
||||
setTimeConfig(challenge.parameters[2], true);
|
||||
}
|
||||
setMode(challenge.parameters[1], true);
|
||||
if (challenge.parameters[3] !== undefined) {
|
||||
setDifficulty(challenge.parameters[3], true);
|
||||
}
|
||||
}
|
||||
manualRestart = true;
|
||||
restartTest(false, true);
|
||||
notitext = challenge.message;
|
||||
if (notitext === undefined) {
|
||||
Misc.showNotification(`Challenge '${challengeName}' loaded.`, 3000);
|
||||
} else {
|
||||
Misc.showNotification("Challenge loaded. " + notitext, 5000);
|
||||
}
|
||||
} catch (e) {
|
||||
Misc.showNotification("Something went wrong: " + e, 5000);
|
||||
console.log(e);
|
||||
}
|
||||
// Misc.showNotification("Challenge loaded", 2000);
|
||||
}
|
||||
|
||||
let ctx = $("#wpmChart");
|
||||
let wpmOverTimeChart = new Chart(ctx, {
|
||||
type: "line",
|
||||
|
|
1
static/challenges/inAGalaxyFarFarAway.txt
Normal file
1
static/challenges/inAGalaxyFarFarAway.txt
Normal file
File diff suppressed because one or more lines are too long
179
static/challenges/list.json
Normal file
179
static/challenges/list.json
Normal file
|
@ -0,0 +1,179 @@
|
|||
[
|
||||
{
|
||||
"name": "oneHourWarrior",
|
||||
"type": "customTime",
|
||||
"parameters": [3600]
|
||||
}
|
||||
,{
|
||||
"name": "doubleDown",
|
||||
"type": "customTime",
|
||||
"parameters": [7200]
|
||||
}
|
||||
,{
|
||||
"name": "trueSimp",
|
||||
"type": "customText",
|
||||
"parameters": [["miodec"],true,10000]
|
||||
}
|
||||
,{
|
||||
"name": "simp",
|
||||
"type": "customText",
|
||||
"parameters": [["miodec"],true,1000]
|
||||
}
|
||||
,{
|
||||
"name": "antidiseWhat",
|
||||
"type": "customText",
|
||||
"parameters": [["antidisestablishmentarianism"],true,1]
|
||||
}
|
||||
,{
|
||||
"name": "whatsThisWebsiteCalledAgain",
|
||||
"type": "customText",
|
||||
"parameters": [["monkeytype"],true,1000]
|
||||
}
|
||||
,{
|
||||
"name": "developd",
|
||||
"type": "customText",
|
||||
"parameters": [["develop"],true,1000]
|
||||
}
|
||||
,{
|
||||
"name": "slowAndSteady",
|
||||
"type": "customTime",
|
||||
"parameters": [300]
|
||||
}
|
||||
,{
|
||||
"name": "speedSpacer",
|
||||
"type": "customText",
|
||||
"parameters": [["a b c d e f g h i j k l m n o p q r s t u v w x y z"],true,100]
|
||||
}
|
||||
,{
|
||||
"name": "iveGotThePower",
|
||||
"type": "customText",
|
||||
"parameters": [["power"],true,10]
|
||||
}
|
||||
,{
|
||||
"name": "accuracy",
|
||||
"type": "accuracy",
|
||||
"parameters": []
|
||||
}
|
||||
,{
|
||||
"name": "inAGalaxyFarFarAway",
|
||||
"type": "script",
|
||||
"parameters": ["inAGalaxyFarFarAway.txt",null,"space_balls"]
|
||||
}
|
||||
,{
|
||||
"name": "beLikeWater",
|
||||
"type": "funbox",
|
||||
"parameters": ["layoutfluid","time",60],
|
||||
"message": "Remember: You need to achieve at least 50 wpm in each layout."
|
||||
}
|
||||
,{
|
||||
"name": "rollercoaster",
|
||||
"type": "funbox",
|
||||
"parameters": ["round_round_baby","time",3600]
|
||||
}
|
||||
,{
|
||||
"name": "oneHourMirror",
|
||||
"type": "funbox",
|
||||
"parameters": ["mirror","time",3600]
|
||||
}
|
||||
,{
|
||||
"name": "chooChoo",
|
||||
"type": "funbox",
|
||||
"parameters": ["choo_choo","time",3600]
|
||||
}
|
||||
,{
|
||||
"name": "mnemonist",
|
||||
"type": "funbox",
|
||||
"parameters": ["memory","words",25,"master"]
|
||||
}
|
||||
,{
|
||||
"name": "earfquake",
|
||||
"type": "funbox",
|
||||
"parameters": ["earthquake","time",3600]
|
||||
}
|
||||
,{
|
||||
"name": "simonSez",
|
||||
"type": "funbox",
|
||||
"parameters": ["simon_says","time",3600]
|
||||
}
|
||||
,{
|
||||
"name": "accountant",
|
||||
"type": "funbox",
|
||||
"parameters": ["58008","time",3600]
|
||||
}
|
||||
,{
|
||||
"name": "hidden",
|
||||
"type": "funbox",
|
||||
"parameters": ["read_ahead","time",60]
|
||||
}
|
||||
,{
|
||||
"name": "whatAreWordsAtThisPoint",
|
||||
"type": "funbox",
|
||||
"parameters": ["gibberish","time",3600]
|
||||
}
|
||||
,{
|
||||
"name": "specials",
|
||||
"type": "funbox",
|
||||
"parameters": ["specials","time",3600]
|
||||
}
|
||||
,{
|
||||
"name": "aeiou",
|
||||
"type": "funbox",
|
||||
"parameters": ["tts","time",3600]
|
||||
}
|
||||
,{
|
||||
"name": "asciiWarrior",
|
||||
"type": "funbox",
|
||||
"parameters": ["ascii","time",3600]
|
||||
}
|
||||
,{
|
||||
"name": "iKiNdAlIkEhOwInEfFiCiEnTqWeRtYiS",
|
||||
"type": "funbox",
|
||||
"parameters": ["randomcase","time",3600]
|
||||
}
|
||||
,{
|
||||
"name": "oneNauseousMonkey",
|
||||
"type": "funbox",
|
||||
"parameters": ["nausea","time",3600]
|
||||
}
|
||||
,{
|
||||
"name": "thumbWarrior",
|
||||
"type": "customTime",
|
||||
"parameters": [3600]
|
||||
}
|
||||
,{
|
||||
"name": "mouseWarrior",
|
||||
"type": "customTime",
|
||||
"parameters": [3600]
|
||||
}
|
||||
,{
|
||||
"name": "mobileWarrior",
|
||||
"type": "customTime",
|
||||
"parameters": [3600]
|
||||
}
|
||||
,{
|
||||
"name": "69",
|
||||
"type": "customTime",
|
||||
"parameters": [69],
|
||||
"message": "You need to achieve 69 wpm, 69 raw, 69% accuracy and 69% consistency."
|
||||
}
|
||||
,{
|
||||
"name": "upsideDown",
|
||||
"type": "customTime",
|
||||
"parameters": [60]
|
||||
}
|
||||
,{
|
||||
"name": "oneArmedBandit",
|
||||
"type": "customWords",
|
||||
"parameters": [10000]
|
||||
}
|
||||
,{
|
||||
"name": "englishMaster",
|
||||
"type": "customTime",
|
||||
"parameters": [3600]
|
||||
}
|
||||
,{
|
||||
"name": "feetWarrior",
|
||||
"type": "customTime",
|
||||
"parameters": [3600]
|
||||
}
|
||||
]
|
Loading…
Reference in a new issue