Greasy Fork

Greasy Fork is available in English.

CSDN 助手

移除CSDN博客详情页推荐列表中的下载和推荐课程 | 百度搜索结果优化:标红百度搜索中CSDN的下载、聚合搜索、社区,阿里云、腾讯云、华为云等网站的聚合搜索

当前为 2022-02-17 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         CSDN 助手
// @namespace    http://tampermonkey.net/
// @version      0.2.9
// @author       myaijarvis
// @description  移除CSDN博客详情页推荐列表中的下载和推荐课程 | 百度搜索结果优化:标红百度搜索中CSDN的下载、聚合搜索、社区,阿里云、腾讯云、华为云等网站的聚合搜索
// @match        https://*.blog.csdn.net/article/details/*
// @match        https://blog.csdn.net/*/article/details/*
// @match        https://www.baidu.com/s?*
// @match        https://editor.csdn.net/md/*
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js
// @icon         https://g.csdnimg.cn/static/logo/favicon32.ico
// @run-at       document-end
// @grant        unsafeWindow
// ==/UserScript==

//debugger;
// console.log("csdn助手本地文件输出");
const url = window.location.href;

(function () {
    "use strict";
    //debugger;
    // 百度搜索
    if (url.match(/baidu.com\/s?/)) {
        // 找出百度搜索结果中csdn的下载项、聚合搜索,并标红显示
        // 在油猴插件《AC-baidu-重定向优化百度搜狗谷歌必应搜索_favicon_双列》渲染后执行
        setTimeout(findCSDNDownload, 1000); //第一次进入搜索界面

        // 点击搜索触发函数
        $("#su").click(function () {
            // 在搜索界面按下搜索按钮
            setTimeout(findCSDNDownload, 1000);
            console.log("点击了搜索");
        });

        // 监听滚轮 配合AC重定向脚本翻页使用
        $(window).scroll(function () {
            //为了保证兼容性,这里取两个值,哪个有值取哪一个 scrollTop就是触发滚轮事件时滚轮的高度
            let scrollTop =
                document.documentElement.scrollTop || document.body.scrollTop;
            if (scrollTop > 100) {
                //搜索翻页
                findCSDNDownload();
            }
            //console.log("滚动距离" + scrollTop);
        });
    }

    // csdn文章详情页
    if (url.match(/blog.csdn.net/)) {
        setTimeout(removeDownloadAndCourse, 3000);
        setTimeout(() => {
            $(".toolbar-advert").remove(); // csdn 顶部横幅广告
            $(".csdn-common-logo-advert").remove();
            $(".leftPop").remove();
        }, 2000);
    }

    // 点击目录 csdn编辑文章目录有bug
    if (url.match(/editor.csdn.net\/md/)) {
        setTimeout(() => {
            $(".side-title__button_close").click();
        }, 500);

        setTimeout(() => {
            $("button[data-title='目录']").click();
        }, 1000);
    }
})();

/** 去除csdn下载项、推荐课程
 * type_blog : 文章
 * type_download : 下载项
 * type_course : 推荐课程
 */
function removeDownloadAndCourse() {
    // 1.文章底部,评论前面
    $(".first-recommend-box > div").hasClass("type_blog")
        ? ""
    : $(".first-recommend-box > div").remove();
    $(".second-recommend-box > div").hasClass("type_blog")
        ? ""
    : $(".second-recommend-box > div").remove();

    // 2.相关推荐  csdn这里是动态渲染的,所以需要延迟执行
    $(".insert-baidu-box .recommend-item-box").each((index, domEle) => {
        $(domEle).hasClass("type_blog") ? "" : $(domEle).remove();
        $(domEle).attr('data-type')=="download" ? $(domEle).remove() : '';
    });
    $("#blogColumnPayAdvert").remove();
}

const url_arr = [
    "download.csdn", // CSDN下载
    "iteye.com/resource", // CSDN下载
    "csdn.net/tags", // CSDN聚合搜索
    "bbs.csdn.net", // CSDN社区
    "csdn.net/gather", // CSDN聚合搜索 https://www.csdn.net/gather_22/MtjaUg5sODM4MjgtYmxvZwO0O0OO0O0O.html
    "help.aliyun.com", // 阿里云聚合搜索 https://help.aliyun.com/wordpower/6127209-1.html https://developer.aliyun.com/askzt/10237805.html
    "developer.aliyun.com", // 阿里云聚合搜索 https://help.aliyun.com/wordpower/6127209-1.html https://developer.aliyun.com/askzt/10237805.html
    "cloud.tencent.com/developer/information/", // 腾讯云聚合搜索 https://cloud.tencent.com/developer/information/html%E7%AE%80%E5%8D%95%E5%BC%B9%E5%87%BA%E6%A1%86
    "blog.51cto.com/topic/", // 51CTO博客聚合搜索 https://blog.51cto.com/topic/youhoujiaobencss.html
    "huaweicloud.com/theme/", // 华为云聚合搜索 https://www.huaweicloud.com/theme/881818-2-H
    "itdaan.com/tag/", // 开发者知识库聚合搜索 https://www.itdaan.com/tag/%E6%96%B9%E6%B3%95/java.html
    "recomm.cnblogs.com/blogpost/", // 博客园聚合搜索 https://recomm.cnblogs.com/blogpost/5681713
    "javashuo.com/search/", // JavaShuo http://www.javashuo.com/search/gorsdn
    "xinnet.com/xinzhi/tags" // 新网聚合搜索 https://www.xinnet.com/xinzhi/tags/501018.html
];
const tip="不要点这个,浪费时间!";
// 百度搜索csdn结果优化
function findCSDNDownload() {
    //debugger; //开启调试
    let $blocks = $("#content_left .result-op");
    $blocks.each(function (index, item) {
        let href = $(this).find(".c-row a").attr("href") || "";
        if(href==""){
            return;
        }
        for (const url_item of url_arr) {
            if (href.includes(url_item)) {
                let $titleDom=$(this).find("h3.c-title");
                $titleDom.css("background", "red");
                if(!$titleDom.text().includes(tip))
                    $titleDom.append(`<span style="color: white;font-size: 18px;">${tip}</span>`);
                // console.log(`============标红了第${index + 1}个=>${href}`);
            }
        }
    });
}