Greasy Fork

来自缓存

Greasy Fork is available in English.

百度首页简洁优化

去除百度首页的推荐广告,简洁优化界面,集成多搜索引擎切换功能

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         百度首页简洁优化
// @version      1.2.14
// @license      MIT
// @author       初晓
// @namespace    https://github.com/zhChuXiao
// @match        *://*.baidu.com/*
// @run-at       document-start

// @description:zh-cn 去除百度首页的推荐广告,简洁优化界面,集成多搜索引擎切换功能
// @description  去除百度首页的推荐广告,简洁优化界面,集成多搜索引擎切换功能
// @grant        GM_addStyle
// ==/UserScript==

;(function () {
    'use strict'

    // 配置选项
    const config = {
        // 页面元素
        elements: {
            logo: '#s_lg_img_new',
            searchInput: '#kw',
            searchWrapper: '#s_form_wrapper',
            removeElements: [
                '#s_wrap',
                '#s-top-left',
                '#s_new_search_guide',
                '.operate-wrapper',
                '.s-weather-wrapper',
                '.s-bottom-layer-content'
            ]
        }
    }

    // 注入隐藏元素的CSS样式
    function hideElements() {
        const selectors = config.elements.removeElements.join(', ')
        const css = `
      ${selectors} {
        display: none !important;
      }
    `
    GM_addStyle(css)
  }

    // 注入自定义样式
    function injectStyles() {
        const css = `

    `
    GM_addStyle(css)
  }

    // 初始化函数
    function initialize() {
        // 检查我们是否在百度首页
        if (
            window.location.href.includes('www.baidu.com') &&
            (window.location.pathname === '/' || window.location.pathname === '/index.html')
        ) {
            console.log(
                '%c 百度首页简洁优化脚本已加载 %c 呢喃Ninc %c blog.ninc.top ',
                'background:#4e6ef2; color:#fff; border-radius:3px 0 0 3px; padding:2px; font-weight:bold',
                'background:#606060; color:#fff; padding:2px; font-weight:bold',
                'background:#42c02e; color:#fff; border-radius:0 3px 3px 0; padding:2px'
            )
        }
    }

    // 立即执行隐藏元素和样式注入
    hideElements()
    injectStyles()

    // 页面加载完成后执行其他初始化
    if (document.readyState === 'complete') {
        initialize()
    } else {
        window.addEventListener('DOMContentLoaded', initialize)
    }
})()