跳到正文

科技·工程

洛谷龙笑

Enigma_Soul约 6 分钟
原文
文章信息与版本

文章信息

发布
2026年3月21日
收录
2026年9月20日
更新
2026年10月3日
篇幅
约 6 分钟

版本

  1. v1当前

原作者

让你讨厌的人的头像变成唐笑奶龙

这个改版支持了多人 打开主页 选择添加即可

油叉

JavaScript
// ==UserScript==
// @name         洛谷龙笑
// @namespace    https://www.luogu.com.cn/user/1326504
// @version      1.0.0
// @description  将你讨厌的人的头像换成奶龙唐笑
// @author       Enigma_Soul
// @author       cooluo
// @match        https://www.luogu.com.cn/*
// @icon         https://cdn.luogu.com.cn/upload/usericon/3.png
// @license      MIT
// @run-at       document-idle
// @grant        GM_registerMenuCommand
// @grant        GM_notification
// ==/UserScript==

(function() {
    'use strict';

    var IMG = 'https://gifbed.com/i/2026/03/21/202040.gif';
    var KEY = 'lg_block';
    var cache = null;  // 缓存屏蔽列表

    // 获取屏蔽列表(带缓存)
    function get() {
        if (cache === null) {
            try { cache = JSON.parse(localStorage[KEY]) || []; } catch(e) { cache = []; }
        }
        return cache;
    }
    function set(list) { localStorage[KEY] = JSON.stringify(list); cache = list; }

    // 替换头像
    function fix(img) {
        if (img._done) return;
        var m = img.src.match(/usericon\/(\d+)\./);
        if (!m) return;
        var uid = m[1];
        if (get().indexOf(uid) === -1) return;

        img.src = IMG;
        img._done = true;
    }

    // 主函数
    function run() {
        var imgs = document.querySelectorAll('img[src*="usericon"]');
        for (var i = 0; i < imgs.length; i++) fix(imgs[i]);
    }

    // 油猴菜单
    function menu() {
        var m = location.href.match(/\/user\/(\d+)/);
        if (!m) return;
        var uid = m[1];
        var list = get();
        var has = list.indexOf(uid) !== -1;

        if (has) {
            GM_registerMenuCommand('✅ 已添加 #' + uid + ' | 取消', function() {
                set(list.filter(function(x){ return x !== uid; }));
                location.reload();
            });
        } else {
            GM_registerMenuCommand('➕ 添加 #' + uid, function() {
                list.push(uid);
                set(list);
                location.reload();
            });
        }
        GM_registerMenuCommand('📋 列表(' + list.length + ')', function() {
            GM_notification({title:'龙笑列表', text: get().join(', ') || '空', timeout:2000});
        });
        GM_registerMenuCommand('🗑️ 清空', function() {
            if(confirm('确定清空?')) { set([]); location.reload(); }
        });
    }

    // 启动
    menu();
    run();

    var obs = new MutationObserver(function(mutations) {
        for (var i = 0; i < mutations.length; i++) {
            if (mutations[i].addedNodes.length) { run(); break; }
        }
    });
    obs.observe(document.body, { childList: true, subtree: true });

})();
原文