diff options
author | Romain Gonçalves <me@rgoncalves.se> | 2024-05-14 18:53:03 +0200 |
---|---|---|
committer | Romain Gonçalves <me@rgoncalves.se> | 2024-05-14 18:53:03 +0200 |
commit | 612dbb6993c8a548744f29a4d15d6b31325357c8 (patch) | |
tree | 0d61cee0ea74ac811268d0ffc00d3d55f7174112 /.config/qutebrowser/greasemonkey/amazon.js | |
parent | 23e2bfd987c430bb41bc7860c46c2f572e9e2db4 (diff) | |
download | dots-612dbb6993c8a548744f29a4d15d6b31325357c8.tar.gz |
Diffstat (limited to '.config/qutebrowser/greasemonkey/amazon.js')
-rwxr-xr-x | .config/qutebrowser/greasemonkey/amazon.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/.config/qutebrowser/greasemonkey/amazon.js b/.config/qutebrowser/greasemonkey/amazon.js new file mode 100755 index 0000000..0edf4fd --- /dev/null +++ b/.config/qutebrowser/greasemonkey/amazon.js @@ -0,0 +1,62 @@ +// ==UserScript== +// @name Amazon CamelCamelCamel + Keepa Price Charts +// @version 1.0.8 +// @description Add a CamelCamelCamel and Keepa price charts to Amazon product pages. +// @author miki.it +// @namespace null +// @homepage https://github.com/mikispag/userscripts/ +// @include https://www.amazon.*/* +// @include https://smile.amazon.*/* +// @run-at document-end +// @downloadURL https://update.greasyfork.org/scripts/416590/Amazon%20CamelCamelCamel%20%2B%20Keepa%20Price%20Charts.user.js +// @updateURL https://update.greasyfork.org/scripts/416590/Amazon%20CamelCamelCamel%20%2B%20Keepa%20Price%20Charts.meta.js +// ==/UserScript== + +function getASIN() { + var asinElement = document.getElementById("ASIN") || document.evaluate("//@data-asin", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; + if (!asinElement) { + throw new Error("Amazon CamelCamelCamel + Keepa Price Charts: unable to find ASIN!"); + } + return asinElement.value; +} + +window.addEventListener("load", function() { + var tld = document.domain.split(".").pop(); + var country = tld; + if (tld == "com") { + country = "us"; + } + + var asin = getASIN(); + if (!asin) { + throw new Error("Amazon CamelCamelCamel + Keepa Price Charts: unable to get ASIN!"); + } + + var parentElement = document.getElementById("unifiedPrice_feature_div") || document.getElementById("MediaMatrix"); + if (!parentElement) { + throw new Error("Amazon CamelCamelCamel + Keepa Price Charts: unable to get parent element!"); + } + + var camelChartContainer = document.createElement("div"); + var camelLink = document.createElement("a"); + camelLink.target = "_blank"; + camelLink.href = "https://" + country + ".camelcamelcamel.com/product/" + asin; + var camelChart = new Image(500, 400); + camelChart.src = "https://charts.camelcamelcamel.com/" + country + "/" + asin + "/amazon-new-used.png?force=1&zero=0&w=500&h=400&desired=false&legend=1&ilt=1&tp=all&fo=0"; + camelLink.appendChild(camelChart); + camelChartContainer.appendChild(camelLink); + + var keepaChartContainer = document.createElement("div"); + var keepaLink = document.createElement("a"); + keepaLink.target = "_blank"; + keepaLink.href = "https://keepa.com/#!product/8-" + asin; + var keepaChart = new Image(500, 200); + keepaChart.src = "https://graph.keepa.com/pricehistory.png?used=1&asin=" + asin + "&domain=" + tld; + keepaLink.appendChild(keepaChart); + keepaChartContainer.appendChild(keepaLink); + + var chartsContainer = document.createElement("div"); + chartsContainer.appendChild(camelChartContainer); + chartsContainer.appendChild(keepaChartContainer); + parentElement.appendChild(chartsContainer); +}, false); |