Greasy Fork

Greasy Fork is available in English.

百度搜索结果优化

百度搜索结果优化:标红百度搜索中CSDN的下载、社区、聚合搜索 && 阿里云、腾讯云、华为云等网站的聚合搜索

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

// ==UserScript==
// @name         百度搜索结果优化
// @namespace    http://tampermonkey.net/
// @version      0.3.1
// @author       myaijarvis
// @description  百度搜索结果优化:标红百度搜索中CSDN的下载、社区、聚合搜索 && 阿里云、腾讯云、华为云等网站的聚合搜索
// @icon         https://www.baidu.com/favicon.ico
// @match        https://www.baidu.com/s?*
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js
// @run-at       document-end
// @grant        unsafeWindow
// ==/UserScript==

//debugger;
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);
        });
    }

})();

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 = $(".result > h3");
    $blocks.each(function (index, item) {
        let href = $(this).children("a").attr("href") || "";
        if(href==""){
            return;
        }
        for (const url_item of url_arr) {
            if (href.includes(url_item)) {
                $(this).css("background", "red");
                if(!$(this).text().includes(tip))
                    $(this).append(`<span style="color: white;font-size: 18px;">${tip}</span>`);
                // console.log(`============标红了第${index + 1}个=>${href}`);
            }
        }
    });
}