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) {
|
if (e.keyCode === 13) {
|
||||||
let word = document.getElementById("searchbox").value
|
let word = document.getElementById("searchbox").value
|
||||||
word = word.toLowerCase();
|
word = word.toLowerCase();
|
||||||
|
safe_word = sanitize(word)
|
||||||
if (word === "\\n") {
|
if (word === "\\n") {
|
||||||
window.alert("Nice try...");
|
window.alert("Nice try...");
|
||||||
document.getElementById("searchbox").value = "";
|
document.getElementById("searchbox").value = "";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
safe_word = sanitize(word)
|
if (!safe_word) {
|
||||||
|
window.alert("Illegal character detected")
|
||||||
|
return;
|
||||||
|
}
|
||||||
words.push(word);
|
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>")
|
$("#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 = "";
|
document.getElementById("searchbox").value = "";
|
||||||
@ -166,24 +170,15 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
function sanitize(string) {
|
function sanitize(string) {
|
||||||
const map = {
|
return string.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
|
||||||
'&': '',
|
|
||||||
'<': '',
|
|
||||||
'>': '',
|
|
||||||
'"': '',
|
|
||||||
"'": '',
|
|
||||||
"/": '',
|
|
||||||
};
|
|
||||||
const reg = /[&<>"'/]/ig;
|
|
||||||
string = string.replaceAll("\\", "")
|
|
||||||
return string.replace(reg, (match) => (map[match]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteItem(item) {
|
function deleteItem(item) {
|
||||||
let safe_item = sanitize(item);
|
let safe_item = sanitize(item);
|
||||||
console.log(item)
|
|
||||||
words.splice(words.indexOf(item), 1);
|
words.splice(words.indexOf(item), 1);
|
||||||
|
if (safe_item) {
|
||||||
$("#" + safe_item.replaceAll(" ", "-")).remove();
|
$("#" + safe_item.replaceAll(" ", "-")).remove();
|
||||||
|
}
|
||||||
liveSearch();
|
liveSearch();
|
||||||
localStorage.setItem("words", JSON.stringify(words))
|
localStorage.setItem("words", JSON.stringify(words))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user