CH Amazon ASIN Adder

Display ASIN after product links in Amazon.com search results, and after the title on a product page; plus, the dash is a short product link. Note that Amazon often uses AJAX to change search page content without reloading the new URL, in which case you won't see this script's ASINs on the new results; simply hit Refresh/F5 when this happens, and then the ASINs should appear.

目前为 2014-12-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name CH Amazon ASIN Adder
  3. // @author clickhappier
  4. // @namespace clickhappier
  5. // @description Display ASIN after product links in Amazon.com search results, and after the title on a product page; plus, the dash is a short product link. Note that Amazon often uses AJAX to change search page content without reloading the new URL, in which case you won't see this script's ASINs on the new results; simply hit Refresh/F5 when this happens, and then the ASINs should appear.
  6. // @version 1.0c
  7. // @include http://www.amazon.com/*
  8. // @require http://code.jquery.com/jquery-latest.min.js
  9. // @grant GM_log
  10. // ==/UserScript==
  11.  
  12.  
  13. // adapted from https://greasyfork.org/en/scripts/3908-shorten-amazon-product-links-google-chrome-compatible/
  14. // and https://greasyfork.org/en/scripts/6205-mturk-auto-accept-changer-for-mturkgrind-com/
  15.  
  16.  
  17. // create :childof selector - from http://andreasnylin.com/blog/2011/09/jquery-not-child-of/
  18. $.expr[':'].childof = function(obj, index, meta, stack){
  19. return $(obj).parent().is(meta[3]);
  20. };
  21.  
  22. function getASIN(href) {
  23. var asinMatch;
  24. asinMatch = href.match(/\/exec\/obidos\/ASIN\/(\w{10})/i);
  25. if (!asinMatch) { asinMatch = href.match(/\/gp\/product\/(\w{10})/i); }
  26. if (!asinMatch) { asinMatch = href.match(/\/exec\/obidos\/tg\/detail\/\-\/(\w{10})/i); }
  27. if (!asinMatch) { asinMatch = href.match(/\/dp\/(\w{10})/i); }
  28. if (!asinMatch) { return null; }
  29. return asinMatch[1];
  30. }
  31.  
  32. // add ASIN after most absolute product links that aren't an image, price, or Other Colors link
  33. $('a[href*="www.amazon.com/"]').not(':has(img)').not(':has(span.a-color-secondary)').not(':has(span.s-price)').not(':childof(td.toeOurPrice)').each(function(){
  34. var asin = getASIN( $(this).attr('href') );
  35. if (asin != null) {
  36. $(this).after(' <a href="http://www.amazon.com/dp/' + asin + '">&ndash;</a> <span style="font-size:70%;color:rgb(130, 130, 130)">' + asin + '</span>');
  37. }
  38. });
  39.  
  40. // add ASIN after most relative product links that aren't an image, price, Other Colors, or Try Prime link
  41. $('a[href^="/gp/product/"]').not(':has(img)').not(':has(span.a-color-secondary)').not(':has(span.s-price)').not(':childof(td.toeOurPrice)').not('a.nav-prime-try').each(function(){
  42. var asin = getASIN( $(this).attr('href') );
  43. if (asin != null) {
  44. $(this).after(' <a href="http://www.amazon.com/dp/' + asin + '">&ndash;</a> <span style="font-size:70%;color:rgb(130, 130, 130)">' + asin + '</span>');
  45. }
  46. });
  47.  
  48. // add ASIN after top-of-page product title on individual product pages
  49. $('span#productTitle').each(function(){
  50. var asin = getASIN( document.location.href );
  51. if (asin != null) {
  52. $(this).after(' <a href="http://www.amazon.com/dp/' + asin + '">&ndash;</a> <span style="font-size:70%;color:rgb(170, 170, 170)">' + asin + '</span>');
  53. }
  54. });
  55.  
  56. // add ASIN after relative product links in carousels (first page only) on individual product pages
  57. $('li.a-carousel-card > div.a-section > a.a-link-normal').each(function(){
  58. var asin = getASIN( $(this).attr('href') );
  59. if (asin != null) {
  60. $(this).after(' <a href="http://www.amazon.com/dp/' + asin + '">&ndash;</a> <span style="font-size:70%;color:rgb(130, 130, 130)">' + asin + '</span>');
  61. }
  62. });
  63.  
  64. // add ASIN after relative product links in 'after viewing this item' at bottom of individual product pages
  65. $('div.asinDetails > a').each(function(){
  66. var asin = getASIN( $(this).attr('href') );
  67. if (asin != null) {
  68. $(this).after(' <a href="http://www.amazon.com/dp/' + asin + '">&ndash;</a> <span style="font-size:70%;color:rgb(130, 130, 130)">' + asin + '</span>');
  69. }
  70. });
  71.