34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
// cs-notice.js
|
|
(function () {
|
|
const list = document.querySelector('.notice-list2');
|
|
if (!list) return;
|
|
|
|
const q = (list.getAttribute('data-highlight') || '').trim();
|
|
if (!q) return;
|
|
|
|
const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
const re = new RegExp(escapeRegExp(q), 'ig');
|
|
|
|
document.querySelectorAll('.js-hl').forEach((el) => {
|
|
const text = el.textContent || '';
|
|
if (!re.test(text)) return;
|
|
|
|
// 안전: textContent 기반으로 split -> mark
|
|
const parts = text.split(new RegExp(`(${escapeRegExp(q)})`, 'ig'));
|
|
el.textContent = '';
|
|
parts.forEach((p) => {
|
|
if (p.toLowerCase() === q.toLowerCase()) {
|
|
const mark = document.createElement('mark');
|
|
mark.textContent = p;
|
|
mark.style.background = 'rgba(255,255,255,.14)';
|
|
mark.style.color = 'inherit';
|
|
mark.style.padding = '0 2px';
|
|
mark.style.borderRadius = '6px';
|
|
el.appendChild(mark);
|
|
} else {
|
|
el.appendChild(document.createTextNode(p));
|
|
}
|
|
});
|
|
});
|
|
})();
|