版本比较
删犇器
正文
增加 334 行删除 52 行
2 行未改动34567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011022 行未改动这个删犇器参考了常见的[这个版本](https://www.luogu.com.cn/problem/U562424),同样是 $300 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/U6843232 行未改动34567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833842 行未改动这个删犇器参考了常见的[这个版本](https://www.luogu.com.cn/problem/U562424),同样是 $300 ms$ 间隔,对于可能出现的 `403` 乃至封禁,作者概不负责。温馨提示:犇犇不可找回,删前请慎重考虑。::::::::info[$update$]$1.0版$:首个发布版,支持犇犇全部删除$2.1版$:优化了 UI,支持时间筛选 ~~DeepSeek 真的太好用了你们知道吗~~::::::::info[源代码]::::info[$2.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();})();```::::