mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-27 17:27:32 +08:00
added opposite shift mode. coses #1059
This commit is contained in:
parent
9fc71e1956
commit
7890fd7777
8 changed files with 172 additions and 0 deletions
|
|
@ -97,6 +97,7 @@ const refactoredSrc = [
|
|||
"./src/js/leaderboards.js",
|
||||
"./src/js/sound.js",
|
||||
"./src/js/custom-text.js",
|
||||
"./src/js/shift-tracker.js",
|
||||
];
|
||||
|
||||
//legacy files
|
||||
|
|
|
|||
|
|
@ -304,6 +304,15 @@ let commands = {
|
|||
showCommandLine();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "changeOppositeShiftMode",
|
||||
display: "Change opposite shift mode...",
|
||||
subgroup: true,
|
||||
exec: () => {
|
||||
currentCommands.push(commandsOppositeShiftMode);
|
||||
showCommandLine();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "togglePlaySoundOnError",
|
||||
display: "Toggle play sound on error",
|
||||
|
|
@ -779,6 +788,26 @@ let commandsRepeatQuotes = {
|
|||
],
|
||||
};
|
||||
|
||||
let commandsOppositeShiftMode = {
|
||||
title: "Change opposite shift mode...",
|
||||
list: [
|
||||
{
|
||||
id: "setOppositeShiftModeOff",
|
||||
display: "off",
|
||||
exec: () => {
|
||||
setOppositeShiftMode("off");
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "setOppositeShiftModeOn",
|
||||
display: "on",
|
||||
exec: () => {
|
||||
setOppositeShiftMode("on");
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
let commandsKeymapMode = {
|
||||
title: "Change keymap mode...",
|
||||
list: [
|
||||
|
|
|
|||
|
|
@ -30,3 +30,4 @@ import * as ResultFilters from "./result-filters";
|
|||
import * as Leaderboards from "./leaderboards";
|
||||
import * as Sound from "./sound";
|
||||
import * as CustomText from "./custom-text";
|
||||
import * as ShiftTracker from "./shift-tracker";
|
||||
|
|
|
|||
|
|
@ -2982,6 +2982,7 @@ function restartTest(withSameWordset = false, nosave = false, event) {
|
|||
missedWords = {};
|
||||
correctedHistory = [];
|
||||
currentCorrected = "";
|
||||
ShiftTracker.reset();
|
||||
setFocus(false);
|
||||
hideCaret();
|
||||
testActive = false;
|
||||
|
|
@ -3899,6 +3900,12 @@ function updateTestModesNotice() {
|
|||
);
|
||||
}
|
||||
|
||||
if (config.oppositeShiftMode === "on") {
|
||||
$(".pageTest #testModesNotice").append(
|
||||
`<div class="text-button" commands="commandsOppositeShiftMode"><i class="fas fa-exchange-alt"></i>opposite shift</div>`
|
||||
);
|
||||
}
|
||||
|
||||
let tagsString = "";
|
||||
try {
|
||||
db_getSnapshot().tags.forEach((tag) => {
|
||||
|
|
@ -5473,6 +5480,9 @@ function handleAlpha(event) {
|
|||
)
|
||||
return;
|
||||
if (event.metaKey) return;
|
||||
|
||||
let originalEvent = event;
|
||||
|
||||
event = emulateLayout(event);
|
||||
|
||||
//start the test
|
||||
|
|
@ -5555,6 +5565,13 @@ function handleAlpha(event) {
|
|||
thisCharCorrect = true;
|
||||
}
|
||||
|
||||
if (
|
||||
config.oppositeShiftMode === "on" &&
|
||||
ShiftTracker.isUsingOppositeShift(originalEvent) === false
|
||||
) {
|
||||
thisCharCorrect = false;
|
||||
}
|
||||
|
||||
if (!thisCharCorrect) {
|
||||
accuracyStats.incorrect++;
|
||||
currentError.count++;
|
||||
|
|
@ -5586,6 +5603,12 @@ function handleAlpha(event) {
|
|||
}
|
||||
}
|
||||
|
||||
if (
|
||||
config.oppositeShiftMode === "on" &&
|
||||
ShiftTracker.isUsingOppositeShift(originalEvent) === false
|
||||
)
|
||||
return;
|
||||
|
||||
//update current corrected verison. if its empty then add the current key. if its not then replace the last character with the currently pressed one / add it
|
||||
if (currentCorrected === "") {
|
||||
currentCorrected = currentInput + event["key"];
|
||||
|
|
|
|||
|
|
@ -134,6 +134,10 @@ settingsGroups.freedomMode = new SettingsGroup(
|
|||
}
|
||||
);
|
||||
settingsGroups.strictSpace = new SettingsGroup("strictSpace", setStrictSpace);
|
||||
settingsGroups.oppositeShiftMode = new SettingsGroup(
|
||||
"oppositeShiftMode",
|
||||
setOppositeShiftMode
|
||||
);
|
||||
settingsGroups.confidenceMode = new SettingsGroup(
|
||||
"confidenceMode",
|
||||
setConfidenceMode,
|
||||
|
|
|
|||
72
src/js/shift-tracker.js
Normal file
72
src/js/shift-tracker.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
export let leftState = false;
|
||||
export let rightState = false;
|
||||
|
||||
$(document).keydown((e) => {
|
||||
if (e.code === "ShiftLeft") {
|
||||
leftState = true;
|
||||
} else if (e.code === "ShiftRight") {
|
||||
rightState = true;
|
||||
}
|
||||
});
|
||||
|
||||
$(document).keyup((e) => {
|
||||
if (e.code === "ShiftLeft") {
|
||||
leftState = false;
|
||||
} else if (e.code === "ShiftRight") {
|
||||
rightState = false;
|
||||
}
|
||||
});
|
||||
|
||||
export function reset() {
|
||||
leftState = false;
|
||||
rightState = false;
|
||||
}
|
||||
|
||||
let leftSideKeys = [
|
||||
"KeyQ",
|
||||
"KeyW",
|
||||
"KeyE",
|
||||
"KeyR",
|
||||
"KeyT",
|
||||
|
||||
"KeyA",
|
||||
"KeyS",
|
||||
"KeyD",
|
||||
"KeyF",
|
||||
"KeyG",
|
||||
|
||||
"KeyZ",
|
||||
"KeyX",
|
||||
"KeyC",
|
||||
"KeyV",
|
||||
];
|
||||
|
||||
let rightSideKeys = [
|
||||
"KeyU",
|
||||
"KeyI",
|
||||
"KeyO",
|
||||
"KeyP",
|
||||
|
||||
"KeyH",
|
||||
"KeyJ",
|
||||
"KeyK",
|
||||
"KeyL",
|
||||
|
||||
"KeyN",
|
||||
"KeyM",
|
||||
];
|
||||
|
||||
export function isUsingOppositeShift(event) {
|
||||
if (!leftState && !rightState) return null;
|
||||
if (!rightSideKeys.includes(event.code) && !leftSideKeys.includes(event.code))
|
||||
return null;
|
||||
|
||||
if (
|
||||
(leftState && rightSideKeys.includes(event.code)) ||
|
||||
(rightState && leftSideKeys.includes(event.code))
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -76,6 +76,7 @@ let defaultConfig = {
|
|||
showLiveAcc: false,
|
||||
monkey: false,
|
||||
repeatQuotes: "off",
|
||||
oppositeShiftMode: "off",
|
||||
};
|
||||
|
||||
let cookieConfig = null;
|
||||
|
|
@ -579,6 +580,15 @@ function toggleStrictSpace() {
|
|||
saveConfigToCookie();
|
||||
}
|
||||
|
||||
//opposite shift space
|
||||
function setOppositeShiftMode(val, nosave) {
|
||||
if (val == undefined) {
|
||||
val = "off";
|
||||
}
|
||||
config.oppositeShiftMode = val;
|
||||
if (!nosave) saveConfigToCookie();
|
||||
}
|
||||
|
||||
function setPageWidth(val, nosave) {
|
||||
if (val == null || val == undefined) {
|
||||
val = "100";
|
||||
|
|
@ -1609,6 +1619,7 @@ function applyConfig(configObj) {
|
|||
setHideExtraLetters(configObj.hideExtraLetters, true);
|
||||
setStartGraphsAtZero(configObj.startGraphsAtZero, true);
|
||||
setStrictSpace(configObj.strictSpace, true);
|
||||
setOppositeShiftMode(configObj.oppositeShiftMode, true);
|
||||
setMode(configObj.mode, true);
|
||||
setMonkey(configObj.monkey, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -1938,6 +1938,37 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section oppositeShiftMode">
|
||||
<h1>opposite shift mode</h1>
|
||||
<div class="text">
|
||||
This mode will force you to use opposite
|
||||
<key>shift</key>
|
||||
keys for capitalisation. Using an incorrect one will count as
|
||||
an error. This feature ignores keys in locations
|
||||
<key>B</key>
|
||||
and
|
||||
<key>Y</key>
|
||||
because many people use the other hand for those keys.
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<div
|
||||
class="button"
|
||||
oppositeShiftMode="off"
|
||||
tabindex="0"
|
||||
onclick="this.blur();"
|
||||
>
|
||||
off
|
||||
</div>
|
||||
<div
|
||||
class="button"
|
||||
oppositeShiftMode="on"
|
||||
tabindex="0"
|
||||
onclick="this.blur();"
|
||||
>
|
||||
on
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section stopOnError">
|
||||
<h1>stop on error</h1>
|
||||
<div class="text">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue