页面ID快速跳转

显示当前页面ID,并允许通过快捷键增减ID来跳转页面

目前為 2024-09-09 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==  
// @name         页面ID快速跳转  
// @namespace    http://tampermonkey.net/  
// @version      0.1  
// @description  显示当前页面ID,并允许通过快捷键增减ID来跳转页面  
// @author       Your Name  
// @match        *://*/*  
// @license      LGPL
// @grant        none  
// ==/UserScript==   
  
(function() {  
    'use strict';  
  
    // 存储解析后的URL部分  
    let baseUrl = '';  
    let pageId = '';  
    let extension = '';  
  
    // 解析URL的函数  
    function parseUrl() {  
        const url = window.location.href;  
        const regex = /([^/]*\/?)([^/\.]*?)(\.(html|jsp|htm|php))$/i;  
        const match = url.match(regex);  
  
        if (match) {  
            baseUrl = match[1];  
            pageId = match[2];  
            extension = match[3];  
  
            // 检查pageId是否全为数字  
            if (!/^\d+$/.test(pageId)) {  
                pageId = '';  
            }  
        }  
  
        updateDisplay();  
    }  
  
    // 更新页面ID显示  
    function updateDisplay() {  
        const displayDiv = document.getElementById('pageIdDisplay');  
        if (!displayDiv) {  
            const newDiv = document.createElement('div');  
            newDiv.id = 'pageIdDisplay';  
            newDiv.style.position = 'fixed';  
            newDiv.style.bottom = '20px';  
            newDiv.style.right = '20px';  
            newDiv.style.fontSize = '36px';  
            newDiv.style.color = 'orange';  
            newDiv.style.zIndex = '10000';  
            newDiv.style.padding = '5px 10px';  
            newDiv.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';  
            newDiv.style.borderRadius = '10px';  
            document.body.appendChild(newDiv);  
        }  
        displayDiv.textContent = 'Page ID: ' + (pageId || 'Not Found');  
    }  
  
    // 处理键盘快捷键  
    document.addEventListener('keydown', function(event) {  
        if (!pageId) return;  
  
        const currentId = parseInt(pageId, 10);  
        let newId = '';  
  
        if (event.ctrlKey && event.key === 'ArrowRight') {  
            newId = (currentId + 1).toString();  
        } else if (event.ctrlKey && event.key === 'ArrowLeft') {  
            newId = (currentId - 1).toString();  
        }  
  
        if (newId) {  
            const newUrl = baseUrl + newId + extension;  
            window.location.href = newUrl;  
        }  
    });  
  
    // 页面加载完成后解析URL  
    window.onload = parseUrl;  
})();