Reorder Showtopic URL Parameters

将showtopic前的参数移动到后面,使showtopic位于首位

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Reorder Showtopic URL Parameters
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  将showtopic前的参数移动到后面,使showtopic位于首位
// @author       1415ddfer
// @license MIT
// @match        https://forums.e-hentai.org/index.php*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    const url = new URL(location.href);
    const rawSearch = url.search;

    // 没有查询参数或没有showtopic,直接放行
    if (!rawSearch || !rawSearch.includes('showtopic=')) return;

    // 解析原始查询字符串,保持参数顺序
    const params = [];
    const searchParams = new URLSearchParams(rawSearch);
    for (const [key, value] of searchParams) {
        params.push({ key, value });
    }

    // 找到showtopic的索引
    const showtopicIndex = params.findIndex(p => p.key === 'showtopic');
    if (showtopicIndex === -1) return;

    // showtopic已经在最前面,放行
    if (showtopicIndex === 0) return;

    // 重组参数:showtopic放最前,其余按原顺序排列
    const showtopicParam = params[showtopicIndex];
    const otherParams = params.filter((_, i) => i !== showtopicIndex);
    const reorderedParams = [showtopicParam, ...otherParams];

    // 构建新的查询字符串
    const newSearch = reorderedParams.map(p => {
        if (p.value === '') return encodeURIComponent(p.key);
        return encodeURIComponent(p.key) + '=' + encodeURIComponent(p.value);
    }).join('&');

    const cleanUrl = url.origin + url.pathname + '?' + newSearch + url.hash;

    // 显示提示并跳转
    document.documentElement.innerHTML = `
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>正在整理链接参数...</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            color: #333;
        }
        .box {
            background: white;
            padding: 48px 40px;
            border-radius: 16px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.15);
            text-align: center;
            max-width: 560px;
            width: 90%;
            animation: fadeIn 0.4s ease;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .icon {
            width: 64px; height: 64px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 24px;
            font-size: 28px;
        }
        h2 { font-size: 22px; margin-bottom: 12px; color: #1a1a2e; }
        .desc { color: #666; font-size: 15px; line-height: 1.7; margin-bottom: 24px; }
        .url-box {
            background: #f8f9fa;
            border: 1px solid #e9ecef;
            border-radius: 10px;
            padding: 16px;
            margin-bottom: 12px;
            text-align: left;
        }
        .url-label {
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 1px;
            color: #999;
            margin-bottom: 6px;
            font-weight: 600;
        }
        .url {
            font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
            font-size: 13px;
            word-break: break-all;
            line-height: 1.5;
        }
        .url-old { color: #dc3545; }
        .url-new { color: #28a745; }
        .arrow {
            text-align: center;
            color: #999;
            font-size: 20px;
            margin: 8px 0;
        }
        .spinner {
            width: 36px; height: 36px;
            border: 3px solid #e9ecef;
            border-top-color: #667eea;
            border-radius: 50%;
            animation: spin 0.8s linear infinite;
            margin: 24px auto 16px;
        }
        @keyframes spin { to { transform: rotate(360deg); } }
        .status {
            color: #667eea;
            font-size: 14px;
            font-weight: 500;
        }
        .manual {
            margin-top: 16px;
            font-size: 12px;
            color: #999;
        }
        .manual a {
            color: #667eea;
            text-decoration: none;
        }
        .manual a:hover { text-decoration: underline; }
    </style>
</head>
<body>
    <div class="box">
        <div class="icon">🔗</div>
        <h2>正在整理 URL 参数顺序</h2>
        <p class="desc">检测到 <code>showtopic</code> 前面有其他参数,正在自动将其移至首位...</p>
        <div class="url-box">
            <div class="url-label">原始链接</div>
            <div class="url url-old">${location.href}</div>
        </div>
        <div class="arrow">↓</div>
        <div class="url-box">
            <div class="url-label">整理后链接</div>
            <div class="url url-new">${cleanUrl}</div>
        </div>
        <div class="spinner"></div>
        <div class="status">正在跳转,请稍候...</div>
        <div class="manual">若未自动跳转,请 <a href="${cleanUrl}">点击此处</a></div>
    </div>
</body>
</html>
    `;

    // 1.5秒后跳转
    setTimeout(() => {
        location.replace(cleanUrl);
    }, 500);

})();