【手机】去除百度跳转及去推广,标识csdn下载

由于手机搜索东西搜到cdsn下载的网站,特意标识一下防止误进恶心人

目前為 2021-10-12 提交的版本,檢視 最新版本

// ==UserScript==
// @name         【手机】去除百度跳转及去推广,标识csdn下载
// @namespace    http://tampermonkey.net/
// @version      0.2.0
// @description  由于手机搜索东西搜到cdsn下载的网站,特意标识一下防止误进恶心人
// @author       MT-戒酒的李白染
// @include    *://m.baidu.com/*
// @include    *://www.baidu.com/*
// @include    *://baijiahao.baidu.com/*
// @include    *://tieba.baidu.com/*
// @include    *://wk.baidu.com/*
// @include    *://jingyan.baidu.com/*
// @include    *://baike.baidu.com/*
// @grant        GM_addStyle
// @require	     http://cdn.staticfile.org/jquery/2.1.4/jquery.min.js
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';
    var Flag_Title_css = `
    .component-box .praise {
        padding-right: 20px;
        background: #ff5722;
        text-indent: 1em;
        border-top-left-radius: 50px;
        border-top-right-radius: 50px;
        border-bottom-left-radius: 50px;
        border-bottom-right-radius: 50px;
        background: -webkit-linear-gradient(left,#ff5722,#f78d6b);
        background: -o-linear-gradient(right,#ff5722,#f78d6b);
        background: -moz-linear-gradient(right,#ff5722,#f78d6b);
        background: linear-gradient(to right,#ff5722,#f78d6b);
    }
    .component-box .praise,.component-box .share {
        /*width: 110px;
        height: 34px;
        line-height: 34px;*/
        height:auto;line-height:normal;color: #fff;
    }
    .component-box a {
        display: inline-block;
        font-size: 14px;
    }
    .component-box {
        /*margin: 0 auto;
        text-align: center;
        display: inline;*/
        display: flex;
        margin: 0;
        text-align: left;
        font-size: 0;
        position: relative;
        width: 260px;
    }
`

    function repalceLink_Event() {
        function repalceA_Tag(DOM, new_href) {
            let aTag = Array.from(DOM.getElementsByTagName("a"));
            aTag.forEach((item) => {
                item.href = new_href;
            })
            removeControl();
        }

        function addWebsiteFlag(DOM) {
            let WebsiteTitle = Array.from(DOM.getElementsByClassName("c-title-text"));
            if (WebsiteTitle.length) {
                console.log(WebsiteTitle[0]);
                let Title_Div = document.createElement("div");
                Title_Div.className = 'component-box';
                Title_Div.innerHTML = `<a class="praise" href="javascript:;">CSDN下载</a>`;
                WebsiteTitle[0].append(Title_Div);
            }

        }

        function removeControl() {
            if ($(".icon-logo").length) {
                $(".icon-logo")[0].remove(); //底部下一页前面图标删除
            }

            $("#page-relative").remove(); //末尾 ===>>  大家都在搜  广告位
            $(".c-recomm-wrap.new-ux-recom-wrapper.c-bg-color-white.animation").remove(); //中间 ===>>  大家都在搜  广告位
            $("#pop-up").remove(); //跳转百度app提示
            let searchWebSitePages = $(".c-result.result");
            searchWebSitePages = Array.from(searchWebSitePages);
            searchWebSitePages.forEach((items, index) => {
                let searchArticleOriginal_link = JSON.parse(items.dataset.log)['mu'];
                if (searchArticleOriginal_link.match(/recommend_list.baidu.com/g)) {
                    console.log('%c%s', 'color:blue;', "删除广告==>大家都在搜");
                    items.remove();
                }
                if (items.outerText.substr(0, 5) == "大家还在搜") {
                    console.log('%c%s', 'color:blue;', "删除广告==>大家都在搜:显示出来的");
                    items.remove();
                }
                if (items.childNodes.length > 1) {
                    if (items.outerText.match(/(大家还在搜|百度APP内打开)/)) {
                        console.log('%c%s', 'color:blue;', "删除广告==>大家都在搜:隐藏的(点击后,跳出来的)");
                        items.childNodes[1].remove();
                    }
                }
                let bottom_logo_text = items.getElementsByClassName("c-color-source"); //底部标识
                if (bottom_logo_text != null) {
                    let bottom_remove_flag = false;
                    let bottom_logo = Array.from(bottom_logo_text);
                    bottom_logo.forEach((items_b, index_b) => {
                        let it_text = items_b.outerText;
                        if (it_text.match(/百度(APP内打开|手机助手)/)) {
                            bottom_remove_flag = true;
                        }
                    })
                    if (bottom_remove_flag) {
                        console.log('%c%s', 'color:blue;', "删除广告==>百度APP内打开");
                        items.remove();
                    }
                }
                if (items.getElementsByClassName('component-box').length == 0 && searchArticleOriginal_link.match(/http(s|):\/\/(download.csdn.net|www.iteye.com\/resource)/g)) {
                    addWebsiteFlag(items);
                    console.log("插入csdn标题");
                }
                if (items.hasAttribute("srcid") && items.attributes.srcid.value.match(/(sigma|vid_fourfold)/g)) {
                    console.log('%c%s', 'color:blue;', "删除推荐==>xxx 相关 xxx");
                    items.remove();
                }
            })
            let every_result = $("span");
            every_result = Array.from(every_result);
            every_result.forEach((items, index) => {
                let result_parent = items.parentElement.parentElement;
                if (items.outerText.match(/百度APP内打开/) || result_parent.getAttribute("data-from") == "etpl") {
                    console.log("存在隐藏");
                    every_result[index].parentElement.parentElement.remove();
                }
            })
        }

        function replaceLink() {
            let searchWebSitePages = $(".c-result.result");
            searchWebSitePages = Array.from(searchWebSitePages);
            searchWebSitePages.forEach((items, index) => {
                let searchArticleOriginal_link = JSON.parse(items.dataset.log)['mu'];
                if (searchArticleOriginal_link) {
                    let BaiduSearchReplaceAfter = items.getElementsByTagName("article")[0];
                    if (BaiduSearchReplaceAfter && BaiduSearchReplaceAfter.hasAttribute('rl-link-href')) {
                        let BaiduSearchReplaceAfterValue = BaiduSearchReplaceAfter.getAttributeNode("rl-link-href").value;
                        if (!BaiduSearchReplaceAfterValue.match(/http(s|):\/\/m.baidu.com\/from/g)) {
                            console.info('%c%s', 'color:red;', "当前的 ===>> " + BaiduSearchReplaceAfterValue);
                            return
                        }
                        if (BaiduSearchReplaceAfterValue.match(/http:\/\/www.internal.video.baidu.com/g) || searchArticleOriginal_link.match(/http:\/\/www.internal.video.baidu.com/g)) {

                            let internalVideo = decodeURIComponent(BaiduSearchReplaceAfter.getAttribute("rl-link-data-log"));
                            let internalVideoMatch = internalVideo.match(/\/sf\?pd=video_pag(.*?)={/g);
                            if (internalVideoMatch) {
                                internalVideoMatch = internalVideoMatch[0];
                                let newinternalVideo = internalVideoMatch.substring(0, internalVideoMatch.length - 2);
                                console.log('%c%s', 'color:orange;', "修复后的视频:" + newinternalVideo);
                                BaiduSearchReplaceAfter.setAttribute("rl-link-href", newinternalVideo);
                                repalceA_Tag(items, newinternalVideo);
                            }
                        } else if (searchArticleOriginal_link.match(/http:\/\/m.baidu.com\/productcard/g)) {
                            console.info('%c%s', 'color:red;', "该链接不予替换");
                        } else {
                            BaiduSearchReplaceAfter.setAttribute("rl-link-href", searchArticleOriginal_link);
                            repalceA_Tag(items, searchArticleOriginal_link);
                            //console.info('%c%s','color:red;',"修复后的 ===>> "+searchArticleOriginal_link);
                        }
                    }
                }
            })
        }

        function main() {
            removeControl();
            replaceLink();
        }
        main();
    }
    var runNum = 0;

    function replaceLink() {
        Array.from($("script")).forEach((items, index) => {
            if (items.text.match(/define\(\"@molecule\/aftclk\/index\",/g)) {
                console.log('%c%s', 'color:blue;', "删除跳转百度app提示js==>");
                items.remove();
            }
        })
        $(".search-page").bind("DOMNodeInserted", function () {
            console.log("当前执行次数:" + runNum);
            repalceLink_Event();
            runNum = runNum + 1;
        })
    }

    let baidu = {
        current_url: window.location.href,
        init() {
            this.baijiahao();
            this.tieba();
            this.wenku();
            this.jingyan();
            this.baike();
        },
        css: {
            baijiahao: `
            .layer-wrap,
            .openImg,
            .oPadding,
            .infinite-scroll-component__outerdiv,
            .bottomTTSStruct,
            .undefined,
            .headDeflectorContainer,
            .followSuper,
            #searchwordSdk ~ div:nth-child(n+4),
            #searchwordSdk,
            div#commentModule div div span:last-child
            {
              display:none !important;
            }
            body.scrollHide{
              overflow:auto !important;
            }
            .mainContent{
              height:  auto !important;
            }
            `,
            tieba: `
            .tb-backflow-defensive,
            .fixed-nav-bar-defensive,
            .post-cut-guide,
            .ertiao-wrap-defensive,
            .feed-warp.gray-background,
            .pb-page-wrapper.app-view.transition-fade nav:first-child,
            .banner-wrapper-defensive{
              display:none !important;
            }
            body.tb-modal-open{
              overflow:auto !important;
            }`,
            wenku: `
            .reader-pop-manager-view-containter,
            .core-download,
            .card-wrap.card-vip,
            #app{
              display:none !important;
            }
            .reader-wrap{
              height:auto !important;
            }
            #view-app,
            #view-rr-app{
              max-height: 100% !important;
            }
            *{
              -webkit-touch-callout: inherit !important;
              -khtml-user-select: auto !important;
              -moz-user-select: auto !important;
              -ms-user-select: auto !important;
              user-select: auto !important;
            }
            `,
            jingyan: `
            .article-feed-next,
            .wgt-rel-exp-feed,
            .article-feed-btn-fixed,
            .read-whole-mask.app{
              display:none !important;
            }
            .exp-content-container.fold.more2line{
              max-height: 100% !important;
            }
            `,
            baike: `
            .BK-after-content-wrapper,
            .yitiao-container,
            #J-tashuo-button-fixed{
              display:none !important;
            }`,
        },
        baijiahao() {
            // 百家号
            if (this.current_url.indexOf("baijiahao.baidu.com") != -1) {
                GM_addStyle(this.css.baijiahao);
            }
        },
        tieba() {
            //  贴吧
            if (this.current_url.indexOf("tieba.baidu.com") != -1) {
                GM_addStyle(this.css.tieba);
            }
        },
        wenku() {
            // 文库
            if (this.current_url.indexOf("wk.baidu.com") != -1) {
                GM_addStyle(this.css.wenku);
            }
        },
        jingyan() {
            // 经验
            if (this.current_url.indexOf("jingyan.baidu.com") != -1) {
                GM_addStyle(this.css.jingyan);
            }
        },
        baike() {
            // 百科
            if (this.current_url.indexOf("baike.baidu.com") != -1) {
                GM_addStyle(this.css.baike);
            }
        }
    }

    function main_start() {
        replaceLink();
    }
    GM_addStyle(`
        .c-container.na-ec-item,
        .c-recomm-wrap.new-ux-recom-wrapper.animation,
        #results-pre,
        .video-recommend,
        .c-result.sfc-log[data-tpl="search_recomm"],
        .sfc-image-content-waterfall-item[wat-item-data-id="no-img"],
        .se-results-pre,
        .copyright + div{
            display:none !important;
        }
    `);
    GM_addStyle(Flag_Title_css);
    baidu.init();
    $(function () {
        main_start();
    })
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址