Skip to content

Instantly share code, notes, and snippets.

@remy
Created January 15, 2026 21:55
Show Gist options
  • Select an option

  • Save remy/fe07147ecff299c340644f324cfa509a to your computer and use it in GitHub Desktop.

Select an option

Save remy/fe07147ecff299c340644f324cfa509a to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Amazon UK Search Highlighter
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Highlights search terms in Amazon results
// @match https://www.amazon.co.uk/s*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const urlParams = new URLSearchParams(window.location.search);
const searchQuery = urlParams.get('k');
if (!searchQuery) return;
const searchWords = searchQuery.toLowerCase()
.split(/\s+/)
.filter(word => word.length > 2);
if (searchWords.length === 0) return;
const colours = ['#ff0', '#0f0', '#f0f', '#0ff', '#ffa500'];
function highlightTextNodes(element) {
const walker = document.createTreeWalker(
element,
NodeFilter.SHOW_TEXT,
null,
false
);
const textNodes = [];
let node;
while (node = walker.nextNode()) {
textNodes.push(node);
}
textNodes.forEach(textNode => {
let text = textNode.textContent;
let replaced = false;
searchWords.forEach((word, index) => {
const regex = new RegExp(`(${word})`, 'gi');
if (regex.test(text)) {
const colour = colours[index % colours.length];
text = text.replace(regex,
`<mark style="background: ${colour}; color: #000; font-weight: bold; padding: 2px;">$1</mark>`
);
replaced = true;
}
});
if (replaced) {
const span = document.createElement('span');
span.innerHTML = text;
textNode.parentNode.replaceChild(span, textNode);
}
});
}
// Find all search result items
const resultItems = document.querySelectorAll('[data-component-type="s-search-result"]');
resultItems.forEach(result => {
const resultText = result.textContent.toLowerCase();
// Check if ALL search words are present
const matchesAll = searchWords.every(word => resultText.includes(word));
if (matchesAll) {
result.style.border = '4px solid #00ff00';
result.style.boxShadow = '0 0 10px #00ff00';
result.style.backgroundColor = '#f0fff0';
}
highlightTextNodes(result);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment