Greasy Fork is available in English.

拒绝百度搜索结果二次跳转

将百度搜索结果链接替换成原始链接

// ==UserScript==
// @name         拒绝百度搜索结果二次跳转
// @namespace    baidu-real-link
// @version      0.0.3
// @author       lyswhut
// @license      MIT
// @description  将百度搜索结果链接替换成原始链接
// @match        https://www.baidu.com/s?*
// @run-at       document-start
// @noframes
// @grant        none
// ==/UserScript==
(function() {
  'use strict'

  const handleReplace = () => {
    for (const item of document.querySelectorAll('.new-pmd')) {
      const link = item.getAttribute('mu')
      if (!link) continue
      if (link.includes('lightapp.baidu.com')) continue
      let a = item.querySelector('.c-title > a')
      if (!a) a = item.querySelector('.c-border a')
      if (!a) continue
      a.setAttribute('href', link)
    }
  }

  document.addEventListener('DOMContentLoaded', () => {
    handleReplace()

    const observer = new window.MutationObserver(() => {
      setTimeout(handleReplace)
    })
    const dom_content = document.querySelector('#wrapper_wrapper')
    if (!dom_content) return
    observer.observe(dom_content, {
      attributes: false,
      childList: true,
      subtree: false,
    })
  })
})()