跳到正文

个人记录

删犇器

a_small_OIer约 31 分钟
原文
文章信息与版本

文章信息

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

版本

  1. v2当前
  2. v1

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

免责声明

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

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

updateupdate

1.0版1.0版:首个发布版,支持犇犇全部删除

2.1版2.1版:优化了 UI,支持时间筛选 DeepSeek 真的太好用了你们知道吗

源代码
2.12.1 版源代码
JavaScript
// ==UserScript==
// @name         删犇器
// @namespace    http://tampermonkey.net/
// @version      2.1
// @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 style = document.createElement('style');
        style.textContent = `
            .ts-feed-panel {
                font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
                position: fixed;
                bottom: 24px;
                right: 24px;
                z-index: 99999;
                background: #ffffff;
                border: 1px solid #e0e0e0;
                border-radius: 12px;
                box-shadow: 0 4px 24px rgba(0,0,0,0.12);
                padding: 16px 18px;
                width: 280px;
                display: flex;
                flex-direction: column;
                gap: 12px;
                transition: box-shadow 0.2s;
            }
            .ts-feed-panel:hover {
                box-shadow: 0 6px 30px rgba(0,0,0,0.16);
            }
            .ts-panel-title {
                font-size: 15px;
                font-weight: 600;
                color: #333;
                margin: 0;
                display: flex;
                align-items: center;
                gap: 6px;
            }
            .ts-option-row {
                display: flex;
                align-items: center;
                gap: 6px;
            }
            .ts-option-row label {
                font-size: 13px;
                color: #444;
                cursor: pointer;
                user-select: none;
            }
            .ts-time-row {
                display: flex;
                flex-direction: column;
                gap: 8px;
                opacity: 1;
                transition: opacity 0.2s, max-height 0.3s;
                overflow: hidden;
                max-height: 150px;
            }
            .ts-time-row.hidden {
                opacity: 0;
                max-height: 0;
                margin: 0;
                pointer-events: none;
            }
            .ts-time-field {
                display: flex;
                flex-direction: column;
                gap: 4px;
            }
            .ts-time-field label {
                font-size: 12px;
                font-weight: 500;
                color: #555;
                margin-left: 2px;
            }
            .ts-time-field input {
                border: 1px solid #d0d0d0;
                border-radius: 6px;
                padding: 6px 8px;
                font-size: 13px;
                width: 100%;
                box-sizing: border-box;
                transition: border-color 0.2s;
                background: #fafafa;
            }
            .ts-time-field input:focus {
                border-color: #4a90d9;
                background: #fff;
                outline: none;
                box-shadow: 0 0 0 2px rgba(74,144,217,0.15);
            }
            .ts-status-area {
                font-size: 12px;
                color: #888;
                min-height: 18px;
                line-height: 18px;
                display: flex;
                align-items: center;
                gap: 6px;
            }
            .ts-status-area .ts-spinner {
                display: none;
                width: 14px;
                height: 14px;
                border: 2px solid #e0e0e0;
                border-top: 2px solid #4a90d9;
                border-radius: 50%;
                animation: ts-spin 0.8s linear infinite;
            }
            @keyframes ts-spin { to { transform: rotate(360deg); } }
            .ts-delete-btn {
                background: #e74c3c;
                color: white;
                border: none;
                padding: 10px 0;
                border-radius: 8px;
                font-size: 14px;
                font-weight: 600;
                cursor: pointer;
                transition: background 0.2s, transform 0.1s;
                width: 100%;
                text-align: center;
            }
            .ts-delete-btn:hover:not(:disabled) {
                background: #c0392b;
                transform: translateY(-1px);
            }
            .ts-delete-btn:active:not(:disabled) {
                transform: translateY(0);
            }
            .ts-delete-btn:disabled {
                background: #ccc;
                cursor: not-allowed;
                transform: none;
            }
            .ts-delete-btn.completed {
                background: #27ae60;
            }
        `;
        document.head.appendChild(style);
        // 构建面板
        const $panel = $('<div class="ts-feed-panel">');
        const $title = $('<div class="ts-panel-title">').text('犇犇一键删除');
        const $optionRow = $('<div class="ts-option-row">');
        const $checkbox = $('<input type="checkbox" id="ts-enable-timerange">');
        const $checkboxLabel = $('<label for="ts-enable-timerange">启用时间范围筛选</label>');
        $optionRow.append($checkbox, $checkboxLabel);
        const $timeRow = $('<div class="ts-time-row hidden">');
        const $startField = $('<div class="ts-time-field">');
        $startField.append('<label>开始时间(含)</label>');
        const $startInput = $('<input type="datetime-local" placeholder="不限">');
        $startField.append($startInput);
        const $endField = $('<div class="ts-time-field">');
        $endField.append('<label>结束时间(含)</label>');
        const $endInput = $('<input type="datetime-local" placeholder="不限">');
        $endField.append($endInput);
        $timeRow.append($startField, $endField);
        const $statusArea = $('<div class="ts-status-area">');
        const $spinner = $('<div class="ts-spinner">');
        const $statusText = $('<span>').text('就绪');
        $statusArea.append($spinner, $statusText);
        const $startBtn = $('<button class="ts-delete-btn">删除全部犇犇</button>');
        $panel.append($title, $optionRow, $timeRow, $statusArea, $startBtn);
        $('body').append($panel);
        $checkbox.on('change', function() {
            if (this.checked) {
                $timeRow.removeClass('hidden');
                $startBtn.text('开始删除选中犇犇');
            } else {
                $timeRow.addClass('hidden');
                $startBtn.text('开始删除选中犇犇');
                $startInput.val('');
                $endInput.val('');
            }
        });
        let stopped = false;
        function setStatus(text, showSpinner = false) {
            $statusText.text(text);
            $spinner.css('display', showSpinner ? 'block' : 'none');
        }
        $startBtn.on('click', function() {
            if ($startBtn.prop('disabled')) return;

            const useTimeRange = $checkbox.is(':checked');
            let startTime = null, endTime = null;

            if (useTimeRange) {
                const startVal = $startInput.val();
                const endVal = $endInput.val();
                startTime = startVal ? new Date(startVal) : null;
                endTime = endVal ? new Date(endVal) : null;

                if ((startVal && isNaN(startTime.getTime())) || (endVal && isNaN(endTime.getTime()))) {
                    alert('时间格式错误啦啊喂');
                    return;
                }
                if (startTime && endTime && startTime > endTime) {
                    alert('开始时间不能晚于结束时间');
                    return;
                }
            }

            if (!confirm(useTimeRange ? '真的要删除指定时间范围内的所有犇犇吗?删掉了可就找不回来啦' : '真的要删除所有犇犇吗?删掉了可就找不回来啦')) {
                return;
            }
            $startBtn.text('删除中……').prop('disabled', true).removeClass('completed');
            setStatus('正在准备...', true);
            console.log('[删犇器] 开始删除' + (useTimeRange ? `,时间区间:${startTime ? startTime.toLocaleString() : '不限'} ~ ${endTime ? endTime.toLocaleString() : '不限'}` : '所有动态'));
            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).addClass('completed');
                        setStatus('全部删除完成', false);
                        return;
                    }

                    const $html = $('<div>').html(resp);
                    const rawItems = [];

                    $html.find('[data-feed-id]').each(function() {
                        const $el = $(this);
                        const feedId = $el.attr('data-feed-id');
                        if (!feedId) return;

                        const $container = $el.closest('li, .feed-item, article');
                        const timeStr = extractTime($container.length ? $container : $el);
                        const time = timeStr ? new Date(timeStr) : null;

                        if (timeStr && !isNaN(time.getTime())) {
                            rawItems.push({ id: feedId, time: time });
                        }
                    });
                    if (!useTimeRange) {
                        const allIds = [];
                        $html.find('[data-feed-id]').each(function() {
                            const id = $(this).attr('data-feed-id');
                            if (id) allIds.push(id);
                        });
                        console.log(`[删犇器] 第 ${feedPage} 页,共 ${allIds.length} 条动态(无时间筛选)`);
                        setStatus(`第 ${feedPage} 页,待删除 ${allIds.length} 条`, true);
                        deleteAllArray(allIds, 0);
                        return;
                    }
                    if (rawItems.length === 0) {
                        console.log(`[删犇器] 第 ${feedPage} 页无有效时间动态,跳过`);
                        setStatus(`跳过第 ${feedPage} 页(无时间数据)`, true);
                        feedPage++;
                        setTimeout(loadAndDelete, 200);
                        return;
                    }
                    const newestTime = rawItems[0].time;
                    const oldestTime = rawItems[rawItems.length - 1].time;
                    if (startTime && newestTime < startTime) {
                        console.log('[删犇器] 本页犇犇均早于开始时间,停止翻页');
                        $startBtn.text('完成!').prop('disabled', true).addClass('completed');
                        setStatus('已完成(超出时间范围)', false);
                        return;
                    }
                    if (endTime && oldestTime > endTime) {
                        console.log(`[删犇器] 第 ${feedPage} 页动态均晚于结束时间,跳过本页`);
                        setStatus(`跳过第 ${feedPage} 页(太新)`, true);
                        feedPage++;
                        setTimeout(loadAndDelete, 200);
                        return;
                    }

                    const toDelete = rawItems.filter(item => {
                        if (startTime && item.time < startTime) return false;
                        if (endTime && item.time > endTime) return false;
                        return true;
                    });

                    setStatus(`第 ${feedPage} 页,待删除 ${toDelete.length}/${rawItems.length} 条`, true);
                    deleteArray(toDelete, 0);
                });
            }
            function deleteAllArray(ids, index) {
                if (stopped) return;
                if (index >= ids.length) {
                    feedPage++;
                    setTimeout(loadAndDelete, 200);
                    return;
                }
                const currentId = ids[index];
                $.post('/api/feed/delete/' + currentId, function() {
                    setStatus(`已删 ${index+1}/${ids.length} (ID:${currentId})`, true);
                    console.log(`[删犇器] 已删除 ID:${currentId}`);
                    setTimeout(() => deleteAllArray(ids, index + 1), 300);
                }).fail(function(jqXHR) {
                    if (jqXHR.status === 403) {
                        stopped = true;
                        $startBtn.text('重新开始删除').prop('disabled', false).removeClass('completed');
                        setStatus('403 错误,已停止', false);
                        alert('删除请求被拒绝啦(403),可能操作频率过高,已停止');
                        return;
                    }
                    setStatus(`删除失败 ${currentId},继续`, true);
                    console.warn(`[删犇器] 删除失败 ID:${currentId} (${jqXHR.status}),跳过`);
                    setTimeout(() => deleteAllArray(ids, index + 1), 300);
                });
            }
            function deleteArray(items, index) {
                if (stopped) return;
                if (index >= items.length) {
                    feedPage++;
                    setTimeout(loadAndDelete, 200);
                    return;
                }
                const current = items[index];
                $.post('/api/feed/delete/' + current.id, function() {
                    setStatus(`已删 ${index+1}/${items.length} (ID:${current.id})`, true);
                    console.log(`[删犇器] 已删除 ID:${current.id} (${current.time.toLocaleString()})`);
                    setTimeout(() => deleteArray(items, index + 1), 300);
                }).fail(function(jqXHR) {
                    if (jqXHR.status === 403) {
                        stopped = true;
                        $startBtn.text('重新开始删除').prop('disabled', false).removeClass('completed');
                        setStatus('403 错误,已停止', false);
                        alert('删除请求被拒绝(403),可能操作频率过高,已自动停止。');
                        return;
                    }
                    setStatus(`删除失败 ${current.id},继续`, true);
                    console.warn(`[删犇器] 删除失败 ID:${current.id} (${jqXHR.status}),继续下一条`);
                    setTimeout(() => deleteArray(items, index + 1), 300);
                });
            }

            function extractTime($container) {
                const $timeTag = $container.find('time[datetime]');
                if ($timeTag.length) return $timeTag.attr('datetime');

                const $dataTime = $container.find('[data-time]');
                if ($dataTime.length) return $dataTime.attr('data-time');

                const $timeClass = $container.find('[class*="time"]');
                if ($timeClass.length) {
                    const text = $timeClass.first().text().trim();
                    if (text && /^\d{4}-\d{2}-\d{2}/.test(text)) return text;
                }

                const fullText = $container.text();
                const match = fullText.match(/(\d{4}-\d{2}-\d{2}[\sT]\d{2}:\d{2}(:\d{2})?)/);
                return match ? match[0] : null;
            }
        });
    }
    init();
})();
原文
存档评论1 条抓取于