洛谷专栏/云剪贴板续命脚本(自动跳转保存站+判断是否封锁+自动修改安全访问链接) v1.2

v1.2 特性:

  • 检测讨论区帖子是否无法访问(因为某些管理员帖还是能看的),无法访问的自动跳转至洛谷帖子保存站 洛谷讨论区已经复活,此项功能不再需要,普天同庆!
  • 对于国际站的专栏和云剪贴板,一律自动跳转至洛谷保存站
  • 在“安全访问中心”(即洛谷跳转至国际站的中转点)处,直接修改目标链接。

此部分内容前置以方便搜索引擎获取网页简介。


2025.4.2 更新:由于洛谷讨论区已经复活,讨论区不再需要脚本续命,此脚本改名为“洛谷专栏/云剪贴板续命脚本”,普天同庆!

闲话

起初,大家都以为这仅仅是一个愚人节整活……

image

但我们仍心怀希望……

image

直到,在夜深人静的夜晚,放不下讨论区的用户们看到了……

image

那是一段漫长的等待,但它是值得的。

image

希望历史不会再重蹈覆辙,祝愿洛谷讨论区能永远继续下去!

image


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

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

未来功能:

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


v1.2 代码,需配合 TamperMonkey 使用,脚本安装方法请自行搜索。

// ==UserScript==
// @name         洛谷专栏/云剪贴板续命
// @namespace    https://www.cnblogs.com/jerrycyx/p/18755697
// @version      1.2
// @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(host === 'www.luogu.com.cn' && (path.startsWith('/article/') || path.startsWith('/paste/'))) {
        const warningTitle = document.querySelector('body > div:nth-child(1) > div > h3');
        if (document.title == '安全访问中心 - 洛谷' && warningTitle.textContent.trim() == '即将离开洛谷') {
            const urlElement = document.querySelector('#url');
            if (urlElement) {
                urlElement.textContent = urlElement.textContent
                    .replace('luogu.com', 'luogu.me')
                    .replace('luogu.com.cn', 'luogu.me');
            }

            const continueLink = document.querySelector('body > div:nth-child(1) > div > p:nth-child(5) > a');
            if (continueLink) {
                continueLink.href = continueLink.href
                    .replace('luogu.com', 'luogu.me')
                    .replace('luogu.com.cn', 'luogu.me');
            }
        }
       return;
    }
})();

旧版本留档

v1.0
// ==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);
    }
})();
v1.1
// ==UserScript==
// @name         洛谷讨论区/专栏/云剪贴板续命
// @namespace    http://tampermonkey.net/
// @version      1.1
// @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);
    }

    if(host === 'www.luogu.com.cn' && (path.startsWith('/article/') || path.startsWith('/paste/'))) {
        const warningTitle = document.querySelector('body > div:nth-child(1) > div > h3');
        if (document.title == '安全访问中心 - 洛谷' && warningTitle.textContent.trim() == '即将离开洛谷') {
            const urlElement = document.querySelector('#url');
            if (urlElement) {
                urlElement.textContent = urlElement.textContent
                    .replace('luogu.com', 'luogu.me')
                    .replace('luogu.com.cn', 'luogu.me');
            }

            const continueLink = document.querySelector('body > div:nth-child(1) > div > p:nth-child(5) > a');
            if (continueLink) {
                continueLink.href = continueLink.href
                    .replace('luogu.com', 'luogu.me')
                    .replace('luogu.com.cn', 'luogu.me');
            }
        }
       return;
    }
})();
posted @ 2025-03-06 16:29  Jerrycyx  阅读(3375)  评论(0)    收藏  举报