Amazon Camel Graph Revived/Fixed

Add CamelCamelCamel graph + link to Amazon product pages.

  1. // ==UserScript==
  2. // @name Amazon Camel Graph Revived/Fixed
  3. // @version 1.0.14
  4. // @description Add CamelCamelCamel graph + link to Amazon product pages.
  5. // @namespace null
  6. // @include https://www.amazon.*/*
  7. // @include https://smile.amazon.*/*
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
  10. // @grant GM_xmlhttpRequest
  11. // @grant GM_getValue
  12. // ==/UserScript==
  13.  
  14. var width = GM_getValue("width", 400);
  15. var height = GM_getValue("height", 250);
  16. var maxwidth = GM_getValue("maxwidth", 400);
  17. var chart = GM_getValue("chart", "amazon-new-used"); //Possible other values are "amazon", "new", "used", "new-used", & "amazon-new-used"
  18.  
  19. var arr = document.domain.split(".");
  20. var country = arr[arr.length - 1];
  21. if (country=="com") {country = "us";}
  22.  
  23. var element = $(':input[id="ASIN"]');
  24. var asin = $.trim(element.attr("value"));
  25.  
  26. if (asin=="") {
  27. element = $(':input[id="ASIN"]');
  28. asin = $.trim(element.attr("value"));
  29. }
  30. var link2 = "<a target='blank' href='https://" + country + ".camelcamelcamel.com/product/" + asin + "'><img src='https://charts.camelcamelcamel.com/" + country + "/" + asin + "/" + chart + ".png?force=1&zero=0&w=" + width + "&h=" + height + "&desired=false&legend=1&ilt=1&tp=all&fo=0' /></a>";
  31. var camelurl = 'https://' + country + '.camelcamelcamel.com/product/' + asin;
  32. GM_xmlhttpRequest({
  33. method: 'GET',
  34. url: camelurl,
  35.  
  36. onload: function(response) {
  37.  
  38. var parser = new DOMParser ();
  39. var responseDoc = parser.parseFromString (response.responseText, "text/html");
  40. var chartpost = 0;
  41.  
  42. /* if (chart=="amazon"||chart=="amazon-new"||chart=="amazon-new-used"||chart=="amazon-used"){
  43. if (!responseDoc.getElementById('price_type_1').disabled) {
  44. $("#averageCustomerReviews_feature_div").append("<div id='camelcamelcamel' style='margin-top: 10px; margin-left: -10px'>" + link2 + "</div>");
  45. chartpost = 1;
  46. }
  47. }
  48.  
  49. if (chart=="new"||chart=="amazon-new"||chart=="amazon-new-used"||chart=="new-used"){
  50. if (!responseDoc.getElementById('price_type_2').disabled && chartpost==0) {
  51. $("#averageCustomerReviews_feature_div").append("<div id='camelcamelcamel' style='margin-top: 10px; margin-left: -10px'>" + link2 + "</div>");
  52. chartpost = 1;
  53. }
  54. }
  55.  
  56.  
  57. if (chart=="used"||chart=="amazon-used"||chart=="amazon-new-used"||chart=="new-used"){
  58. if (!responseDoc.getElementById('price_type_2').disabled && chartpost==0) {
  59. $("#averageCustomerReviews_feature_div").append("<div id='camelcamelcamel' style='margin-top: 10px; margin-left: -10px'>" + link2 + "</div>");
  60.  
  61. }
  62. } */
  63.  
  64. /* Block comment above replaced by */
  65. $("#unifiedPrice_feature_div").append("<div id='camelcamelcamel' style='margin-top: 10px; margin-left: -10px; max-width: " + maxwidth +"%'>" + link2 + "</div>");
  66.  
  67. }
  68. });
  69.  
  70. function thisCodeProduct () {
  71. var url = unescape(location.href);
  72. var pattern = "https://([a-z]{0,2}).?camelcamelcamel.com/(.*)/product/B([A-Z0-9]{9}).*";
  73. var exp = new RegExp(pattern, "gi");
  74. return url.replace(exp,"$3");
  75. }
  76.  
  77. var url = unescape(location.href);
  78. var pattern = "https://([a-z]{0,2}).?camelcamelcamel.com/.*";
  79. var exp = new RegExp(pattern, "gi");
  80. var code = url.replace(exp,"$1");
  81.  
  82. if (code == '')
  83. code = 'com';
  84. else if (code == 'uk')
  85. code = 'co.uk';
  86.  
  87. $(document).ready(function () {
  88. var links = document.evaluate("//a[contains(@href, 'camelcamelcamel.com')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  89. for (var i = 0; i < links.snapshotLength; i++)
  90. {
  91. var link = links.snapshotItem(i);
  92. if (link.title == 'View the product page at Amazon') {
  93. link.removeAttribute('onclick');
  94. link.href = 'https://www.amazon.'+code+'/dp/B'+thisCodeProduct()+'/';
  95. }
  96. }
  97.  
  98.  
  99.  
  100. });
  101.  
  102. (function(doc) {
  103. // ASIN.0 in kindle store
  104. var asin = doc.getElementById("ASIN") || doc.getElementsByName("ASIN.0")[0];
  105. if (asin) {
  106. asin = asin.value
  107. history.replaceState(null, "", "/dp/" + asin + "/");
  108. }
  109.  
  110. })(document);