removed any further non ascii characters, moved function to misc.js

This commit is contained in:
Miodec 2021-01-03 22:29:35 +00:00
parent 08e374ed1e
commit dd8855654d
2 changed files with 26 additions and 17 deletions

View file

@ -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] || "");
}

View file

@ -2954,22 +2954,6 @@ function setCustomText() {
}
}
function cleanTypographySymbols(textToClean) {
var specials = {
"“": '"', // &ldquo; &#8220;
"”": '"', // &rdquo; &#8221;
"": "'", // &lsquo; &#8216;
"": "'", // &rsquo; &#8217;
",": ",", // &sbquo; &#8218;
"—": "-", // &mdash; &#8212;
"…": "...", // &hellip; &#8230;
"«": "<<",
"»": ">>",
"": "-",
};
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");