☰

E-Hentai Left Click New Tab

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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

})();