网页效果增强

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

目前為 2023-11-21 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         网页效果增强
// @namespace    https://github.com/xjl456852
// @version      0.1.12
// @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         23-11-21 0.1.12 去除折叠代码,去除关注博客才能继续浏览
// @note         23-11-20 0.1.11 去除csdn的代码行高限制
// @note         22-06-25 0.1.9 清除一些网站的干扰码,隐藏文字
// @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);
                    //去除隐藏和关注功能
                    processHide()
                }

                function processHide() {
                    //行的限高去掉
                    $("pre").css("max-height","none")
                    //去除折叠代码
                    $(".hide-preCode-box").remove()
                    $("pre.set-code-hide").css("height", "initial")
                    $("pre.set-code-hide").css("overflow", "initial")
                    //去除关注博主才能继续浏览
                    $(".hide-article-box").remove()
                    $("#article_content").css("height", "initial")
                    $("#article_content").css("overflow", "initial")
                }
                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()
            $("font[class='jammer']").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();
})();