Amazon Camel Graph Revived/Fixed

Add CamelCamelCamel graph + link to Amazon product pages.

当前为 2017-07-28 提交的版本,查看 最新版本

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