AMZONsampleADDER

Adds send sample button after amazon links (FOR BOOKS)

  1. // ==UserScript==
  2. // @name AMZONsampleADDER
  3. // @namespace Andrew
  4. // @description Adds send sample button after amazon links (FOR BOOKS)
  5. // @include http://www.amazon.com.au/*
  6. // @version 1
  7. // @require http://code.jquery.com/jquery-latest.min.js
  8. // @grant GM_log
  9. // ==/UserScript==
  10.  
  11. // adapted from https://greasyfork.org/en/scripts/6862-ch-amazon-asin-adder
  12.  
  13.  
  14. // create :childof selector - from http://andreasnylin.com/blog/2011/09/jquery-not-child-of/
  15. $.expr[':'].childof = function(obj, index, meta, stack){
  16. return $(obj).parent().is(meta[3]);
  17. };
  18.  
  19. // create variables for sample request so far i havnt implemented scraping so youll have to fin them on your own. HINT just go to the sample request link and see what they are.
  20. //
  21. //!!!!RIGHT HERE!!!!
  22. //
  23. var name = '';
  24. var Name = '';
  25. var device = '';
  26.  
  27. // get the ASIN
  28. function getASIN(href) {
  29. var asinMatch;
  30. asinMatch = href.match(/\/exec\/obidos\/ASIN\/(\w{10})/i);
  31. if (!asinMatch) { asinMatch = href.match(/\/gp\/product\/(\w{10})/i); }
  32. if (!asinMatch) { asinMatch = href.match(/\/exec\/obidos\/tg\/detail\/\-\/(\w{10})/i); }
  33. if (!asinMatch) { asinMatch = href.match(/\/dp\/(\w{10})/i); }
  34. if (!asinMatch) { return null; }
  35. return asinMatch[1];
  36. }
  37.  
  38. // add ASIN after most absolute product links that aren't an image, price, or Other Colors link
  39. $('a[href*="www.amazon.com.au/"]').not(':has(img)').not(':has(span.a-color-secondary)').not(':has(span.s-price)').not(':childof(td.toeOurPrice)').each(function(){
  40. var asin = getASIN( $(this).attr('href') );
  41. if (asin != null) {
  42. $(this).after(' <a href="http://www.amazon.com.au/gp/digital/' + name + '/clarification/sample-downloaded?ie=UTF8&action=&asin=' + asin + '&target' + Name + '=' + device + '">&ndash; <span style="color:rgb(130, 130, 130)"> Send Sample </span> </a>');
  43. }
  44. });
  45.  
  46. // add ASIN after most relative product links that aren't an image, price, Other Colors, Try Prime, or Buy Kindle link
  47. $('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(){
  48. var asin = getASIN( $(this).attr('href') );
  49. if ( (asin != null) && (asin != 'B00DBYBNEE') ) {
  50. $(this).after(' <a href="http://www.amazon.com.au/gp/digital/' + name + '/clarification/sample-downloaded?ie=UTF8&action=&asin=' + asin + '&target' + Name + '=' + device + '">&ndash; <span style="color:rgb(130, 130, 130)"> Send Sample </span> </a>');
  51. }
  52. });
  53.  
  54. // add ASIN after top-of-page product title on individual product pages
  55. $('span#productTitle').each(function(){
  56. var asin = getASIN( document.location.href );
  57. if (asin != null) {
  58. $(this).after(' <a href="http://www.amazon.com.au/gp/digital/' + name + '/clarification/sample-downloaded?ie=UTF8&action=&asin=' + asin + '&target' + Name + '=' + device + '">&ndash; <span style="color:rgb(130, 130, 130)"> Send Sample </span> </a>');
  59. }
  60. });
  61. $('span#btAsinTitle').each(function(){
  62. var asin = getASIN( document.location.href );
  63. if (asin != null) {
  64. $(this).after(' <a href="http://www.amazon.com.au/gp/digital/' + name + '/clarification/sample-downloaded?ie=UTF8&action=&asin=' + asin + '&target' + Name + '=' + device + '">&ndash; <span style="color:rgb(130, 130, 130)"> Send Sample </span> </a>');
  65. }
  66. });
  67.  
  68. // add ASIN after relative product links in carousels (first page only) on individual product pages
  69. $('li.a-carousel-card > div.a-section > a.a-link-normal').each(function(){
  70. var asin = getASIN( $(this).attr('href') );
  71. if (asin != null) {
  72. $(this).after(' <a href="http://www.amazon.com.au/gp/digital/' + name + '/clarification/sample-downloaded?ie=UTF8&action=&asin=' + asin + '&target' + Name + '=' + device + '">&ndash; <span style="color:rgb(130, 130, 130)"> Send Sample </span> </a>');
  73. }
  74. });
  75.  
  76. // add ASIN after relative product links in 'after viewing this item' at bottom of individual product pages
  77. $('div.asinDetails > a').each(function(){
  78. var asin = getASIN( $(this).attr('href') );
  79. if (asin != null) {
  80. $(this).after(' <a href="http://www.amazon.com.au/gp/digital/' + name + '/clarification/sample-downloaded?ie=UTF8&action=&asin=' + asin + '&target' + Name + '=' + device + '">&ndash; <span style="color:rgb(130, 130, 130)"> Send Sample </span> </a>');
  81. }
  82. });
  83.  
  84. // add ASIN after relative product links in 'more to explore' on bestsellers pages
  85. $('div.zg_more_item > a').each(function(){
  86. var asin = getASIN( $(this).attr('href') );
  87. if (asin != null) {
  88. $(this).after(' <a href="http://www.amazon.com.au/gp/digital/' + name + '/clarification/sample-downloaded?ie=UTF8&action=&asin=' + asin + '&target' + Name + '=' + device + '">&ndash; <span style="color:rgb(130, 130, 130)"> Send Sample </span> </a>');
  89. }
  90. });