🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

搜索引擎新标签打开链接

谷歌、百度、搜狗、必应、F搜、头条、360、DuckDuckGo、Ecosia 搜索结果新标签打开

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         搜索引擎新标签打开链接
// @description  谷歌、百度、搜狗、必应、F搜、头条、360、DuckDuckGo、Ecosia 搜索结果新标签打开
// @version      2.9
// @author       ChatGPT
// @match        *://www.so.com/*
// @match        *://m.so.com/*
// @match        *://so.toutiao.com/*
// @match        *://www.ecosia.org/*
// @match        *://fsoufsou.com/*
// @match        *://duckduckgo.com/*
// @match        *://yandex.com/*
// @match        *://www.google.co.jp/*
// @match        *://www.google.com.hk/*
// @match        *://www.google.com/*
// @match        *://m.baidu.com/*
// @match        *://www.baidu.com/*
// @match        *://wap.sogou.com/*
// @match        *://m.sogou.com/*
// @match        *://www.sogou.com/*
// @match        *://cn.bing.com/*
// @match        *://www.bing.com/*
// @run-at       document-end
// @grant        none
// @namespace    https://greasyfork.org/users/452911
// ==/UserScript==

(function() {
  'use strict';

  if (window.location.href.search(/search|q=|wd=|word=/) !== -1) {
    function modifyLinks() {
      let linksToOpenInSelf = document.querySelectorAll('a.sb_halfnext, a[class^="container"], a.control,a#pnnext,a.fl');
      linksToOpenInSelf.forEach(link => {
        link.setAttribute('target', '_self');
      });

      let linksToOpenInNewTab = document.querySelectorAll('a:not(.sb_halfnext):not([class^="container"]):not(.control):not([href^="/s?wd="]):not(.fl):not(#pnnext)');
      linksToOpenInNewTab.forEach(link => {
        link.setAttribute('target', '_blank');
      });

      let base = document.querySelector('base');
      if (!base) {
        let head = document.querySelector('head');
        let newBase = document.createElement('base');
        newBase.setAttribute('target', '_blank');
        head.appendChild(newBase);
      }
    }

    modifyLinks();

   (function() {
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.addedNodes.length > 0) {
                mutation.addedNodes.forEach(addedNode => {
                    if (addedNode.nodeType === Node.ELEMENT_NODE) {
                        modifyLinks();
                    }
                });
            }
        });
    });

    const config = { childList: true, subtree: true };

    observer.observe(document.body, config);
})();       
    }
})();