☰

E-Hentai Left Click New Tab

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

スクリプトをインストールするには、Tampermonkey, Greasemonkey や Violentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、 Tampermonkey や Violentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、Tampermonkey や Violentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、Tampermonkey や Userscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら、通報はこちらへお寄せください
// ==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);

})();