Luogu Blog & Paste Auto-Redirect Userscript

This userscript siletnly fixes three common haedaches when browsing Luogu from mainland China:

  1. International site (luogu.com) blocks are bypassed by rewriting the domain to luogu.me.
  2. Domestic "Safe Access Center" interstitial pages have their outbound links patched so you land directly on the mirror instead of bouncing through the warning screen.
  3. No manual URL editing is ever required again.

Installation

  1. Install Tampermonkey (Chrome/Edge) or Violentmonkey (Firefox).
  2. Create a new userscript and paste the code below.
  3. Save and reload any Luogu page to test.

Current version 1.2

// ==UserScript==
// @name         Luogu Blog & Paste Auto-Redirect
// @namespace    https://example.com/luogu-redirect
// @version      1.2
// @description  Automatically redirect Luogu blogs and pastes to luogu.me mirror
// @author       anonymous
// @match        https://www.luogu.com/*
// @match        https://www.luogu.com.cn/*
// @grant        none
// ==/UserScript==

(() => {
    'use strict';

    const { hostname, pathname } = location;

    // 1. Redirect international site immediately
    if (hostname === 'www.luogu.com') {
        if (pathname.startsWith('/article/') || pathname.startsWith('/paste/')) {
            location.replace(`https://www.luogu.me${pathname}`);
            return;
        }
    }

    // 2. Patch Safe Access Center links
    if (hostname === 'www.luogu.com.cn') {
        if (pathname.startsWith('/article/') || pathname.startsWith('/paste/')) {
            const heading = document.querySelector('body > div:nth-child(1) > div > h3');
            if (document.title === '安全访问中心 - 洛谷' && heading?.textContent.trim() === '即将离开洛谷') {
                const urlBox = document.querySelector('#url');
                if (urlBox) {
                    urlBox.textContent = urlBox.textContent
                        .replace(/luogu\.com(\.cn)?/g, 'luogu.me');
                }

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

Changelog

  • v1.2 (2025-04-02) – Removed discuss-section logic after Luogu restored access; renamed script accordingly.
  • v1.1 – Added Safe Access Center patching.
  • v1.0 – Initial release covering blogs, pastes, and discuss.

Roadmap

li>Toggle switch to enable/disable redirection per page. - Settings panel for custom mirror domains.

Tags: userscript Tampermonkey luogu redirect greasemonkey

Posted on Thu, 30 Jul 2026 16:19:47 +0000 by bl00dshooter