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.

  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.0.1c
  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://gf.qytechs.cn/en/scripts/3908-shorten-amazon-product-links-google-chrome-compatible/
  14. // and https://gf.qytechs.cn/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, Try Prime, or Buy Kindle 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').not('a.nav-link-prime').not(':contains("Buy a Kindle")').each(function(){
  42. var asin = getASIN( $(this).attr('href') );
  43. if ( (asin != null) && (asin != 'B00DBYBNEE') ) {
  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 + '" style="text-decoration:none;">&ndash;</a> <span style="font-size:70%;color:rgb(170, 170, 170)">' + asin + '</span>');
  53. }
  54. });
  55. $('span#btAsinTitle').each(function(){
  56. var asin = getASIN( document.location.href );
  57. if (asin != null) {
  58. $(this).after(' <a href="http://www.amazon.com/dp/' + asin + '" style="text-decoration:none;">&ndash;</a> <span style="font-size:70%;color:rgb(170, 170, 170)">' + asin + '</span>');
  59. }
  60. });
  61.  
  62. // add ASIN after relative product links in carousels (first page only) on individual product pages
  63. $('li.a-carousel-card > div.a-section > a.a-link-normal').each(function(){
  64. var asin = getASIN( $(this).attr('href') );
  65. if (asin != null) {
  66. $(this).after(' <a href="http://www.amazon.com/dp/' + asin + '">&ndash;</a> <span style="font-size:70%;color:rgb(130, 130, 130)">' + asin + '</span>');
  67. }
  68. });
  69.  
  70. // add ASIN after relative product links in 'after viewing this item' at bottom of individual product pages
  71. $('div.asinDetails > a').each(function(){
  72. var asin = getASIN( $(this).attr('href') );
  73. if (asin != null) {
  74. $(this).after(' <a href="http://www.amazon.com/dp/' + asin + '">&ndash;</a> <span style="font-size:70%;color:rgb(130, 130, 130)">' + asin + '</span>');
  75. }
  76. });
  77.  
  78. // add ASIN after relative product links in 'more to explore' on bestsellers pages
  79. $('div.zg_more_item > a').each(function(){
  80. var asin = getASIN( $(this).attr('href') );
  81. if (asin != null) {
  82. $(this).after(' <a href="http://www.amazon.com/dp/' + asin + '">&ndash;</a> <span style="font-size:70%;color:rgb(130, 130, 130)">' + asin + '</span>');
  83. }
  84. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址