-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
94 lines (77 loc) · 2.58 KB
/
content.js
File metadata and controls
94 lines (77 loc) · 2.58 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
// content.js
function generatePrompt(brain) {
const persona = brain.persona;
const style = brain.style_preferences;
const memory = brain.memory_snippets.map(m => `- ${m.title}: ${m.summary}`).join('\n');
const goals = brain.goals.join(', ');
const tips = brain.chat_context_hints.join(' ');
return `You are talking to ${persona.name}, a ${persona.role}. Tone: ${persona.tone}. He prefers ${style.response_format} responses, typically ${style.response_length} in length. He values clarity, bullet points, and analogies.
His goals include: ${goals}.
Background: ${persona.background}.
Topics of interest: ${persona.interests.join(', ')}.
Previous work:
${memory}
Guidance: ${tips}`;
}
function waitForElement(selector, timeout = 10000) {
return new Promise((resolve, reject) => {
const start = Date.now();
const interval = setInterval(() => {
const el = document.querySelector(selector);
if (el) {
clearInterval(interval);
resolve(el);
} else if (Date.now() - start > timeout) {
clearInterval(interval);
reject(new Error("Timeout: Element not found"));
}
}, 300);
});
}
function loadBrain() {
return new Promise(resolve => {
chrome.storage.local.get(["userBrain"], (result) => {
if (result.userBrain) {
resolve(result.userBrain);
} else {
fetch(chrome.runtime.getURL("user-brain.json"))
.then(resp => resp.json())
.then(resolve);
}
});
});
}
function injectPersonaIntoClaude() {
chrome.storage.local.get('userBrain', (data) => {
const brain = data.userBrain;
if (!brain) {
console.warn("⚠️ No user persona found in storage.");
return;
}
const promptBox = document.querySelector('div.ProseMirror[contenteditable="true"]');
if (!promptBox) {
console.error("❌ Could not find Claude's prompt box.");
return;
}
const prompt = `Here is my user persona to help you respond better. Store this context for this session:\n\n` +
"```json\n" +
JSON.stringify(brain, null, 2) +
"\n```";
promptBox.focus();
// Simulate paste
const pasteEvent = new ClipboardEvent('paste', {
clipboardData: new DataTransfer(),
bubbles: true,
cancelable: true
});
pasteEvent.clipboardData.setData('text/plain', prompt);
promptBox.dispatchEvent(pasteEvent);
console.log("✅ Injected persona into Claude.");
});
}
// Start after delay to give page time to settle
setTimeout(() => {
if (window.location.hostname.includes("claude.ai")) {
injectPromptToClaude();
}
}, 2000);