summper-plus南+浏览优化

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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.');
            }
        }
    });
})();