Google Search Plus

Google 搜索增强:自动显示被过滤的结果,并在新标签页打开外链

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!)

Advertisement:

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

Advertisement:

// ==UserScript==
// @name         Google Search Plus
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Google 搜索增强:自动显示被过滤的结果,并在新标签页打开外链
// @author       ChenXu
// @license      MIT
// @include      *://www.google.com*/search*
// @include      *://scholar.google.com*/scholar*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    "use strict";

    const isSearch = (url) => /^https?:\/\/(www|scholar)\.google\.[^\/]+\/(search|scholar)/.test(url);

    const url = new URL(location.href);
    if (isSearch(location.href) && !url.searchParams.has('filter')) {
        url.searchParams.set('filter', '0');
        location.replace(url.href);
        return;
    }

    const processLinks = () => {
        document.querySelectorAll('a[href]:not([data-processed])').forEach(link => {
            const href = link.href;
            if (href && !isSearch(href) && !href.startsWith('javascript:')) {
                link.dataset.processed = 'true';
                link.target = '_blank';
                link.rel = 'noopener noreferrer';
            }
        });
    };

    const init = () => {
        processLinks();
        new MutationObserver(() => processLinks()).observe(document.body, {
            childList: true,
            subtree: true
        });
    };

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();