-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexplore-snippets.ts
More file actions
109 lines (95 loc) · 3.46 KB
/
explore-snippets.ts
File metadata and controls
109 lines (95 loc) · 3.46 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { connectToSuperhuman, disconnect, openCompose, closeCompose } from "./src/superhuman-api";
async function main() {
const conn = await connectToSuperhuman(9333);
if (!conn) { console.log("No connection"); process.exit(1); }
// First, open a compose window
const draftKey = await openCompose(conn);
console.log("Opened compose:", draftKey);
await new Promise(r => setTimeout(r, 500));
// Now simulate ";" to open snippet autocomplete in compose
await conn.Input.dispatchKeyEvent({ type: "keyDown", key: ";", code: "Semicolon", text: ";" });
await conn.Input.dispatchKeyEvent({ type: "keyUp", key: ";", code: "Semicolon" });
// Wait for autocomplete/snippets to load
await new Promise(r => setTimeout(r, 1000));
const result = await conn.Runtime.evaluate({
expression: `
(() => {
const vs = window.ViewState;
const cfc = vs?._composeFormController;
const draftKey = Object.keys(cfc || {})[0];
const ctrl = cfc?.[draftKey];
const account = ctrl?.props?.account;
const threads = account?.threads;
const onDisk = threads?.onDisk;
// Check user object in onDisk
const user = onDisk?.user;
const userKeys = user ? Object.keys(user) : [];
const userSnippetKeys = userKeys.filter(k =>
k.toLowerCase().includes("snippet") ||
k.toLowerCase().includes("phrase") ||
k.toLowerCase().includes("template")
);
// Check if snippets is a property on user
let userSnippets = null;
if (user?.snippets) {
userSnippets = {
type: typeof user.snippets,
isArray: Array.isArray(user.snippets),
count: user.snippets.length || Object.keys(user.snippets).length || "unknown"
};
}
// Try portal.invoke for snippet services
const ga = window.GoogleAccount;
let portalSnippetResult = null;
const servicesToTry = [
["snippets", "list"],
["snippet", "list"],
["snippetInternal", "list"],
["snippetInternal", "listAsync"],
["draftInternal", "listSnippets"],
["userInternal", "getSnippets"]
];
for (const [service, method] of servicesToTry) {
try {
const result = await ga.portal.invoke(service, method, []);
if (result) {
portalSnippetResult = {
service,
method,
resultType: typeof result,
isArray: Array.isArray(result),
sample: JSON.stringify(result).slice(0, 500)
};
break;
}
} catch (e) {
// continue
}
}
// Check for snippets in localStorage or indexedDB
let localStorageSnippets = null;
for (const key of Object.keys(localStorage)) {
if (key.toLowerCase().includes("snippet")) {
localStorageSnippets = { key, preview: localStorage.getItem(key)?.slice(0, 200) };
break;
}
}
return {
userKeys: userKeys.slice(0, 50),
userSnippetKeys,
userSnippets,
portalSnippetResult,
localStorageSnippets
};
})()
`,
returnByValue: true,
});
console.log(JSON.stringify(result.result.value, null, 2));
// Close the compose window
if (draftKey) {
await closeCompose(conn, draftKey);
}
await disconnect(conn);
}
main().catch(console.error);