mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 15:26:15 +08:00
fix: copy words command not working (fehmer) (#5400)
This commit is contained in:
parent
85502eae53
commit
65dffce716
|
@ -1,34 +1,10 @@
|
|||
import * as TestLogic from "../../test/test-logic";
|
||||
import * as TestUI from "../../test/test-ui";
|
||||
import * as PractiseWords from "../../test/practise-words";
|
||||
import * as GetText from "../../utils/generate";
|
||||
import * as Notifications from "../../elements/notifications";
|
||||
|
||||
const copyWords: MonkeyTypes.CommandsSubgroup = {
|
||||
title: "Are you sure...",
|
||||
list: [
|
||||
{
|
||||
id: "copyNo",
|
||||
display: "Nevermind",
|
||||
},
|
||||
{
|
||||
id: "copyYes",
|
||||
display: "Yes, I am sure",
|
||||
exec: (): void => {
|
||||
const words = GetText.getWords();
|
||||
|
||||
navigator.clipboard.writeText(words).then(
|
||||
() => {
|
||||
Notifications.add("Copied to clipboard", 1);
|
||||
},
|
||||
() => {
|
||||
Notifications.add("Failed to copy!", -1);
|
||||
}
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
import * as TestInput from "../../test/test-input";
|
||||
import * as TestWords from "../../test/test-words";
|
||||
import Config from "../../config";
|
||||
|
||||
const practiceSubgroup: MonkeyTypes.CommandsSubgroup = {
|
||||
title: "Practice words...",
|
||||
|
@ -130,7 +106,22 @@ const commands: MonkeyTypes.Command[] = [
|
|||
id: "copyWordsToClipboard",
|
||||
display: "Copy words to clipboard",
|
||||
icon: "fa-copy",
|
||||
subgroup: copyWords,
|
||||
exec: (): void => {
|
||||
const words = (
|
||||
Config.mode === "zen"
|
||||
? TestInput.input.history
|
||||
: TestWords.words.list.slice(0, TestInput.input.history.length)
|
||||
).join(" ");
|
||||
|
||||
navigator.clipboard.writeText(words).then(
|
||||
() => {
|
||||
Notifications.add("Copied to clipboard", 1);
|
||||
},
|
||||
() => {
|
||||
Notifications.add("Failed to copy!", -1);
|
||||
}
|
||||
);
|
||||
},
|
||||
available: (): boolean => {
|
||||
return TestUI.resultVisible;
|
||||
},
|
||||
|
|
|
@ -97,22 +97,6 @@ export function getGibberish(): string {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the words from the HTML elements with IDs "words" and returns them as a string.
|
||||
* @returns The words extracted from the HTML elements.
|
||||
*/
|
||||
export function getWords(): string {
|
||||
const words = [...document.querySelectorAll("#words .word")]
|
||||
.map((word) => {
|
||||
return [...word.querySelectorAll("letter")]
|
||||
.map((letter) => letter.textContent)
|
||||
.join("");
|
||||
})
|
||||
.join(" ");
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random ASCII string of printable characters.
|
||||
* @returns The generated ASCII string.
|
||||
|
|
Loading…
Reference in a new issue