Use My Amazon Affiliate Code

Puts your own Amazon affiliate ID in Amazon links

目前为 2018-08-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Use My Amazon Affiliate Code
  3. // @namespace http://www.lysator.liu.se/~jhs/userscript
  4. // @description Puts your own Amazon affiliate ID in Amazon links
  5. // @include http://*
  6. // @include https://*
  7. // @version 0.0.1.20180814201445
  8. // ==/UserScript==
  9.  
  10. // leave intact to sponsor my scripting, or set to your own:
  11. const affiliate = 'skeagxmvv-20';
  12. const at_amazon = /(.*\.)?amazon\.(com|[a-z]{2}(\.[a-z]{2})?)$/i;
  13. const aff_links = /(obidos.(ASIN.{12}([^\/]*(=|%3D)[^\/]*\/)*|redirect[^\/]*.(tag=)?))[^\/&]+/i;
  14.  
  15. if( location.hostname.match( at_amazon ) )
  16. return;
  17.  
  18. var i, l, p;
  19. for( i=0; l=document.links[i]; i++ )
  20. {
  21. if( !l.hostname.match( at_amazon ) || !l.hostname.match( /^www\./i ) )
  22. continue;
  23. if( l.href.match( aff_links ) )
  24. l.href = l.href.replace( aff_links, '$1'+affiliate );
  25. else if( !l.search )
  26. {
  27. p = encodeURIComponent( l.pathname.substring( 1 ) + l.search );
  28. l.search = '?tag='+ affiliate +'&path='+ p;
  29. l.pathname = '/exec/obidos/redirect';
  30. }
  31. }