☰

E-Hentai Left Click New Tab

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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

})();