Amazon CamelCamelCamel + Keepa Price Charts

Add a CamelCamelCamel and Keepa price charts to Amazon product pages.

当前为 2020-11-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Amazon CamelCamelCamel + Keepa Price Charts
  3. // @version 1.0.5
  4. // @description Add a CamelCamelCamel and Keepa price charts to Amazon product pages.
  5. // @author miki.it
  6. // @namespace null
  7. // @homepage https://github.com/mikispag/userscripts/
  8. // @include https://www.amazon.*/*
  9. // @include https://smile.amazon.*/*
  10. // ==/UserScript==
  11.  
  12. function getASIN() {
  13. var asinElement = document.getElementById("ASIN") || document.evaluate("//@data-asin", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  14. if (!asinElement) {
  15. throw new Error("Amazon CamelCamelCamel + Keepa Price Charts: unable to find ASIN!");
  16. }
  17. return asinElement.nodeValue;
  18. }
  19.  
  20. var tld = document.domain.split(".").pop();
  21. var country = tld;
  22. if (tld == "com") {
  23. country = "us";
  24. }
  25.  
  26. var asin = getASIN();
  27. if (!asin) {
  28. throw new Error("Amazon CamelCamelCamel + Keepa Price Charts: unable to get ASIN!");
  29. }
  30.  
  31. var parentElement = document.getElementById("unifiedPrice_feature_div") || document.getElementById("MediaMatrix");
  32. if (!parentElement) {
  33. throw new Error("Amazon CamelCamelCamel + Keepa Price Charts: unable to get parent element!");
  34. }
  35.  
  36. var camelChartContainer = document.createElement("div");
  37. var camelLink = document.createElement("a");
  38. camelLink.target = "_blank";
  39. camelLink.href = "https://" + country + ".camelcamelcamel.com/product/" + asin;
  40. var camelChart = new Image(500, 400);
  41. 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";
  42. camelLink.appendChild(camelChart);
  43. camelChartContainer.appendChild(camelLink);
  44.  
  45. var keepaChartContainer = document.createElement("div");
  46. var keepaLink = document.createElement("a");
  47. keepaLink.target = "_blank";
  48. keepaLink.href = "https://keepa.com/#!product/8-" + asin;
  49. var keepaChart = new Image(500, 200);
  50. keepaChart.src = "https://graph.keepa.com/pricehistory.png?used=1&asin=" + asin + "&domain=" + tld;
  51. keepaLink.appendChild(keepaChart);
  52. keepaChartContainer.appendChild(keepaLink);
  53.  
  54. var chartsContainer = document.createElement("div");
  55. chartsContainer.appendChild(camelChartContainer);
  56. chartsContainer.appendChild(keepaChartContainer);
  57. parentElement.appendChild(chartsContainer);