尽人事,听天命。|

Jerrycyx

园龄:2年9个月粉丝:2关注:1

2025-03-06 16:29阅读: 107评论: 0推荐: 1

洛谷讨论区/专栏/云剪贴板续命(自动跳转保存站) v1.0

众所周知,由于某些特殊原因,洛谷讨论区倒闭了。国际站对国内用户封锁,专栏和云剪贴板也不再可用。

然而,过去的讨论区的部分帖子仍然可以用洛谷帖子保存站来查看,专栏和剪贴板也可以用新兴的洛谷保存站访问,但是为了避免每次都要麻烦地手动更改链接,我们需要一个方便的脚本。

v1.0 特性:

  • 检测讨论区帖子是否无法访问(因为某些管理员帖还是能看的),并自动跳转至洛谷帖子保存站
  • 对于国际站的专栏和云剪贴板,一律自动跳转至洛谷保存站

未来功能:

DeepSeek-R1 辅助了代码编写和调试,在此感谢!

// ==UserScript==
// @name 洛谷讨论区/专栏/云剪贴板续命
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 洛谷讨论区/专栏/云剪贴板自动重定向至相关保存站
// @author Jerrycyx
// @match https://www.luogu.com.cn/*
// @match https://www.luogu.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const currentUrl = window.location.href;
const path = window.location.pathname;
const host = window.location.hostname;
if (host === 'www.luogu.com') {
if (path.startsWith('/article/') || path.startsWith('/paste/')) {
const newUrl = `https://www.luogu.me${path}`;
window.location.replace(newUrl);
return;
}
}
if (path.startsWith('/discuss/')) {
const checkError = () => {
const errorDiv = document.querySelector('.card.message.padding-default');
if (errorDiv && errorDiv.textContent.includes('操作失败,请查看置顶帖')) {
const discussId = path.split('/')[2];
window.location.replace(`https://lglg.top/${discussId}`);
return true;
}
return false;
};
if (checkError()) return;
const observer = new MutationObserver(() => checkError());
observer.observe(document.body, {
childList: true,
subtree: true
});
setTimeout(() => observer.disconnect(), 10000);
}
})();
posted @   Jerrycyx  阅读(107)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起