网页效果增强

去除csdn代码行号,复制代码时,会粘贴到行号,此脚本可以去除行号.可以限制kaggle子页面的完整页面.清除一些网站的隐藏文字,干扰码

当前为 2023-08-10 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         网页效果增强
// @namespace    https://github.com/xjl456852
// @version      0.1.8
// @description  去除csdn代码行号,复制代码时,会粘贴到行号,此脚本可以去除行号.可以限制kaggle子页面的完整页面.清除一些网站的隐藏文字,干扰码
// @author       解江磊
// @connect      www.csdn.net
// @match        *://www.kaggleusercontent.com/*
// @match        *://*.csdn.net/*
// @match        *://*.forbes.com/*
// @match        *://*/*
// @require      http://code.jquery.com/jquery-1.10.2.min.js
// @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-25 0.1.8 清除一些网站的干扰码,隐藏文字
// @note         22-06-25 0.1.5 优化循环代码,对kaggle内嵌页优化
// @note         22-06-25 0.1.4 增加forbes.com自动弹窗取消,滚动条支持
// @note         22-06-25 0.1.3 增加kaggle子网页单独取出来,显示不完整问题.并增加匹配,修改插件名,并取消:@include      *://*.csdn.net/*
// @note         22-06-25 0.1.2 修改动态无缝支持各种语言正确显示.不转义
// @note         22-06-20 0.1.1 修改动态无缝支持各种语言正确显示.不转义
// @note         22-06-20 0.1.0 修改单独页面不同的动态语言
// @note         22-06-18 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';
    function loopTemplate(name,e, count){
        let ref = "";
        let changeCount = 0;
        let loopResult = false;
        function startMonitor() {
            ref = setInterval(function () {
                changeCount++;
                console.log("effect loop monitor",name)
                if(changeCount>count){
                    clearInterval(ref);
                }
                loopResult = e()
                console.log('effect loop',name,loopResult)
                if(loopResult){
                    clearInterval(ref);
                    console.log('effect done',name)
                }
            }, 100);
        }
        startMonitor();
    }


    // Your code here...
    let csdn = {
        init() {
                $(".pre-numbering").remove();
                $(".prettyprint").css({"padding":" 8px 16px 6px 10px"})
                $(".hljs-ln-numbers").remove()

                let ref = "";
                let changeCount = 0;
                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;
                    }
                    for(var i=0; i<len; i++){
                        var languageArr = $(data[i]).attr("class").split(" ")
                        var language="";
                        for (var j in languageArr ) {
                            if(languageArr[j].startsWith("language-")){
                                language = languageArr[j];
                                break;
                            }
                        }

                        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;"></code></pre>';
                        var newCurrent = $(current)
                        _par.replaceWith(newCurrent)
                        newCurrent.find("code").text(getText(totalLi))
                    }
                    console.log("去行号完成")
                    clearInterval(ref);
                }


                function startChange() {
                    var src_class = $('pre').attr('class')
                    if("prettyprint" != src_class){
                        ref = setInterval(function () {
                            changeCount++;
                            console.log(changeCount)
                            if(changeCount>200){
                                clearInterval(ref);
                            }
                            changeCode()
                        }, 0);
                    }
                }
                startChange();
        }
    }
    let kaggle  = {
        init(){
            loopTemplate("kaggle",function(){
                if("hidden" == $("body").css("overflow-y")){
                    console.log("kaggle effect done")
                    $("body").css("overflow-y","auto")
                    return true;
                }
            },1000)
        }
    }
    
    let forbes  = {
        init(){
            let ref = "";
            let changeCount = 0;
            function startMonitor() {
                ref = setInterval(function () {
                    changeCount++;
                    console.log("loop monitor forbess")
                    if(changeCount>1000){
                        clearInterval(ref);
                    }
                    if(true == $("div").is(".tp-modal")){
                        console.log("remove forbes")
                        changeForbesCss()
                        clearInterval(ref);
                    }
                }, 100);
            }
            startMonitor();
            function changeForbesCss(){
                $("div.tp-backdrop").remove()
                $("div.tp-modal").remove()
                $("body").css("cssText", "overflow:auto !important;");
            }
        }
    }
    let cleanHide = {
        init(){
            $("font[style='color:rgb(255, 255, 255)']").remove()
        }
    }
    let main = {
        init() {
            if (/.csdn.net/.test(location.host)) {
                csdn.init();
            }
            if (/.kaggleusercontent.com/.test(location.host)) {
                kaggle.init();
            }
            if (/.forbes.com/.test(location.host)) {
                forbes.init();
            }
            cleanHide.init();
        }
    };

    main.init();
})();