@@ -51,13 +51,17 @@ document.addEventListener('DOMContentLoaded', (event) => {
51
51
const table = document .querySelector (' table' );
52
52
const rows = table .querySelectorAll (' tr' );
53
53
54
+ function removeAccents (str ) {
55
+ return str .normalize (" NFD" ).replace (/ [\u0300 -\u036f ] / g , " " );
56
+ }
57
+
54
58
function performSearch () {
55
- const searchTerm = searchInput .value .toLowerCase ();
59
+ const searchTerm = removeAccents ( searchInput .value .toLowerCase () );
56
60
57
61
rows .forEach ((row , index ) => {
58
62
if (index === 0 ) return ; // Skip header row
59
63
60
- const name = row .cells [0 ].textContent .toLowerCase ();
64
+ const name = removeAccents ( row .cells [0 ].textContent .toLowerCase () );
61
65
const uvaId = row .cells [1 ].textContent .toLowerCase ();
62
66
63
67
if (name .includes (searchTerm) || uvaId .includes (searchTerm)) {
@@ -73,10 +77,19 @@ document.addEventListener('DOMContentLoaded', (event) => {
73
77
[0 , 1 ].forEach (cellIndex => {
74
78
const cell = row .cells [cellIndex];
75
79
const originalText = cell .textContent ;
76
- const highlightedText = originalText .replace (
77
- new RegExp (searchTerm, ' gi' ),
78
- match => ` <span class="highlight">${ match} </span>`
79
- );
80
+ const normalizedText = removeAccents (originalText);
81
+ let highlightedText = ' ' ;
82
+ let lastIndex = 0 ;
83
+
84
+ const regex = new RegExp (searchTerm, ' gi' );
85
+ let match;
86
+ while ((match = regex .exec (normalizedText)) !== null ) {
87
+ highlightedText += originalText .slice (lastIndex, match .index );
88
+ highlightedText += ` <span class="highlight">${ originalText .slice (match .index , match .index + match[0 ].length )} </span>` ;
89
+ lastIndex = match .index + match[0 ].length ;
90
+ }
91
+ highlightedText += originalText .slice (lastIndex);
92
+
80
93
cell .innerHTML = highlightedText;
81
94
});
82
95
}
0 commit comments