Twitter fast clean link copy

Copy tweet links with one click and strip query parameters

  1. // ==UserScript==
  2. // @name Twitter fast clean link copy
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Copy tweet links with one click and strip query parameters
  6. // @author cro
  7. // @match https://*.twitter.com/*
  8. // @match https://*.x.com/*
  9. // @icon https://www.google.com/s2/favicons?domain=twitter.com
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13. /* jshint esversion: 6 */
  14.  
  15. (function()
  16. {
  17. 'use strict';
  18. let id = 'cro-copy-id';
  19.  
  20. let make_button = function()
  21. {
  22. let button = document.createElement('button');
  23. button.textContent = 'copy link';
  24. button.onclick = function ()
  25. {
  26. let url = new URL(button.closest('article').querySelector('[href*="status"]').href);
  27. url.pathname = url.pathname.split('/').slice(0,4).join('/');
  28. navigator.clipboard.writeText(url.toString());
  29. };
  30. button.id = id;
  31. return button;
  32. };
  33.  
  34. setInterval(function()
  35. {
  36. let nodes = document.querySelectorAll('article div[role="group"]');
  37. for (let node of nodes)
  38. {
  39. if (!node.querySelector(`#${id}`))
  40. {
  41. node.lastChild.append(make_button());
  42. }
  43. }
  44. }, 250);
  45. })();

QingJ © 2025

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