Greasy Fork

Greasy Fork is available in English.

强制新标签页打开链接

让所有网页链接都在新标签页中打开,提升浏览效率。

当前为 2024-06-26 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Force Link Open in New
// @name:zh-CN   强制新标签页打开链接
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Opens all web links in new tabs, enhancing browsing efficiency and preventing loss of work progress.
// @description:zh-CN  让所有网页链接都在新标签页中打开,提升浏览效率。
// @author       Yearly
// @license      AGPL-v3.0
// @match        *://*/*
// @exclude      *://*.greasyfork.org/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Capture all click events and open links in a new tab
    document.addEventListener('click', function(event) {
        let anchor = event.target.closest('a');
        if (anchor && anchor.href) {
            event.preventDefault();
            window.open(anchor.href, '_blank');
        }
    }, true);

    // Override window.open method to open URLs in a new tab
    const originalOpen = window.open;
    window.open = function(url, target = '_blank', features) {
        if (['_self', '_parent', '_top'].includes(target)) {
            target = '_blank';
        }
        return originalOpen.call(window, url, target, features);
    };

})();