无敌脚本批量删除私有笔记
因为测试软件的关系我上传过一些测试笔记,有一些是我上传的,有一些是脚本上传的。留着怕占用社长的服务器存储空间,准备删掉。于是写了一个无敌脚本:
// 删除一个item并确认
async function deleteOneItem() {
const noteOps = document.querySelectorAll([class*="note-operation"]);
if (noteOps.length === 0) {
console.log("没有items了");
return false;
}
const firstNoteOp = noteOps[0];
const parent = firstNoteOp.parentElement;
const grandParent = parent?.parentElement;
if (grandParent) {
const titleEl = grandParent.querySelector([class*="title"]);
const title = titleEl ? titleEl.textContent.trim() : "";
console.log("删除: " + title);
// 找索引1的按钮(真正的删除按钮)
const allButtons = firstNoteOp.querySelectorAll("button, div[class*=\"button\"]");
if (allButtons.length >= 2) {
const deleteBtn = allButtons[1]; // 索引1是删除按钮
console.log(" 点击删除按钮");
deleteBtn.click();
// 等待确认面板出现
await new Promise(resolve => setTimeout(resolve, 300));
// 找并点击确定按钮
const confirmBtn = document.querySelector(".button.button-primary.alert");
if (confirmBtn) {
console.log(" 点击确定");
confirmBtn.click();
await new Promise(resolve => setTimeout(resolve, 300));
return true;
}
}
}
return false;
}
// 连续删除直到目标
async function deleteAllBeforeTarget() {
const targetTitle = "黄宗义规律";
let deletedCount = 0;
while (true) {
const noteOps = document.querySelectorAll([class*="note-operation"]);
if (noteOps.length === 0) {
console.log("没有更多items了");
break;
}
const firstNoteOp = noteOps[0];
const parent = firstNoteOp.parentElement;
const grandParent = parent?.parentElement;
const titleEl = grandParent ? grandParent.querySelector([class*="title"]) : null;
const title = titleEl ? titleEl.textContent.trim() : "";
console.log("[" + (deletedCount + 1) + "] 检查: " + title);
// 检查是否到达目标
if (title === targetTitle) {
console.log("到达目标: " + title);
console.log("停止删除");
break;
}
// 删除这一项
const success = await deleteOneItem();
if (success) {
deletedCount++;
console.log("已删除 " + deletedCount + " 项");
} else {
console.log("删除失败");
break;
}
}
}
// 执行
window.deleteAllBeforeTarget();
使用方法很简单,打开 tab:
https://note.mowen.cn/my/notes?tab=private
在 console 面板粘入以上代码就可以了。
注意,一定要设置一个停止条件,例如我的是“黄宗义规律”,到这里就停止。你也要设置一条,防止都删除了。
写到这里想起一则旧笑话,一个程序员在网上找了一个教程,照着做,不小心执行 rm -rf 指令,然后电脑就坏了。他打开教程继续往下看,作者后面才写:以上操作是错误的,切莫尝试!
希望你看到了我写“黄宗义规律”。

#技术·求真·AI
📅 2026/01/20 周二 10:14
该文由 rustpress 编译。
评论