diff --git a/src/js/commandline-lists.js b/src/js/commandline-lists.js
index ed2da742a..195d3fae3 100644
--- a/src/js/commandline-lists.js
+++ b/src/js/commandline-lists.js
@@ -126,7 +126,7 @@ let commandsFunbox = {
id: "changeFunboxNone",
display: "none",
exec: () => {
- if (Funbox.activate("none", null)) {
+ if (Funbox.setFunbox("none", null)) {
TestLogic.restart();
}
},
@@ -140,7 +140,7 @@ Misc.getFunboxList().then((funboxes) => {
id: "changeFunbox" + funbox.name,
display: funbox.name.replace(/_/g, " "),
exec: () => {
- if (Funbox.activate(funbox.name, funbox.type)) {
+ if (Funbox.setFunbox(funbox.name, funbox.type)) {
TestLogic.restart();
}
},
diff --git a/src/js/settings.js b/src/js/settings.js
index 41a142d83..405b46c10 100644
--- a/src/js/settings.js
+++ b/src/js/settings.js
@@ -428,7 +428,7 @@ export function updateDiscordSection() {
function setActiveFunboxButton() {
$(`.pageSettings .section.funbox .button`).removeClass("active");
$(
- `.pageSettings .section.funbox .button[funbox='${Funbox.active}']`
+ `.pageSettings .section.funbox .button[funbox='${Funbox.funboxSaved}']`
).addClass("active");
}
@@ -624,7 +624,7 @@ $(".pageSettings .section.discordIntegration #unlinkDiscordButton").click(
$(document).on("click", ".pageSettings .section.funbox .button", (e) => {
let funbox = $(e.currentTarget).attr("funbox");
let type = $(e.currentTarget).attr("type");
- Funbox.activate(funbox, type);
+ Funbox.setFunbox(funbox, type);
setActiveFunboxButton();
});
diff --git a/src/js/test/funbox.js b/src/js/test/funbox.js
index 38fee9ba2..9d97494f0 100644
--- a/src/js/test/funbox.js
+++ b/src/js/test/funbox.js
@@ -7,6 +7,8 @@ import Config, * as UpdateConfig from "./config";
import * as Settings from "./settings";
export let active = "none";
+export let funboxSaved = "none";
+export let modeSaved = null;
let memoryTimer = null;
let memoryInterval = null;
@@ -71,12 +73,8 @@ export function toggleScript(...params) {
}
export async function activate(funbox, mode) {
- if (TestLogic.active || TestUI.resultVisible) {
- Notifications.add(
- "You can only change the funbox before starting a test.",
- 0
- );
- return false;
+ if (funbox === undefined || funbox === null) {
+ funbox = funboxSaved;
}
if (Misc.getCurrentLanguage().ligatures) {
if (funbox == "choo_choo" || funbox == "earthquake") {
@@ -96,8 +94,12 @@ export async function activate(funbox, mode) {
$("#wordsWrapper").removeClass("hidden");
// }
-
- if (mode === null || mode === undefined) {
+ if (funbox === "none" && mode === undefined) {
+ mode = null;
+ } else if (
+ (funbox !== "none" && mode === undefined) ||
+ (funbox !== "none" && mode === null)
+ ) {
let list = await Misc.getFunboxList();
mode = list.filter((f) => f.name === funbox)[0].type;
}
@@ -162,3 +164,16 @@ export async function activate(funbox, mode) {
TestUI.updateModesNotice();
return true;
}
+export function setFunbox(funbox, mode) {
+ if (TestLogic.active || TestUI.resultVisible) {
+ Notifications.add(
+ "You can only change the funbox before starting a test.",
+ 0
+ );
+ return false;
+ }
+ funboxSaved = funbox;
+ modeSaved = mode;
+ active = funbox;
+ return true;
+}
diff --git a/src/js/test/test-logic.js b/src/js/test/test-logic.js
index a6a18cbbb..68c478ff3 100644
--- a/src/js/test/test-logic.js
+++ b/src/js/test/test-logic.js
@@ -576,6 +576,9 @@ export async function init() {
// } else {
TestUI.showWords();
// }
+ if ($(".pageTest").hasClass("active")) {
+ Funbox.activate();
+ }
}
export function restart(withSameWordset = false, nosave = false, event) {
@@ -697,6 +700,7 @@ export function restart(withSameWordset = false, nosave = false, event) {
input.reset();
PaceCaret.init();
TestUI.showWords();
+ Funbox.activate();
}
if (Config.mode === "quote") {
setRepeated(false);
@@ -924,6 +928,7 @@ export function finish(difficultyFailed = false) {
LiveAcc.hide();
TimerProgress.hide();
Keymap.hide();
+ Funbox.activate("none", null);
let stats = TestStats.calculateStats();
if (stats === undefined) {
stats = {
@@ -1653,8 +1658,8 @@ export function finish(difficultyFailed = false) {
if (Config.blindMode) {
testType += "
blind";
}
- if (Funbox.active !== "none") {
- testType += "
" + Funbox.active.replace(/_/g, " ");
+ if (Funbox.funboxSaved !== "none") {
+ testType += "
" + Funbox.funboxSaved.replace(/_/g, " ");
}
if (Config.difficulty == "expert") {
testType += "
expert";
diff --git a/src/js/ui.js b/src/js/ui.js
index 16a6b634a..dfc1ab06c 100644
--- a/src/js/ui.js
+++ b/src/js/ui.js
@@ -14,6 +14,7 @@ import * as ManualRestart from "./manual-restart-tracker";
import * as Settings from "./settings";
import * as Account from "./account";
import * as Leaderboards from "./leaderboards";
+import * as Funbox from "./funbox";
export let pageTransition = false;
@@ -136,6 +137,7 @@ export function changePage(page) {
TestStats.resetIncomplete();
ManualRestart.set();
TestLogic.restart();
+ Funbox.activate(Funbox.funboxSaved, Funbox.modeSaved);
} else if (page == "about") {
setPageTransition(true);
TestLogic.restart();
@@ -144,6 +146,7 @@ export function changePage(page) {
history.pushState("about", null, "about");
$(".page.pageAbout").addClass("active");
});
+ Funbox.activate("none", null);
TestConfig.hide();
SignOutButton.hide();
} else if (page == "settings") {
@@ -154,6 +157,7 @@ export function changePage(page) {
history.pushState("settings", null, "settings");
$(".page.pageSettings").addClass("active");
});
+ Funbox.activate("none", null);
Settings.update();
TestConfig.hide();
SignOutButton.hide();
@@ -176,6 +180,7 @@ export function changePage(page) {
SignOutButton.show();
}
);
+ Funbox.activate("none", null);
Account.update();
TestConfig.hide();
}
@@ -190,6 +195,7 @@ export function changePage(page) {
history.pushState("login", null, "login");
$(".page.pageLogin").addClass("active");
});
+ Funbox.activate("none", null);
TestConfig.hide();
SignOutButton.hide();
}