You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求开发JavaScript脚本:提取input值生成URL直至值为-1并打开

Auto-Navigate to Final Forum Page with JavaScript

I’ve put together a couple of practical solutions to automate this process—one you can run directly in your browser’s console for quick use, and a seamless userscript that handles navigation automatically.

Option 1: Console Script (Quick Manual Execution)

This script checks the current page, navigates to the next page if needed, and you can re-run it on each new page until you hit the final URL.

// Configure these values to match your forum's setup
const INPUT_NAME = "nextPage"; // Name attribute of the input element to target
const BASE_URL = "https://your-forum-domain.com/thread?page="; // Base URL pattern (append the input value to this)

function checkAndNavigate() {
  // Find the input element by its name attribute
  const nextInput = document.querySelector(`input[name="${INPUT_NAME}"]`);
  
  if (!nextInput) {
    alert(`Couldn't find input with name "${INPUT_NAME}"!`);
    return;
  }

  const nextValue = nextInput.value.trim();

  if (nextValue === "-1") {
    alert(`Final URL found: ${window.location.href}`);
    // Optional: Uncomment below to open the final URL in a new tab
    // window.open(window.location.href, "_blank");
    return;
  }

  // Build the next page URL and navigate
  const nextUrl = `${BASE_URL}${nextValue}`;
  console.log(`Navigating to: ${nextUrl}`);
  window.location.href = nextUrl;
}

// Run the function immediately
checkAndNavigate();

How to use:

  1. Open your browser’s developer tools (F12 or Ctrl+Shift+I)
  2. Switch to the "Console" tab
  3. Paste the script, update INPUT_NAME and BASE_URL to match your forum’s structure
  4. Press Enter to run it. Repeat this step on each new page until you reach the final URL.

Option 2: Tampermonkey Userscript (Hands-Off Automatic Navigation)

For a fully automated experience, use a userscript manager like Tampermonkey to run the script every time you load a forum page. This handles all navigations without manual input.

// ==UserScript==
// @name         Forum Final Page Auto-Navigator
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Automatically navigates to the final forum page using the nextPage input value
// @author       Your Name
// @match        https://your-forum-domain.com/* // Replace with your forum's URL pattern
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Configuration
    const INPUT_NAME = "nextPage";
    const BASE_URL = "https://your-forum-domain.com/thread?page=";

    function navigateToFinal() {
        const nextInput = document.querySelector(`input[name="${INPUT_NAME}"]`);
        
        if (!nextInput) {
            console.log(`Input "${INPUT_NAME}" not found—stopping.`);
            return;
        }

        const nextValue = nextInput.value.trim();

        if (nextValue === "-1") {
            console.log(`Final page reached: ${window.location.href}`);
            return;
        }

        const nextUrl = `${BASE_URL}${nextValue}`;
        console.log(`Auto-navigating to next page: ${nextUrl}`);
        window.location.href = nextUrl;
    }

    // Run when the page is fully loaded
    window.addEventListener('load', navigateToFinal);
})();

How to use:

  1. Install Tampermonkey (or another userscript manager) for your browser
  2. Create a new userscript
  3. Replace the template code with the script above
  4. Update the @match line to match your forum’s URL (e.g., https://forum.example.com/threads/*)
  5. Adjust INPUT_NAME and BASE_URL to fit your forum’s setup
  6. Save the script—it will now run automatically whenever you load a matching forum page.

Key Notes:

  • Double-check the BASE_URL to ensure it matches your forum’s next-page pattern (e.g., if the URL uses ?threadId= instead of ?page=, update accordingly).
  • If the input element uses a different name (not "nextPage"), modify the INPUT_NAME variable to match.
  • The script stops and notifies you when it finds the input with value -1—that’s your final URL.

内容的提问来源于stack exchange,提问作者Double Shadow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:13:18