Shorten Medium URL

Shorten URL in medium.com

  1. // ==UserScript==
  2. // @name Shorten Medium URL
  3. // @namespace https://github.com/FlandreDaisuki
  4. // @version 0.1
  5. // @description Shorten URL in medium.com
  6. // @author FlandreDaisuki
  7. // @match https://medium.com/*
  8. // @grant none
  9. // @noframes
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. const shorten = () => {
  14. if (location.pathname.match(/^\/([^/]*)\/.*-(\w+)$/)) {
  15. const url = new URL(location.href);
  16. url.search = '';
  17. url.pathname = url.pathname.replace(/^\/([^/]*)\/.*-(\w+)$/, '/$1/$2');
  18.  
  19. history.replaceState({}, document.title, url.href.replace(url.origin, ''));
  20. }
  21. };
  22.  
  23. window.observer = new MutationObserver(shorten);
  24.  
  25. window.addEventListener('load', shorten);
  26.  
  27. window.addEventListener('beforeunload', () => {
  28. window.observer.disconnect();
  29. });
  30.  
  31. document.addEventListener('DOMContentLoaded', () => {
  32. const rootEl = document.getElementById('container');
  33. const config = { childList: true };
  34. window.observer.observe(rootEl, config);
  35. });

QingJ © 2025

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