dedu

去除百度搜索结果重定向,去除热榜,去除部分百度系推广

目前为 2024-05-15 提交的版本。查看 最新版本

// ==UserScript==
// @license     MIT
// @name        dedu
// @namespace   ojer
// @match       https://www.baidu.com/s
// @grant       GM_addElement
// @runat       document-end
// @version     1.32
// @author      ojer
// @description 去除百度搜索结果重定向,去除热榜,去除部分百度系推广
// ==/UserScript==

const dataId = 'vm-ojer-dedu'
const addStyle = () => {
	const content = `
		#content_right{
			display: none !important;
		}

   	#content_left > div:not([id]) {
			display: none !important;
		}

		#content_left > div[tpl="short_video"],div[tpl="news-realtime"],div[tpl="bjh_addressing"],div[tpl="recommend_list"] {
			display: none !important;
		}

		#content_left > div[mu^="https://baijiahao.baidu.com/s"] {
			display: none !important;
		}
	`
	const ele = GM_addElement(document.head, 'style', content)
	ele.setAttribute('data-id', dataId)
}

const main = (s) => {
	setTimeout(() => {
		const left = document.getElementById('content_left')
		if (left) {
			const childrenElements = left.children
			console.log(2,childrenElements.length - 1)
			for (var i = childrenElements.length - 1; i > -1; i--) {
				const fc = childrenElements[i]
				if (fc.querySelector('a.m.c-gap-left')) {
					fc.remove()
					continue
				}
				try {
					const href = fc.getAttribute('mu')
					if (href) {
						fc.querySelectorAll('a').forEach((a) => a.setAttribute('href', href))
					}
				} catch (ignore) {}
			}
		}
		s += 500
		if(s <= 3000){
			main(s)
		}
	}, s)
}

new MutationObserver((mutationsList, observer) => {
	if (!document.querySelector('style[data-id="' + dataId + '"]')) {
		setTimeout(addStyle())
		main(500)
	}
}).observe(document.body, {
	childList: true
})

QingJ © 2025

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