URL Clean

Clean / minimize large URLs by stripping tracking info

目前为 2021-01-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name URL Clean
  3. // @description Clean / minimize large URLs by stripping tracking info
  4. // @license BSD 3-Clause
  5. // @author Duckle29
  6. // @namespace https://github.com/Duckle29
  7. // @run-at document-start
  8. // @icon https://avatars3.githubusercontent.com/u/2756925?v=3&s=200
  9. // @homepageURL https://github.com/Duckle29/url_clean
  10. // @version 1.1.2
  11. //
  12. // @include /^https?:\/\/(?:www\.)?([a-zA-Z]{2,3}\.)?aliexpress\.com\/(item|store\/product)\/.*/
  13. // @include /^https?:\/\/(?:www\.)?ebay\.(?:co.)?[a-zA-Z]{2,3}\/itm/
  14. // @include /^https?:\/\/(?:www\.)?amazon\.(?:co.)?[a-zA-Z]{2,3}\//
  15. // @history 1.1.2 Fixed regex to match URL encoding
  16. // @history 1.1.1 Fixed regex for Amazon
  17. // @history 1.1 Added Amazon
  18. // @history 1.0 Initial release
  19. // ==/UserScript==
  20.  
  21. (function()
  22. {
  23. 'use strict';
  24. var sites =
  25. [
  26. /^(https?:\/\/(?:www\.)?ebay\.(?:(?:co.)?[a-zA-Z]{2,3})\/itm)(?:\/[0-9a-zA-Z%\-]+)(\/\d+)/,
  27. /^(https?:\/\/(?:[a-zA-Z]{2,3}\.)?aliexpress.com\/(?:item|store\/product))(\/[0-9_]+[.]html(?=$|[?]))/,
  28. /^(https?:\/\/(?:www\.)?amazon\.(?:co.)?[a-zA-Z%]{2,3}\/.*\/dp\/)(.*)(?:\\)?\?/
  29. ];
  30.  
  31. sites.forEach(regReplace)
  32.  
  33. function regReplace(expression)
  34. {
  35. var groups = window.location.href.match(expression)
  36. if (groups == null)
  37. {
  38. return
  39. }
  40.  
  41. if (groups.length === 3 && groups[1]+groups[2] != window.location.href)
  42. {
  43. history.replaceState(null, '', groups[1]+groups[2]);
  44. }
  45. }
  46.  
  47. })();