专栏文章

洛谷链接自动跳转器

个人记录参与者 1已保存评论 1

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
1 条
当前快照
1 份
快照标识符
@miq2uydg
此快照首次捕获于
2025/12/03 22:03
3 个月前
此快照最后确认于
2025/12/03 22:03
3 个月前
查看原文

洛谷链接自动跳转器——使用说明

【 luogu.me 保存站版 】

温馨提示\scriptsize:观看前建议再更新一下


创作背景

近日,kkksc03 应不知名原因关闭了洛谷的讨论区\small(详见 置顶帖---此为保留帖子lglg保存版 \small),还禁止了国内的IP进入洛谷国际站\small(www.luogu.com \small)。因此,我制作了 洛谷链接自动跳转器(luogu浏览版) | (luogu.me浏览版) | (m1.luogu.me浏览版) | (m2.luogu.me浏览版) | (mirror.luogu.me浏览版)

· 本代码依赖于篡改猴 !

代码Code:

JAVASCRIPT
// ==UserScript==
// @name         洛谷链接自动跳转器
// @namespace    http://tampermonkey.net/
// @version      1.0.1_beta
// @description  自动将特定洛谷链接重定向到指定域名
// @author       HuangRuibo (luogu_uid:1286421)
// @match        *://www.luogu.com.cn/discuss/*
// @match        *://www.luogu.com.cn/article/*
// @match        *://www.luogu.com.cn/paste/*
// @match        *://www.luogu.com/discuss/*
// @match        *://www.luogu.com/article/*
// @match        *://www.luogu.com/paste/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // 定义目标域名
    const targetDomains = {
        discuss: 'https://lglg.top',
        article: 'https://www.luogu.me/article',
        paste: 'https://www.luogu.me/paste'
    };

    // 获取当前完整路径
    const currentUrl = window.location.href;

    // 排除写文章的页面
    const isWritingArticle = /^https:\/\/www\.luogu\.com\.cn\/article\/(mine|_new|\w+\/edit)$/.test(currentUrl);
    if (isWritingArticle) {
        return; // 如果是写文章的页面,则不进行跳转
    }

    // 处理 discuss 跳转逻辑(数字ID)
    const discussMatch = currentUrl.match(/^https:\/\/www\.luogu\.com\.cn\/discuss\/(\d+)$/);
    if (discussMatch) {
        window.location.replace(`${targetDomains.discuss}/${discussMatch[1]}`);
    }
    // 处理 article 跳转逻辑(字符串ID)
    const articleMatch = currentUrl.match(/^https:\/\/www\.luogu\.com\.cn\/article\/([^\/]+)$/);
    if (articleMatch) {
        window.location.replace(`${targetDomains.article}/${articleMatch[1]}`);
    }
    // 处理 paste 跳转逻辑(字符串ID)
    const pasteMatch = currentUrl.match(/^https:\/\/www\.luogu\.com\.cn\/paste\/([^\/]+)$/);
    if (pasteMatch) {
        window.location.replace(`${targetDomains.paste}/${pasteMatch[1]}`);
    }
})();

/*
水印 | 水印 | 水印 | 水印 | 水印 | 水印
此代码来自HuangRuibo(luogu_uid:1286421)
水印 | 水印 | 水印 | 水印 | 水印 | 水印
*/

此为 1.0.1_beta 版,如有其他需求,请 @HuangRuibo

评论

1 条评论,欢迎与作者交流。

正在加载评论...