mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Fix JS breaking symbols
This commit is contained in:
parent
e576a69d39
commit
241a33542b
@ -151,12 +151,16 @@
|
||||
if (e.keyCode === 13) {
|
||||
let word = document.getElementById("searchbox").value
|
||||
word = word.toLowerCase();
|
||||
safe_word = sanitize(word)
|
||||
if (word === "\\n") {
|
||||
window.alert("Nice try...");
|
||||
document.getElementById("searchbox").value = "";
|
||||
return;
|
||||
}
|
||||
safe_word = sanitize(word)
|
||||
if (!safe_word) {
|
||||
window.alert("Illegal character detected")
|
||||
return;
|
||||
}
|
||||
words.push(word);
|
||||
$("#ignored-words").append("<li id=" + safe_word.replaceAll(" ", "-") + "><div class='card-header header-sm d-flex justify-content-between align-items-center'>" + word + " <button class='btn btn-danger' onclick='deleteItem(" + '"' + word + '"' + ")' ><i class='fas fa-trash'></i></button></div></li>")
|
||||
document.getElementById("searchbox").value = "";
|
||||
@ -166,24 +170,15 @@
|
||||
});
|
||||
|
||||
function sanitize(string) {
|
||||
const map = {
|
||||
'&': '',
|
||||
'<': '',
|
||||
'>': '',
|
||||
'"': '',
|
||||
"'": '',
|
||||
"/": '',
|
||||
};
|
||||
const reg = /[&<>"'/]/ig;
|
||||
string = string.replaceAll("\\", "")
|
||||
return string.replace(reg, (match) => (map[match]));
|
||||
return string.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
|
||||
}
|
||||
|
||||
function deleteItem(item) {
|
||||
let safe_item = sanitize(item);
|
||||
console.log(item)
|
||||
words.splice(words.indexOf(item), 1);
|
||||
if (safe_item) {
|
||||
$("#" + safe_item.replaceAll(" ", "-")).remove();
|
||||
}
|
||||
liveSearch();
|
||||
localStorage.setItem("words", JSON.stringify(words))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user