找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 158|回复: 3

[油猴脚本] 粘贴链接时去除内容中的空格

[复制链接]

9

主题

7982

回帖

2万

积分

超级版主

(^^ゞ

积分
22398
发表于 2025-4-8 21:41:08 | 显示全部楼层 |阅读模式
在粘贴时,自动去除剪贴板中的链接内容中的空格:
  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. (function () {
  12.   document.addEventListener('paste', evt => {
  13.     const clipboardData = evt.clipboardData;
  14.     if (clipboardData) {
  15.       const target = document.activeElement;
  16.       if (target && (target.tagName === 'INPUT' || target?.tagName === 'TEXTAREA')) {
  17.         let text = clipboardData.getData('text/plain');
  18.         if (text.startsWith('http:') || text.startsWith('https:') || text.startsWith('magnet:') || text.startsWith('ed2k:') || text.startsWith('torrent:') || text.startsWith('thunder:') || text.startsWith('thunderx:')) {
  19.           evt.preventDefault();
  20.           text = text.replace(/\s+/g, '');
  21.           target.value = text;
  22.         }
  23.       }
  24.     }
  25.   }, true);
  26. })();
复制代码

¯\(°_o)/¯
回复

使用道具 举报

44

主题

391

回帖

2489

积分

金牌会员

积分
2489
发表于 2025-4-10 12:30:34 | 显示全部楼层
Good job!支持一下💖
回复

使用道具 举报

29

主题

1639

回帖

8795

积分

论坛元老

积分
8795
发表于 2025-4-10 15:17:42 | 显示全部楼层
会不会有误杀?
回复

使用道具 举报

9

主题

7982

回帖

2万

积分

超级版主

(^^ゞ

积分
22398
 楼主| 发表于 2025-4-10 18:25:36 | 显示全部楼层
gh0ul 发表于 2025-4-10 15:17
会不会有误杀?

理论上会的,但脚本只处理以特定协议头开头字符串内容,一般不会有什么问题。
¯\(°_o)/¯
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|百分浏览器论坛

GMT+8, 2025-4-18 08:43 , Processed in 0.017054 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表