summper-plus南+浏览优化

只有详情会打开新页签,分页查询不会处理

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 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         summper-plus南+浏览优化
// @namespace    www.summer-plus.net
// @version      1.0.1
// @description  只有详情会打开新页签,分页查询不会处理
// @author       JunKai Wang
// @match        *://www.summer-plus.net/*
// @match        *://www.spring-plus.net/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 获取页面根 URL
    const baseUrl = window.location.protocol + "//" + window.location.hostname;

    // 为整个页面添加事件监听,使用事件委托
    document.body.addEventListener('click', function(event) {
        const link = event.target.closest('a');  // 获取最近的 <a> 标签

        // 确保点击的是一个 <a> 标签且 href 属性存在
        if (link && link.href) {
            const href = link.getAttribute('href');
            // 如果链接是相对路径,将其转换为完整 URL
            const fullHref = href.startsWith('http') ? href : baseUrl + '/' + href;
            // console.log('Full URL:', fullHref);

            // 使用 URL 对象提取路径部分
            const url = new URL(fullHref);
            const pathname = url.pathname;
            // console.log('Pathname:', pathname);

            // 使用正则表达式确保路径中是独立的 'read.php'
            const isReadLink = /\/read\.php/.test(pathname);  // 确保是独立的 read.php
            // console.log('Is read.php link:', isReadLink);

            if (isReadLink) {
                // 如果是 read.php 链接,在新标签页打开
                event.preventDefault();
                window.open(fullHref, '_blank');  // 在新标签页打开链接
            } else {
                // 对其他链接不做处理
                // console.log('No action for thread.php or other links.');
            }
        }
    });
})();