洛谷链接自动跳转器
HuangRuibo · · 个人记录
洛谷链接自动跳转器——使用说明
【 luogu.me 保存站版 】
温馨提示\scriptsize: 观看前建议再更新一下
创作背景
近日,kkksc03 应不知名原因关闭了洛谷的讨论区
· 本代码依赖于篡改猴 !
代码Code:
// ==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