讨论区-优化

· · 科技·工程

可以快捷进入讨论帖(尤其是在题目讨论版中),日后还将优化

使用方法:油猴(或脚本猫等)进行运行,没有的自行下载

// ==UserScript==
// @name         洛谷讨论页面重定向
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  洛谷讨论页面优化
// @author       You
// @match        https://www.luogu.com.cn/discuss/*
// @match        https://www.luogu.com/article/*
// @match        https://www.luogu.com.cn/paste/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const currentUrl = window.location.href;

    const articleRegex = /https:\/\/www\.luogu\.com\.cn\/article\/(\d+)/;
https://www.luogu.com.cn/paste/剪贴板编号
    const pasteRegex = /https:\/\/www\.luogu\.com\.cn\/paste\/(\d+)/;
    if (articleRegex.test(currentUrl) || pasteRegex.test(currentUrl)) {
        let newUrl;

        if (articleRegex.test(currentUrl)) {
            newUrl = currentUrl.replace('https://www.luogu.com.cn/article/', 'https://www.luogu.me/article/');
        } else if (pasteRegex.test(currentUrl)) {
            newUrl = currentUrl.replace('https://www.luogu.com.cn/paste/', 'https://www.luogu.me/paste/');
        }
        navigator.clipboard.writeText(newUrl).then(() => {
            console.log(`已将以下 URL 复制到剪贴板: ${newUrl}`);
        }).catch(err => {
            console.error('复制 URL 失败:', err);
        });
    }
    const transitionDiv = document.createElement('div');
    transitionDiv.style.position = 'fixed';
    transitionDiv.style.top = '0';
    transitionDiv.style.left = '0';
    transitionDiv.style.width = '100%';
    transitionDiv.style.height = '100%';
    transitionDiv.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
    transitionDiv.style.color = 'white';
    transitionDiv.style.display = 'flex';
    transitionDiv.style.alignItems = 'center';
    transitionDiv.style.justifyContent = 'center';
    transitionDiv.style.fontSize = '24px';
    transitionDiv.style.zIndex = '9999';
    transitionDiv.style.transition = 'opacity 0.5s';
    const loadingText = document.createElement('span');
    loadingText.textContent = '正在跳转到新页面,Loading...';
    transitionDiv.appendChild(loadingText);
    document.body.appendChild(transitionDiv);
    const discussRegex = /https:\/\/www\.luogu\.com\.cn\/discuss\/(\d+)/;
    const match = currentUrl.match(discussRegex);

    if (match) {
        const problemId = match[1];
        const newUrl = `https://lglg.top/${problemId}`;
        setTimeout(() => {
            transitionDiv.style.opacity = '0';
            setTimeout(() => {
                window.location.href = newUrl;
            }, 500);
        }, 1000);
    }
})();