Amazon Camel Graph Revived/Fixed

Add CamelCamelCamel graph + link to Amazon product pages.

当前为 2022-10-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Amazon Camel Graph Revived/Fixed
  3. // @version 1.0.12
  4. // @description Add CamelCamelCamel graph + link to Amazon product pages.
  5. // @namespace null
  6. // @include https://www.amazon.*/*
  7. // @include https://smile.amazon.*/*
  8. // @include https://*.camelcamelcamel.com/*
  9. // @include https://camelcamelcamel.com/*
  10. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
  11. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
  12. // @grant GM_xmlhttpRequest
  13. // ==/UserScript==
  14.  
  15.  
  16. var width = 400;
  17. var height = 250;
  18. var chart = "amazon-new"; //Possible other values are "amazon", "new", "used", "new-used", & "amazon-new-used"
  19.  
  20.  
  21. var arr = document.domain.split(".");
  22. var country = arr[arr.length - 1];
  23. if (country=="com") {country = "us";}
  24.  
  25. var element = $(':input[id="ASIN"]');
  26. var asin = $.trim(element.attr("value"));
  27. if (asin=="") {
  28. element = $(':input[id="ASIN"]');
  29. asin = $.trim(element.attr("value"));
  30. }
  31. 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>";
  32. var camelurl = 'https://' + country + '.camelcamelcamel.com/product/' + asin;
  33. GM_xmlhttpRequest({
  34. method: 'GET',
  35. url: camelurl,
  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: 60%'>" + 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. (function(doc) {
  101. // ASIN.0 in kindle store
  102. var asin = doc.getElementById("ASIN") || doc.getElementsByName("ASIN.0")[0];
  103. if (asin) {
  104. asin = asin.value
  105. history.replaceState(null, "", "/dp/" + asin + "/");
  106. }
  107.  
  108. })(document);