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完全由通义千问生成。

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Convert LF to CRLF
// @namespace    http://tampermonkey.net/
// @version      0.1.2
// @description  Automatically convert line feed (LF) to carriage return + line feed (CRLF) when copying text from web pages. 可以让复制的greasy fork代码支持在via直接新建,也可以让系统菜单复制的通义千问移动端网页的代码在便签APP正常换行。UserScript完全由通义千问生成。
// @author       幸福的赢得
// @match        *://greasyfork.org/*/scripts/*/code*
// @match        *://update.greasyfork.org/*
// @match        *://tongyi.aliyun.com/*
// @match        *://www.doubao.com/chat/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('copy', function(event) {
        var selection = window.getSelection().toString();
        if (!selection.includes('\n')) return;

        event.preventDefault();

        // Replace LF with CRLF
        var modifiedSelection = selection.replace(/\n/g, '\r\n');


//进一步优化通义千问移动版网页
if (/:\/\/tongyi/.test (location.href) ) {
    // Remove the leading whitespace + newline
    modifiedSelection = modifiedSelection.replace(/^\r\n/, '');

    // Find and remove the pattern "space newline space newline" and everything following it
    var patternMatch = modifiedSelection.match(/\r\n0\/1000\r\n(.*)/);
    if (patternMatch) {
        modifiedSelection = modifiedSelection.slice(0, -patternMatch[0].length -2);
    }
}


        // Put the modified text on the clipboard
        event.clipboardData.setData('text/plain', modifiedSelection);
    });
})();