Amazon URL Cleaner

Show the shortest possible URL for Amazon items.

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

  1. // ==UserScript==
  2. // @name Amazon URL Cleaner
  3. // @description Show the shortest possible URL for Amazon items.
  4. // @namespace https://arantius.com/misc/greasemonkey/
  5. // @match https://www.amazon.com/dp/*
  6. // @match https://www.amazon.com/*/dp/*
  7. // @match https://www.amazon.com/gp/product/*
  8. // @match https://www.amazon.com/*/ASIN/*
  9. // @run-at document-start
  10. // @version 9
  11. // @grant none
  12. // @icon https://www.amazon.com/favicon.ico
  13. // ==/UserScript==
  14.  
  15. function getProductId() {
  16. var m;
  17. m = document.location.href.match(/(?:.+\/)?dp\/([^/?]+)/);
  18. if (m) return m[1];
  19. m = document.location.href.match(/gp\/product\/([^/?]+)/);
  20. if (m) return m[1];
  21. m = document.location.href.match(/ASIN\/([^/?]+)/);
  22. if (m) return m[1];
  23. }
  24.  
  25. var productId = getProductId();
  26. if (productId) {
  27. history.replaceState(
  28. {}, document.title, 'https://www.amazon.com/dp/' + productId);
  29. }