eBay: highlight search keywords in results
Highlights your typed keywords in yellow inside listing titles so exact matches are easier to spot.
Code to copy
// Highlight the searched keywords inside result titles
function highlightKeywords() {
const term = new URL(window.location.href).searchParams.get('_nkw');
if (!term) { return; }
const words = term.toLowerCase().split(/\s+/).filter(function (w) { return w.length > 2; });
if (!words.length) { return; }
document.querySelectorAll('.srp-results .s-item__title:not([data-jz-hl])').forEach(function (el) {
el.setAttribute('data-jz-hl', '1');
let html = el.innerHTML;
words.forEach(function (w) {
const re = new RegExp('(' + w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')', 'gi');
html = html.replace(re, '<mark style="background:#fff176">$1</mark>');
});
el.innerHTML = html;
});
}
highlightKeywords();
const obs = new MutationObserver(highlightKeywords);
obs.observe(document.documentElement, { childList: true, subtree: true });
How to use this example
- Copy the code with the button above.
- Install JustZix (2 minutes) and open the extension on the target page.
- Add a new rule matching that page.
- Paste the code into the rule's JavaScript panel and save — it runs on every page visit.
Rate this example
No ratings yet — be the first.