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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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        *://greatest.deepsurf.us/*/scripts/*/code*
// @match        *://update.greatest.deepsurf.us/*
// @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);
    });
})();