diff --git a/functions/index.js b/functions/index.js index 057468cf7..9bede8782 100644 --- a/functions/index.js +++ b/functions/index.js @@ -898,7 +898,10 @@ exports.saveConfig = functions.https.onCall((request, response) => { { merge: true } ) .then((e) => { - return 1; + return { + returnCode: 1, + message: "Saved", + }; }) .catch((e) => { console.error( diff --git a/public/index.html b/public/index.html index 191edcf5a..ce9149193 100644 --- a/public/index.html +++ b/public/index.html @@ -1509,6 +1509,21 @@ +
+

play sound on error

+
+ Plays a short sound if you press an incorrect key or press space + too early. +
+
+
+ off +
+
+ on +
+
+

tags

diff --git a/public/js/script.js b/public/js/script.js index 5dc3b5253..ac584a8a2 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -59,6 +59,8 @@ let keypressStats = { }, }; +let errorSound = new Audio("../sound/error.wav"); + let customText = "The quick brown fox jumps over the lazy dog".split(" "); let customTextIsRandom = false; let customTextWordCount = 1; @@ -3055,6 +3057,12 @@ function hideCustomMode2Popup() { } } +function playErrorSound() { + if (!config.playSoundOnError) return; + errorSound.currentTime = 0; + errorSound.play(); +} + $("#customMode2PopupWrapper").click((e) => { if ($(e.target).attr("id") === "customMode2PopupWrapper") { hideCustomMode2Popup(); @@ -3331,6 +3339,7 @@ $(document).keypress(function (event) { accuracyStats.incorrect++; currentErrorCount++; thisCharCorrect = false; + playErrorSound(); } else { accuracyStats.correct++; thisCharCorrect = true; @@ -3632,6 +3641,7 @@ $(document).keydown((event) => { updateCaretPosition(); currentKeypressCount++; } else { + playErrorSound(); accuracyStats.incorrect++; if (config.stopOnError) { if (config.difficulty == "expert" || config.difficulty == "master") { diff --git a/public/js/settings.js b/public/js/settings.js index f93095d5d..c90892b09 100644 --- a/public/js/settings.js +++ b/public/js/settings.js @@ -151,6 +151,10 @@ settingsGroups.colorfulMode = new SettingsGroup( ); settingsGroups.randomTheme = new SettingsGroup("randomTheme", setRandomTheme); settingsGroups.stopOnError = new SettingsGroup("stopOnError", setStopOnError); +settingsGroups.stopOnError = new SettingsGroup( + "playSoundOnError", + setPlaySoundOnError +); settingsGroups.showAllLines = new SettingsGroup( "showAllLines", setShowAllLines diff --git a/public/js/userconfig.js b/public/js/userconfig.js index 8b8affff8..636b93a4d 100644 --- a/public/js/userconfig.js +++ b/public/js/userconfig.js @@ -46,6 +46,7 @@ let defaultConfig = { smoothLineScroll: false, alwaysShowDecimalPlaces: false, alwaysShowWordsHistory: false, + playSoundOnError: false, }; let cookieConfig = null; @@ -82,6 +83,7 @@ async function saveConfigToDB() { accountIconLoading(true); saveConfig({ uid: firebase.auth().currentUser.uid, obj: config }).then( (d) => { + console.log(d.data); accountIconLoading(false); if (d.data.returnCode === 1) { // showNotification('config saved to db',1000); @@ -159,6 +161,7 @@ function applyConfig(configObj) { setShowTimerProgress(configObj.showTimerProgress, true); setAlwaysShowDecimalPlaces(config.alwaysShowDecimalPlaces, true); setAlwaysShowWordsHistory(config.alwaysShowWordsHistory, true); + setPlaySoundOnError(config.playSoundOnError, true); // if ( // configObj.resultFilters !== null && // configObj.resultFilters !== undefined @@ -193,6 +196,14 @@ function hideTestConfig() { $("#top .config").css("opacity", 0).addClass("hidden"); } +function setPlaySoundOnError(val, nosave) { + if (val == undefined) { + val = false; + } + config.playSoundOnError = val; + if (!nosave) saveConfigToCookie(); +} + //difficulty function setDifficulty(diff, nosave) { if ( diff --git a/public/sound/error.wav b/public/sound/error.wav new file mode 100644 index 000000000..00556e829 Binary files /dev/null and b/public/sound/error.wav differ