Last active
December 4, 2024 16:00
-
-
Save gperezmz/9eed8bf96ff5d7f50f00e407f60bf480 to your computer and use it in GitHub Desktop.
UserScript - Loads Keepa price tracker for Amazon domains
This file contains 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
// ==UserScript== | |
// @name Keepa - Price History | |
// @description Loads Keepa price tracker for Amazon domains | |
// @version 2.0.1 | |
// @namespace https://gist.github.com/gperezmz | |
// @match https://www.amazon.*/*/dp/* | |
// @match https://www.amazon.*/dp/* | |
// @match https://www.amazon.*/gp/product/* | |
// @author gperezmz | |
// @license bsd-3-clause | |
// @run-at document-idle | |
// @grant none | |
// ==/UserScript== | |
// User Settings: Modify these variables to customize the Amazon Historical Prices chart | |
const userSettings = { | |
showAmazonPrice: 1, // Amazon price graph: 1 (draw), 0 (do not draw) | |
showNewPrice: 1, // New price graph: 1 (draw), 0 (do not draw) | |
showUsedPrice: 1, // Used price graph: 1 (draw), 0 (do not draw) | |
chartRange: 90, // The range of the chart in days: Suggested values are 1, 2, 7, 31, 90, 365 | |
}; | |
(function () { | |
'use strict'; | |
const style = document.createElement("style"); | |
style.innerHTML = ` | |
.historicalPriceContainer { | |
margin-top: 20px; | |
margin-bottom: 20px; | |
text-align: center; | |
} | |
.historicalPriceChart { | |
width: 100%; | |
height: 100%; | |
object-fit: contain; | |
border-radius: 0!important; | |
} | |
`; | |
document.head.appendChild(style); | |
const memoize = (fn) => { | |
const cache = new Map(); | |
return function (...args) { | |
const key = JSON.stringify(args); | |
if (cache.has(key)) return cache.get(key); | |
const result = fn.apply(this, args); | |
cache.set(key, result); | |
return result; | |
}; | |
}; | |
const getASIN = memoize(() => { | |
const asinElement = document.getElementById("ASIN") || document.querySelector('input[name="ASIN"]'); | |
if (!asinElement) { | |
console.error("Unable to find ASIN on the page."); | |
return null; | |
} | |
return asinElement.value; | |
}); | |
const insertPriceCharts = (asin, tld) => { | |
const keepaCountryCode = { | |
com: "1", | |
uk: "2", | |
de: "3", | |
fr: "4", | |
jp: "5", | |
ca: "6", | |
it: "8", | |
es: "9", | |
in: "10", | |
mx: "11", | |
br: "12", | |
}; | |
const countryCode = keepaCountryCode[tld] || "unsupported"; | |
if (countryCode === "unsupported") { | |
return console.error("This country is not supported by Keepa."); | |
} | |
const historicalPriceContainer = document.createElement("div"); | |
historicalPriceContainer.className = "historicalPriceContainer"; | |
const historicalPriceLink = document.createElement("a"); | |
const historicalPriceChart = new Image(); | |
historicalPriceChart.className = "historicalPriceChart"; | |
historicalPriceChart.loading = "lazy"; | |
const parentElement = | |
document.getElementById("unifiedPrice_feature_div") || | |
document.querySelector("#MediaMatrix"); | |
if (!parentElement) { | |
return console.error("Unable to find a suitable parent element for inserting the price charts."); | |
} | |
historicalPriceLink.target = "_blank"; | |
historicalPriceLink.href = `https://keepa.com/#!product/${countryCode}-${asin}`; | |
historicalPriceChart.src = `https://graph.keepa.com/pricehistory.png?used=${userSettings.showUsedPrice}&asin=${asin}&domain=${tld}&amazon=${userSettings.showAmazonPrice}&new=${userSettings.showNewPrice}&range=${userSettings.chartRange}`; | |
historicalPriceLink.appendChild(historicalPriceChart); | |
historicalPriceContainer.appendChild(historicalPriceLink); | |
parentElement.appendChild(historicalPriceContainer); | |
}; | |
const asin = getASIN(); | |
if (asin) { | |
const tld = document.location.hostname.match('.*\.amazon\.(.*)$')[1]; | |
insertPriceCharts(asin, tld); | |
} | |
})(); |
i ended up just writing my own script, but i don't want to publicly share it because i'm greedy and paranoid about keepa defeating it. clearly, they want users to join their botnet (erm, i mean use their browser extension).
i'd share it with you but don't know how. i hate how github doesn't have PMs. lol i also don't want to publicly share my contact info. i guess if you want it bad enough, leave me a way to contact you. discord preferred. sry
Hi there ! Quite late reply, but I'm still interested 🙃
You can DM me on Discord : _sgta_
Thanks !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i ended up just writing my own script, but i don't want to publicly share it because i'm greedy and paranoid about keepa defeating it. clearly, they want users to join their botnet (erm, i mean use their browser extension).
i'd share it with you but don't know how. i hate how github doesn't have PMs. lol
i also don't want to publicly share my contact info. i guess if you want it bad enough, leave me a way to contact you. discord preferred. sry