URL minimizer

Shorten url's to their minimum representation for better sharing without tracking information.

  1. // ==UserScript==
  2. // @name URL minimizer
  3. // @namespace https://github.com/GottZ/url-minimizer
  4. // @version 0.0.3
  5. // @description Shorten url's to their minimum representation for better sharing without tracking information.
  6. // @author GottZ
  7. // @contributors BowuDev
  8. // @include /^https?:\/\/(www\.)?(amazon|ebay|youtube)\.[a-z]+/
  9. // @include https://*.gumroad.com/l/*
  10. // @include https://www.etsy.com/listing/*
  11. // @icon https://gottz.de/favicon.ico
  12. // @grant GM_registerMenuCommand
  13. // @grant GM_notification
  14. // @run-at document-idle
  15. // ==/UserScript==
  16.  
  17. 'use strict';
  18.  
  19. const sites = {
  20. // https://www.amazon.de/.../dp/(...)/?_encoding=.....
  21. "Amazon": {
  22. host: /\b(amazon\.[a-z]+)$/,
  23. path: /dp\/([^\/]+)(?:\/|$)/,
  24. template: ({host, path}) => `https://${host[1]}/dp/${path[1]}`,
  25. },
  26. // https://www.ebay.de/itm/(...)?_trkparms=.....
  27. "eBay": {
  28. host: /\b(ebay\.[a-z]+)$/,
  29. path: /itm\/(\d+)/,
  30. template: ({host, path}) => `https://${host[1]}/itm/${path[1]}`,
  31. },
  32. // https://www.youtube.com/watch?v=(...)
  33. "YouTube": {
  34. host: /\b(youtube\.[a-z]+)$/,
  35. search: /\bv=([\w\-\_]+)/,
  36. template: ({search}) => `https://youtu.be/${search[1]}`,
  37. },
  38. // https://www.etsy.com/listing/(...)/...?ga_order=.....
  39. "Etsy": {
  40. host: /\b(etsy)\.com$/,
  41. path: /^\/listing\/(\d+)\//,
  42. template: ({path}) => `https://etsy.com/listing/${path[1]}`,
  43. },
  44. // https://(ABC).gumroad.com/l/(ABC)?recommended_by=...
  45. "Gumroad": {
  46. host: /\b(\w+)(\.gumroad)\.com$/,
  47. path: /^\/l\/(\w+)$/,
  48. template: ({host, path}) => `https://${host[1]}.gumroad.com/l/${path[1]}`,
  49. },
  50. };
  51.  
  52. const minimize = () => {
  53. let success = false;
  54. for (let name in sites) {
  55. const site = sites[name];
  56. if (!site.host.test(location.hostname)) continue;
  57. if ("path" in site && !site.path.test(location.pathname)) continue;
  58. if ("search" in site && !site.search.test(location.search)) continue;
  59.  
  60. const host = site.host.exec(location.hostname);
  61. const path = "path" in site ? site.path.exec(location.pathname) : null;
  62. const search = "search" in site ? site.search.exec(location.search) : null;
  63.  
  64. const link = site.template({host, path, search});
  65.  
  66. prompt(`copy this ${name} link`, link);
  67. success = true;
  68. break;
  69. }
  70.  
  71. if (!success) alert("could not shorten this url");
  72. };
  73.  
  74. GM_registerMenuCommand("minimize", minimize);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址