Created
January 24, 2025 10:34
-
-
Save tomhermans/970568321c12eed6acc4fb112cfdb06e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// manifest.json | |
{ | |
"manifest_version": 3, | |
"name": "Amazon Price Difference Highlighter", | |
"version": "1.0", | |
"description": "Highlights items with significant price differences in Amazon cart", | |
"permissions": ["activeTab"], | |
"content_scripts": [ | |
{ | |
"matches": [ | |
"*://*.amazon.com/*", | |
"*://*.amazon.co.uk/*", | |
"*://*.amazon.de/*", | |
"*://*.amazon.fr/*", | |
"*://*.amazon.nl/*", | |
"*://*.amazon.com.be/*" | |
], | |
} | |
], | |
"icons": { | |
"48": "icon48.png", | |
"128": "icon128.png" | |
} | |
} | |
// content.js | |
function extractPrice(priceText) { | |
// Extract numerical value from price string (assumes € format) | |
return parseFloat(priceText.replace('€', '').trim()); | |
} | |
function addStarToTitle(titleElement) { | |
const star = document.createElement('span'); | |
star.innerHTML = '⭐ '; | |
star.style.color = '#f4c542'; | |
titleElement.insertBefore(star, titleElement.firstChild); | |
} | |
function analyzePriceDifferences() { | |
// Select all price change messages | |
const priceChangeItems = document.querySelectorAll('li span.a-list-item span[data-feature-id="single-imb-message"]'); | |
priceChangeItems.forEach(item => { | |
// Find price elements | |
const prices = item.querySelectorAll('.sc-product-price'); | |
if (prices.length === 2) { | |
const oldPrice = extractPrice(prices[0].textContent); | |
const newPrice = extractPrice(prices[1].textContent); | |
// Calculate price difference | |
const priceDifference = Math.abs(oldPrice - newPrice); | |
// If difference is more than 10 euros, add star | |
if (priceDifference > 10) { | |
const titleElement = item.querySelector('.sc-product-title'); | |
if (titleElement && !titleElement.querySelector('span')) { | |
addStarToTitle(titleElement); | |
} | |
} | |
} | |
}); | |
} | |
// Run the analysis when the page loads | |
analyzePriceDifferences(); | |
// Optional: Run periodically to catch dynamic updates | |
setInterval(analyzePriceDifferences, 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a Chrome extension that analyzes price differences and adds star icons where appropriate, in this case where the price difference is 10 euro. Change that amount at will on line 53.
Take this gist and split it up in two files, a manifest file and a content script that runs on Amazon's cart page.
Add some basic icons (icon48.png and icon128.png) to the directory
Load the extension in Chrome:
Go to chrome://extensions/
Enable "Developer mode" (top right)
Click "Load unpacked"
Select your extension directory