CSDN代码去行号

去除csdn代码行号,复制代码时,会粘贴到行号,此脚本可以去除行号.

目前為 2022-06-20 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         CSDN代码去行号
// @namespace    https://github.com/adlered
// @version      0.0.9
// @description  去除csdn代码行号,复制代码时,会粘贴到行号,此脚本可以去除行号.
// @author       xiejl
// @connect      www.csdn.net
// @include      *://*.csdn.net/*
// @require      https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery-cookie/1.4.1/jquery.cookie.min.js
// @require      https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/nprogress/0.2.0/nprogress.min.js
// @require      https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/clipboard.js/2.0.10/clipboard.min.js
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @license           LGPLv3
// @note         22-06-17 0.0.9 修改为动态语言
// @note         22-06-17 0.0.8 调整加载时间
// @note         22-06-17 0.0.7 支持csdn两种代码格式
// @note         22-06-17 0.0.6 去除csdn行号,调整缩进

// ==/UserScript==
(function() {
    'use strict';
    var ref = "";
    var changeCount = 0;
    $(".pre-numbering").remove();
    $(".prettyprint").css({"padding":" 8px 16px 6px 10px"})
    $(".hljs-ln-numbers").remove()
    function getText(totalLi) {
        var text = "";
        for(var i=0; i<totalLi.length; i++){
            text +=$(totalLi[i]).text()+"\n"
        }
        return text;
    }
    function changeCode() {
        var data = $("[class~='hljs']");
        var len = data.length;
        if(len<=0) {
            return;
        }
        var language = $($("[class~='hljs']")[0]).attr("class").split(" ")[0]
        for(var i=0; i<len; i++){
            var _par = $(data[i]).parent();
            var totalLi = $(data[i]).find("li");
            if(totalLi.length<=0) {
                continue;
            }
            var current = '<pre class="prettyprint" style="padding: 8px 16px 6px 10px; user-select: auto;"><code class="prism '+language+' has-numbering" onclick="mdcp.copyCode(event)" style="position: unset; user-select: auto;">'
            +
                getText(totalLi)
            +
                '</code></pre>';
            _par.replaceWith(current)
        }
        clearInterval(ref);
    }

    function startChange() {
        if($('pre').attr('class') == undefined ){
            ref = setInterval(function () {
                changeCount++;
                if(changeCount>200){
                    clearInterval(ref);
                }
                changeCode()
            }, 0);
        }
    }
    startChange();
    // Your code here...
})();