-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcleanup-all.ts
More file actions
40 lines (35 loc) · 1.1 KB
/
cleanup-all.ts
File metadata and controls
40 lines (35 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { connectToSuperhuman, disconnect } from "./src/superhuman-api";
async function cleanupAllDrafts() {
const conn = await connectToSuperhuman(9333, true);
if (!conn) return;
const result = await conn.Runtime.evaluate({
expression: `
(async () => {
try {
const cfc = window.ViewState?._composeFormController;
if (!cfc) return { count: 0 };
const keys = Object.keys(cfc).filter(k => k.startsWith('draft'));
let count = 0;
for (const key of keys) {
const ctrl = cfc[key];
if (typeof ctrl.discard === 'function') {
await ctrl.discard();
count++;
} else if (typeof ctrl._discardDraftAsync === 'function') {
await ctrl._discardDraftAsync();
count++;
}
}
return { count };
} catch (e) {
return { error: e.message };
}
})()
`,
returnByValue: true,
awaitPromise: true
});
console.log(JSON.stringify(result.result.value, null, 2));
await disconnect(conn);
}
cleanupAllDrafts();