跳到正文

个人记录

删犇器

a_small_OIer约 8 分钟
原文

这是 2026年5月8日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

收录
2026年5月8日
更新
2026年7月11日
篇幅
约 8 分钟

版本

  1. v2当前
  2. v1

由于一遍遍在控制台写代码太麻烦了,于是写了一个插件,适用于需要频繁删犇的人群。

免责声明

这个删犇器参考了常见的这个版本,同样是 300ms300 ms 间隔,对于可能出现的 403 乃至封禁,作者概不负责。

温馨提示:犇犇不可找回,删前请慎重考虑。

源代码:

JavaScript
// ==UserScript==
// @name         删犇器
// @namespace    http://tampermonkey.net/
// @version      2.3
// @description  一键删除犇犇
// @author       a_small_OIer
// @match        www.luogu.com.cn
// @grant        none
// ==/UserScript==
(function() {
    'use strict';
    function init() {
        if (typeof $ === 'undefined' || typeof switchMode !== 'function') {
            setTimeout(init, 100);
            return;
        }
        const $startBtn = $('<button>')
            .text('一键删除犇犇')
            .css({
                position: 'fixed',
                bottom: '20px',
                right: '20px',
                zIndex: 9999,
                background: '#e74c3c',
                color: 'white',
                border: 'none',
                padding: '10px 20px',
                borderRadius: '4px',
                cursor: 'pointer',
                fontSize: '14px'
            });
        $('body').append($startBtn);
        let stopped = false;
        $startBtn.on('click', function() {
            if (!confirm('确定要删除所有犇犇吗?删错了可找不回来哦')) {
                return;
            }

            $startBtn.text('删除中......').prop('disabled', true);
            console.log('[删犇器] 开始后台删除犇犇');
            stopped = false;
            const feedMode = 'my';
            let feedPage = 1;
            switchMode('my');
            setTimeout(loadAndDelete, 1000);
            function loadAndDelete() {
                if (stopped) return;
                $.get('/feed/' + feedMode + '?page=' + feedPage, function(resp) {
                    if (stopped) return;
                    if (resp.indexOf('没有更多动态了') !== -1) {
                        console.log('[删犇器] 所有犇犇已删除完毕');
                        $startBtn.text('完成!').prop('disabled', true);
                        return;
                    }
                    const $html = $('<div>').html(resp);
                    const feedIds = [];
                    $html.find('[data-feed-id]').each(function() {
                        const id = $(this).attr('data-feed-id');
                        if (id) feedIds.push(id);
                    });
                    console.log(`[删犇器] 第 ${feedPage} 页,共 ${feedIds.length} 条动态`);
                    function deleteNext(index) {
                        if (stopped) return;

                        if (index >= feedIds.length) {
                            feedPage++;
                            setTimeout(loadAndDelete, 200);
                            return;
                        }
                        const currentId = feedIds[index];
                        $.post('/api/feed/delete/' + currentId, function() {
                            console.log(`[删犇器] 已删除 ID:${currentId}`);
                            setTimeout(() => deleteNext(index + 1), 300);
                        }).fail(function(jqXHR) {
                            if (jqXHR.status === 403) {
                                stopped = true;
                                $startBtn.text('开始删除全部犇犇').prop('disabled', false);
                                alert('删除请求被拒绝(403),可能操作频率过高,已停止,请稍后再试');
                                return;
                            }
                            console.warn(`[删犇器] 删除失败 ID:${currentId} (${jqXHR.status}),已跳过`);
                            setTimeout(() => deleteNext(index + 1), 300);
                        });
                    }

                    deleteNext(0);
                });
            }
        });
    }
    init();
})();

.js 文件:https://www.luogu.com.cn/problem/U684323