Skip to content

Instantly share code, notes, and snippets.

@gperezmz
Last active December 4, 2024 16:00
Show Gist options
  • Save gperezmz/9eed8bf96ff5d7f50f00e407f60bf480 to your computer and use it in GitHub Desktop.
Save gperezmz/9eed8bf96ff5d7f50f00e407f60bf480 to your computer and use it in GitHub Desktop.
UserScript - Loads Keepa price tracker for Amazon domains
// ==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);
}
})();
@ftc2
Copy link

ftc2 commented Apr 12, 2024

hi @gperezmz
are you still using this thing? :)

it looks like keepa got rid of https://keepa.com/iframe_addon.html – it now says "You are using an outdated version of the Keepa extension."

e.g. https://keepa.com/iframe_addon.html#1-0-B0BNGVWL98

the keepa extension now injects https://keepa.com/keepaBox.html instead, but i can't get that to work.

with their extension installed, visiting this url works: https://keepa.com/keepaBox.html#1-0-B0BNGVWL98
however, without it installed, it errors: "Please make sure to exclusively utilize our latest browser extension."

either the ASIN and country code need to be specified some other way than a url fragment, or the browser extension check needs to be defeated somehow...

edit: i ended up fixing it via another method... 🥷

@SonicGold
Copy link

hi @gperezmz are you still using this thing? :)

it looks like keepa got rid of https://keepa.com/iframe_addon.html – it now says "You are using an outdated version of the Keepa extension."

e.g. https://keepa.com/iframe_addon.html#1-0-B0BNGVWL98

the keepa extension now injects https://keepa.com/keepaBox.html instead, but i can't get that to work.

with their extension installed, visiting this url works: https://keepa.com/keepaBox.html#1-0-B0BNGVWL98 however, without it installed, it errors: "Please make sure to exclusively utilize our latest browser extension."

either the ASIN and country code need to be specified some other way than a url fragment, or the browser extension check needs to be defeated somehow...

edit: i ended up fixing it via another method... 🥷

Hi there ! Same issue on my end.
How did you end up fixing the deprecated use of iframe_addon.html ?
Thanks for your help 🙃

@ftc2
Copy link

ftc2 commented May 8, 2024

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

@SonicGold
Copy link

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