Amazon short URL

Replace article URL with short Amazon permalink

当前为 2018-02-16 提交的版本,查看 最新版本

  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.2
  9. // ==/UserScript==
  10.  
  11. /* jshint esversion: 6 */
  12. (function (doc) {
  13. 'use strict';
  14. var asinId = doc.getElementById('ASIN');
  15. if (asinId) {
  16.  
  17. asinId = asinId.value;
  18. history.replaceState(null, 'Amazon URL Cleaner', '/dp/' + asinId + '/');
  19. console.log("URL replaced by Amazon URL Cleaner. ASIN: " + asinId);
  20. }
  21. else {
  22. // Get ASIN from canonical link
  23. var links = doc.getElementsByTagName('link');
  24. var i;
  25. for (i=0; i < links.length; i++) {
  26. if (links[i].rel === 'canonical') {
  27. var canonical = links[i].href;
  28. var asin = canonical.replace(/https?:\/\/www\.amazon\..*\/dp\/([\w]+)$/, '$1');
  29. if (asin.length === 10) {
  30. history.replaceState(null, 'Amazon URL Cleaner', '/dp/' + asin + '/');
  31. console.log("URL replaced by Amazon URL Cleaner. ASIN: " + asin);
  32. }
  33. }
  34. }
  35. }
  36. }) (document);