mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-06 05:43:47 +08:00
removed any further non ascii characters, moved function to misc.js
This commit is contained in:
parent
08e374ed1e
commit
dd8855654d
2 changed files with 26 additions and 17 deletions
|
@ -538,3 +538,27 @@ export function toggleFullscreen(elem) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//credit: https://www.w3resource.com/javascript-exercises/javascript-string-exercise-32.php
|
||||
export function remove_non_ascii(str) {
|
||||
if (str === null || str === "") return false;
|
||||
else str = str.toString();
|
||||
|
||||
return str.replace(/[^\x20-\x7E]/g, "");
|
||||
}
|
||||
|
||||
export function cleanTypographySymbols(textToClean) {
|
||||
var specials = {
|
||||
"“": '"', // “ “
|
||||
"”": '"', // ” ”
|
||||
"’": "'", // ‘ ‘
|
||||
"‘": "'", // ’ ’
|
||||
",": ",", // ‚ ‚
|
||||
"—": "-", // — —
|
||||
"…": "...", // … …
|
||||
"«": "<<",
|
||||
"»": ">>",
|
||||
"–": "-",
|
||||
};
|
||||
return textToClean.replace(/[“”’‘—,…«»–]/g, (char) => specials[char] || "");
|
||||
}
|
||||
|
|
|
@ -2954,22 +2954,6 @@ function setCustomText() {
|
|||
}
|
||||
}
|
||||
|
||||
function cleanTypographySymbols(textToClean) {
|
||||
var specials = {
|
||||
"“": '"', // “ “
|
||||
"”": '"', // ” ”
|
||||
"’": "'", // ‘ ‘
|
||||
"‘": "'", // ’ ’
|
||||
",": ",", // ‚ ‚
|
||||
"—": "-", // — —
|
||||
"…": "...", // … …
|
||||
"«": "<<",
|
||||
"»": ">>",
|
||||
"–": "-",
|
||||
};
|
||||
return textToClean.replace(/[“”’‘—,…«»–]/g, (char) => specials[char] || "");
|
||||
}
|
||||
|
||||
function changePage(page) {
|
||||
if (pageTransition) {
|
||||
return;
|
||||
|
@ -3858,8 +3842,9 @@ $("#customTextPopup .button").click(() => {
|
|||
text = text.replace(/[\n\r\t ]/gm, " ");
|
||||
text = text.replace(/ +/gm, " ");
|
||||
if ($("#customTextPopup .typographyCheck input").prop("checked")) {
|
||||
text = cleanTypographySymbols(text);
|
||||
text = Misc.cleanTypographySymbols(text);
|
||||
}
|
||||
text = Misc.remove_non_ascii(text);
|
||||
text = text.split(" ");
|
||||
customText = text;
|
||||
customTextIsRandom = $("#customTextPopup .check input").prop("checked");
|
||||
|
|
Loading…
Reference in a new issue