mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-14 07:54:41 +08:00
Merge pull request #1143 from 0x8b/copy-words-to-clipboard
added ability to copy words to the clipboard
This commit is contained in:
commit
5b051a8781
2 changed files with 48 additions and 0 deletions
|
@ -1174,6 +1174,33 @@ export function updateThemeCommands() {
|
|||
}
|
||||
}
|
||||
|
||||
let commandsCopyWordsToClipboard = {
|
||||
title: "Are you sure...",
|
||||
list: [
|
||||
{
|
||||
id: "copyNo",
|
||||
display: "Nevermind",
|
||||
exec: () => {},
|
||||
},
|
||||
{
|
||||
id: "copyYes",
|
||||
display: "Yes, I am sure",
|
||||
exec: () => {
|
||||
const words = Misc.getWords();
|
||||
|
||||
navigator.clipboard.writeText(words).then(
|
||||
() => {
|
||||
Notifications.add("Copied to clipboard", 1);
|
||||
},
|
||||
() => {
|
||||
Notifications.add("Failed to copy!", -1);
|
||||
}
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export let defaultCommands = {
|
||||
title: "",
|
||||
list: [
|
||||
|
@ -1826,6 +1853,15 @@ export let defaultCommands = {
|
|||
UpdateConfig.toggleMonkey();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "copyWordsToClipboard",
|
||||
display: "Copy words to clipboard",
|
||||
subgroup: true,
|
||||
exec: () => {
|
||||
current.push(commandsCopyWordsToClipboard);
|
||||
Commandline.show();
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
|
|
@ -622,6 +622,18 @@ export function toggleFullscreen(elem) {
|
|||
}
|
||||
}
|
||||
|
||||
export function getWords() {
|
||||
const words = [...document.querySelectorAll("#words .word")]
|
||||
.map((word) => {
|
||||
return [...word.querySelectorAll("letter")]
|
||||
.map((letter) => letter.innerText)
|
||||
.join("");
|
||||
})
|
||||
.join(" ");
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
//credit: https://www.w3resource.com/javascript-exercises/javascript-string-exercise-32.php
|
||||
export function remove_non_ascii(str) {
|
||||
if (str === null || str === "") return false;
|
||||
|
|
Loading…
Reference in a new issue