Convert LF to CRLF

Automatically convert line feed (LF) to carriage return + line feed (CRLF) when copying text from web pages. 可以让复制的Greasy Fork镜像代码支持在via直接新建,也可以让系统菜单复制的通义千问移动端网页的代码在便签APP正常换行。UserScript完全由通义千问生成。

当前为 2024-04-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Convert LF to CRLF
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.3
  5. // @description Automatically convert line feed (LF) to carriage return + line feed (CRLF) when copying text from web pages. 可以让复制的Greasy Fork镜像代码支持在via直接新建,也可以让系统菜单复制的通义千问移动端网页的代码在便签APP正常换行。UserScript完全由通义千问生成。
  6. // @author 幸福的赢得
  7. // @match *://gf.qytechs.cn/*/scripts/*/code*
  8. // @match *://update.gf.qytechs.cn/*
  9. // @match *://tongyi.aliyun.com/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. document.addEventListener('copy', function(event) {
  17. var selection = window.getSelection().toString();
  18. if (!selection.includes('\n')) return;
  19.  
  20. event.preventDefault();
  21.  
  22. // Replace LF with CRLF
  23. var modifiedSelection = selection.replace(/\n/g, '\r\n');
  24.  
  25.  
  26. //进一步优化通义千问移动版网页
  27. if (/:\/\/tongyi/.test (location.href) ) {
  28. // Remove the leading whitespace + newline
  29. modifiedSelection = modifiedSelection.replace(/^\r\n/, '');
  30.  
  31. // Find and remove the pattern "space newline space newline" and everything following it
  32. var patternMatch = modifiedSelection.match(/\r\n0\/1000\r\n(.*)/);
  33. if (patternMatch) {
  34. modifiedSelection = modifiedSelection.slice(0, -patternMatch[0].length);
  35. }
  36. }
  37.  
  38.  
  39. // Put the modified text on the clipboard
  40. event.clipboardData.setData('text/plain', modifiedSelection);
  41. });
  42. })();

QingJ © 2025

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