Greasy Fork 支持简体中文。

交换左键和中键默认打开url的方式

点击超链接,左键新标签页打开.中键当前页面打开

// ==UserScript==
// @name         交换左键和中键默认打开url的方式
// @namespace    http://tampermonkey.net/
// @version      2025-02-18
// @description  点击超链接,左键新标签页打开.中键当前页面打开
// @author       leftyzzk
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mozilla.org
// @grant        none
// @license      MIT
// ==/UserScript==

document.addEventListener("mousedown", function(e) {
    let target = e.target.closest("a");
    if (!target) return;

    if (e.button === 0) { // 左键:新标签页打开
        e.preventDefault();
        window.open(target.href, "_blank");
    } else if (e.button === 1) { // 中键:当前页面打开
        e.preventDefault();
        window.location.href = target.href;
    }
}, true);

document.addEventListener("click", function(e) {
    let target = e.target.closest("a");
    if (!target) return;

    if (e.button === 0 || e.button === 1) {
        e.preventDefault(); // 彻底拦截 Firefox 默认行为
    }
}, true);

document.addEventListener("auxclick", function(e) {
    if (e.button === 1) {
        e.preventDefault(); // 防止中键触发新标签页
    }
}, true);