Greasy Fork 支持简体中文。

Remove spaces from links in the clipboard

Remove spaces

  1. // ==UserScript==
  2. // @name Remove spaces from links in the clipboard
  3. // @version 0.1.0
  4. // @description Remove spaces
  5. // @author dragonish
  6. // @namespace https://github.com/dragonish
  7. // @license GNU General Public License v3.0 or later
  8. // @match *://*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. document.addEventListener('paste', evt => {
  14. const clipboardData = evt.clipboardData;
  15. if (clipboardData) {
  16. const target = document.activeElement;
  17. if (target && (target.tagName === 'INPUT' || target?.tagName === 'TEXTAREA')) {
  18. let text = clipboardData.getData('text/plain');
  19. if (text.startsWith('http:') || text.startsWith('https:') || text.startsWith('magnet:') || text.startsWith('ed2k:') || text.startsWith('torrent:') || text.startsWith('thunder:') || text.startsWith('thunderx:')) {
  20. evt.preventDefault();
  21. text = text.replace(/\s+/g, '');
  22. target.value = text;
  23. }
  24. }
  25. }
  26. }, true);
  27. })();