Amazon Camel Graph Revived/Fixed

Add CamelCamelCamel graph + link to Amazon product pages.

目前为 2016-11-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Amazon Camel Graph Revived/Fixed
  3. // @version 1.0.8
  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. if (chart=="amazon"||chart=="amazon-new"||chart=="amazon-new-used"||chart=="amazon-used"){
  41. if (!responseDoc.getElementById('price_type_1').disabled) {
  42. $("#averageCustomerReviews_feature_div").append("<div id='camelcamelcamel' style='margin-top: 10px; margin-left: -10px'>" + link2 + "</div>");
  43. chartpost = 1;
  44. }
  45. }
  46.  
  47. if (chart=="new"||chart=="amazon-new"||chart=="amazon-new-used"||chart=="new-used"){
  48. if (!responseDoc.getElementById('price_type_2').disabled && chartpost==0) {
  49. $("#averageCustomerReviews_feature_div").append("<div id='camelcamelcamel' style='margin-top: 10px; margin-left: -10px'>" + link2 + "</div>");
  50. chartpost = 1;
  51. }
  52. }
  53.  
  54.  
  55. if (chart=="used"||chart=="amazon-used"||chart=="amazon-new-used"||chart=="new-used"){
  56. if (!responseDoc.getElementById('price_type_2').disabled && chartpost==0) {
  57. $("#averageCustomerReviews_feature_div").append("<div id='camelcamelcamel' style='margin-top: 10px; margin-left: -10px'>" + link2 + "</div>");
  58.  
  59. }
  60. }
  61.  
  62. }
  63. });
  64.  
  65. function thisCodeProduct () {
  66. var url = unescape(location.href);
  67. var pattern = "http://([a-z]{0,2}).?camelcamelcamel.com/(.*)/product/B([A-Z0-9]{9}).*";
  68. var exp = new RegExp(pattern, "gi");
  69. return url.replace(exp,"$3");
  70. }
  71.  
  72. var url = unescape(location.href);
  73. var pattern = "http://([a-z]{0,2}).?camelcamelcamel.com/.*";
  74. var exp = new RegExp(pattern, "gi");
  75. var code = url.replace(exp,"$1");
  76.  
  77. if (code == '')
  78. code = 'com';
  79. else if (code == 'uk')
  80. code = 'co.uk';
  81.  
  82. $(document).ready(function () {
  83. var links = document.evaluate("//a[contains(@href, 'camelcamelcamel.com')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  84. for (var i = 0; i < links.snapshotLength; i++)
  85. {
  86. var link = links.snapshotItem(i);
  87. if (link.title == 'View the product page at Amazon') {
  88. link.removeAttribute('onclick');
  89. link.href = 'https://www.amazon.'+code+'/dp/B'+thisCodeProduct()+'/';
  90. }
  91. }
  92.  
  93. });
  94.  
  95. (function(doc) {
  96. // ASIN.0 in kindle store
  97. var asin = doc.getElementById("ASIN") || doc.getElementsByName("ASIN.0")[0];
  98. if (asin) {
  99. asin = asin.value
  100. history.replaceState(null, "", "/dp/" + asin + "/");
  101. }
  102.  
  103. })(document);