Swap x.com copy link

Replace `x` to `vxtwitter` when clicking 'Copy Link'

  1. // ==UserScript==
  2. // @name Swap x.com copy link
  3. // @namespace https://github.com/gjing/xittershare
  4. // @version 1.1
  5. // @description Replace `x` to `vxtwitter` when clicking 'Copy Link'
  6. // @author gjing
  7. // @match https://twitter.com/*
  8. // @match https://mobile.twitter.com/*
  9. // @match https://tweetdeck.twitter.com/*
  10. // @match https://x.com/*
  11. // @icon https://abs.twimg.com/favicons/twitter.2.ico
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. const replacement = 'vxtwitter';
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. document.addEventListener("copy", (e) => {
  21. let selected = e.target.innerText;
  22. setTimeout(async()=>await replace_x(selected), 0);
  23. });
  24.  
  25. function replace_x(selected) {
  26. if (selected.match(/^https+:\/\/((.+)\.)?(twitter|x)\.com\/(.+)\/status\/(\d+)(\?.+)?$/)) {
  27. let newUrl = selected.replace(/^https+:\/\/((.+)\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.com\/(.+)\/status\/(\d+)(\?.+)?$/, ['https://', replacement, '.com/$3/status/$4'].join(''));
  28. navigator.clipboard.writeText(newUrl);
  29. return;
  30. }
  31. }
  32. })();