diff --git a/js/base.php b/js/base.php index 1fb1102..5d49c86 100644 --- a/js/base.php +++ b/js/base.php @@ -131,6 +131,14 @@ function remove_accents(str) { return str.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); } +function insert_string(main_string, ins_string, pos) { + if (typeof(pos) == undefined) + pos = 0; + if (typeof(ins_string) == undefined) + ins_string = ''; + return main_string.slice(0, pos) + ins_string + main_string.slice(pos); +} + function normalize_for_search(str) { if (str.trim() === '') return ''; str = str.trim().replaceAll(/\s\s+/g, ' '); @@ -140,7 +148,7 @@ function normalize_for_search(str) { var word = words[i]; word = remove_accents(word); word = word.toLowerCase(); - word = word.replaceAll(/[^a-z0-9]+/g, ''); + word = word.replaceAll(/[^a-z0-9]+/g, ' '); if (word.trim() === '') continue; word = word.replaceAll('4','a'); diff --git a/views/instance.php b/views/instance.php index fe871d2..8124bf8 100644 --- a/views/instance.php +++ b/views/instance.php @@ -75,10 +75,25 @@ window.view.instance = { case 'has': case 'includes': case 'contains': - // TODO: implement contains "sr" - break; case 'regex': - // TODO: implement regex "sr" + var t = remove_accents(html); + t = t.replace(/[^a-zA-Z0-9]/g, ' '); + t = t.toLowerCase(); + content = content.replace(/\s+/g, ' ') + .trim().replaceAll(' ', '.'); + content = content.replace(/\w/g, + function(m) { return m+'+?'}); + var n = 0; + console.log(content); + t.replace(new RegExp(content), function(m) { + var st = t.indexOf(m, n); + var en = st + m.length; + const inj_st = ''; + const inj_en = ''; + html = insert_string(html, inj_st, st); + html = insert_string(html, inj_en, en + inj_st.length); + n = t.indexOf(m) + m.length; + }); break; } }