☰

E-Hentai Left Click New Tab

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

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

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.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);

})();