Amazon short URL

Replace article URL with short Amazon permalink

目前为 2017-10-10 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Amazon short URL
  3. // @namespace graphen
  4. // @description Replace article URL with short Amazon permalink
  5. // @include /^https?:\/\/www\.amazon\.(cn|in|co\.jp|sg|fr|de|it|nl|es|co\.uk|ca|com(.\(mx|au|br)?)\/.*(dp|gp\/product|exec\/obidos\/ASIN|o\/ASIN)\/.*$/
  6. // @noframes
  7. // @grant none
  8. // @version 2
  9. // ==/UserScript==
  10.  
  11. (function (doc) {
  12. var links = document.getElementsByTagName('link');
  13. var i;
  14.  
  15. for (i=0; i < links.length; i++) {
  16. if (links[i].rel == 'canonical') {
  17. var canonical = links[i].href;
  18. var asin = canonical.replace(/https?:\/\/www\.amazon\..*\/dp\/([\w]+)$/, '$1');
  19. if (asin.length == 10) {
  20. history.replaceState(null, 'Amazon URL Cleaner', '/dp/' + asin + '/');
  21. console.log("URL replaced by Amazon URL Cleaner. ASIN: " + asin);
  22. }
  23. }
  24. }
  25. }) (document);