☰

E-Hentai Left Click New Tab

普通链接新标签页打开,所有分页留在当前页面

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

您需要先安装一个扩展,例如 篡改猴 或 暴力猴 才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         E-Hentai Left Click New Tab
// @namespace    local.ehentai.mouse
// @version      7.0
// @description  普通链接新标签页打开,所有分页留在当前页面
// @match        *://e-hentai.org/*
// @match        *://www.e-hentai.org/*
// @grant        GM_openInTab
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    document.addEventListener('click', function (e) {

        // 只处理普通左键
        if (e.button !== 0) return;

        // 保留组合键功能
        if (e.ctrlKey || e.shiftKey || e.altKey || e.metaKey) return;

        if (e.defaultPrevented) return;

        const target = e.target;
        if (!(target instanceof Element)) return;

        const link = target.closest('a[href]');
        if (!link) return;

        const url = link.href;

        if (!/^https?:\/\//i.test(url)) return;
        if (link.hasAttribute('download')) return;

        const parsedUrl = new URL(url);

        // 1. 搜索结果翻页:下一页、上一页、末页
        if (
            parsedUrl.searchParams.has('next') ||
            parsedUrl.searchParams.has('prev') ||
            parsedUrl.searchParams.has('page')
        ) {
            return;
        }

        // 2. 搜索结果分页区域:包括首页
        if (link.closest('.ptt, .ptb')) return;

        // 3. 画廊阅读页面翻页
        if (/^\/s\/[^/]+\/\d+-\d+\/?$/.test(parsedUrl.pathname)) {
            return;
        }

        // 4. 其他普通链接:新标签页打开
        e.preventDefault();
        e.stopPropagation();
        e.stopImmediatePropagation();

        GM_openInTab(url, {
            active: true,
            insert: true,
            setParent: true
        });

    }, true);

})();