Google Scholar - Open Links in New Tab

Open links in new tab when clicking on h3 elements

当前为 2025-02-04 提交的版本,查看 最新版本

// ==UserScript==
// @name         Google Scholar - Open Links in New Tab
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Open links in new tab when clicking on h3 elements
// @author       You
// @match        https://scholar.google.*/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    function updateLinks() {
        document.querySelectorAll('h3.gs_rt a').forEach(link => {
            if (!link.hasAttribute('target')) {
                link.setAttribute('target', '_blank');
            }
        });
    }

    // Chạy lần đầu khi trang tải xong
    updateLinks();

    // Sử dụng MutationObserver để theo dõi thay đổi trong DOM
    const observer = new MutationObserver(() => updateLinks());

    observer.observe(document.body, { childList: true, subtree: true });

})();