Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ chrome.action.onClicked.addListener(async () => {
});

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request?.target && request.target !== "background") return false;
if (request.action === "download_conversation_history_deepseek") {
getConversationHistoryFromDeepseek(request.token)
.then(async (res) => {
Expand Down
3 changes: 2 additions & 1 deletion src/content/chatgpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ console.log("Zebra Content Script loaded for ChatGPT.");

// Example: Send a message to the background script
chrome.runtime.sendMessage(
{ greeting: "hello from chatgpt content script" },
{ target: "background",
greeting: "hello from chatgpt content script" },
(response) => {
if (chrome.runtime.lastError) {
console.error(
Expand Down
17 changes: 11 additions & 6 deletions src/content/claude.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
console.log("Zebra Content Script loaded for Claude.ai.");

// Example: Send a message to the background script
chrome.runtime.sendMessage({ greeting: "hello from claude content script" }, (response) => {
if (chrome.runtime.lastError) {
console.error("Error sending message from claude.ts:", chrome.runtime.lastError.message);
} else {
console.log("Response from background:", response);
// Example: Send a message to the background script
chrome.runtime.sendMessage(
{ target: "background",
greeting: "hello from claude content script" },
(response) => {
if (chrome.runtime.lastError) {
console.error("Error sending message from claude.ts:", chrome.runtime.lastError.message);
} else {
console.log("Response from background:", response);
}
}
});
);

// TODO: Add logic to interact with Claude.ai's DOM
// e.g., identify conversation elements, cache them, etc.
3 changes: 2 additions & 1 deletion src/content/deepseek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ console.log("Zebra Content Script loaded for DeepSeek.");

// Example: Send a message to the background script
chrome.runtime.sendMessage(
{ greeting: "hello from deepseek content script" },
{ target: "background",
greeting: "hello from deepseek content script" },
(response) => {
if (chrome.runtime.lastError) {
console.error(
Expand Down
6 changes: 5 additions & 1 deletion src/lib/state/conversations.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ LIMIT ? OFFSET ?
return new Promise<void>((resolve, reject) => {
chrome.runtime.sendMessage(
{
target: "offscreen",
type: "EXECUTE_QUERY",
sql: sql,
params: params,
Expand Down Expand Up @@ -209,6 +210,7 @@ LIMIT ? OFFSET ?
return new Promise<void>((resolve, reject) => {
chrome.runtime.sendMessage(
{
target: "offscreen",
type: "EXECUTE_QUERY",
sql: sql,
params: params,
Expand Down Expand Up @@ -259,6 +261,7 @@ export async function setConversationsResult(
return new Promise<void>((resolve, reject) => {
chrome.runtime.sendMessage(
{
target: "offscreen",
type: "EXECUTE_QUERY",
sql: `
SELECT c.id, c.source, c.title, c.created_at, c.updated_at, c.url,
Expand Down Expand Up @@ -320,6 +323,7 @@ export async function loadConversationsFromBackground() {
return new Promise<void>((resolve, reject) => {
chrome.runtime.sendMessage(
{
target: "offscreen",
type: "GET_CONVERSATIONS",
payload: {
limit: 50,
Expand Down Expand Up @@ -388,7 +392,7 @@ export async function addNewConversationsAndRefresh(
) {
return new Promise<void>((resolve, reject) =>
chrome.runtime.sendMessage(
{ type: "SAVE_CONVERSATIONS", conversations: newConversationData },
{ target: "offscreen", type: "SAVE_CONVERSATIONS", conversations: newConversationData },
(response) => {
if (response && response.success) {
console.log(
Expand Down
10 changes: 4 additions & 6 deletions src/offscreen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ async function initializeDatabase() {
initializeDatabase();

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
// Accept only messages explicitly addressed to the off-screen document
if (request?.target !== "offscreen") return false;
console.log("Offscreen: Message received", request);

if (!sqliteDb) {
Expand Down Expand Up @@ -110,6 +112,8 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
return { result };
},
};
if (request?.target && request.target !== "offscreen") return false;

if (request && request.type && operations[request.type]) {
operations[request.type](request)
.then((result) => {
Expand All @@ -119,12 +123,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.error(`Offscreen: Error processing ${request.type}:`, error);
sendResponse({ success: false, error: error.message });
});
} else {
console.warn("Offscreen: Unknown operation or malformed request", request);
sendResponse({
success: false,
error: "Offscreen: Unknown or malformed operation",
});
}

return true; // Indicate that the response will be sent asynchronously
Expand Down
2 changes: 2 additions & 0 deletions src/options/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

chrome.runtime.sendMessage(
{
target: "offscreen",
type: "GET_CONVERSATIONS",
payload: {
limit: 50,
Expand All @@ -43,6 +44,7 @@
// TODO: Trigger search with the query
chrome.runtime.sendMessage(
{
target: "offscreen",
type: "EXECUTE_QUERY",
sql: "SELECT * FROM conversations WHERE source LIKE ?",
params: [`%${searchQuery}%`],
Expand Down
74 changes: 45 additions & 29 deletions src/popup/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@

onMount(async () => {
console.log("Zebra Popup App Mounted.");
try {
const response = await chrome.runtime.sendMessage({
greeting: "hello from popup",
});
console.log("Response from background in popup:", response);
if (response && response.farewell) {
messageFromBackground = response.farewell;
} else {
messageFromBackground =
"No response or unexpected response format.";
}
} catch (error) {
console.error("Error sending message from popup:", error);
messageFromBackground = `Error: ${error.message}`;
if (chrome.runtime.lastError) {
console.error(
"Chrome runtime error:",
chrome.runtime.lastError.message,
);
messageFromBackground += ` | Chrome Error: ${chrome.runtime.lastError.message}`;
}
}
// try {
// const response = await chrome.runtime.sendMessage({
// target: "background",
// greeting: "hello from popup",
// });
// console.log("Response from background in popup:", response);
// if (response && response.farewell) {
// messageFromBackground = response.farewell;
// } else {
// messageFromBackground =
// "No response or unexpected response format.";
// }
// } catch (error) {
// console.error("Error sending message from popup:", error);
// messageFromBackground = `Error: ${error.message}`;
// if (chrome.runtime.lastError) {
// console.error(
// "Chrome runtime error:",
// chrome.runtime.lastError.message,
// );
// messageFromBackground += ` | Chrome Error: ${chrome.runtime.lastError.message}`;
// }
// }
});

function openOptionsPage(query = "") {
Expand Down Expand Up @@ -115,6 +116,8 @@
responseFromContentScript.token !== undefined
) {
const userToken = responseFromContentScript.token;
messageFromBackground =
"Synching conversations from Deepseek";
chrome.runtime.sendMessage(
{
action: "download_conversation_history_deepseek",
Expand All @@ -123,20 +126,27 @@
(responseFromBackground) => {
if (
responseFromBackground &&
responseFromBackground.success
responseFromBackground.status ===
"success"
) {
messageFromBackground =
"Deepseek Conversations downloaded successfully";
console.log(
"DeepseekConversation downloaded successfully",
"Deepseek Conversations downloaded successfully",
);
} else {
messageFromBackground =
"Could not download Deepseek Conversations";
console.error(
"Failed to download Deepseek conversation:",
"Failed to download Deepseek Conversations:",
responseFromBackground?.error,
);
}
},
);
} else {
messageFromBackground =
"Could not retrieve deepseek token";
console.error(
"Could not retrieve token from active tab's localStorage. Response:",
responseFromContentScript,
Expand All @@ -145,22 +155,28 @@
} else if (
activeTab.url.startsWith("https://chatgpt.com/")
) {
messageFromBackground =
"Synching conversations from ChatGPT";
chrome.runtime.sendMessage(
{
target: "background",
action: "download_conversation_history",
},
(responseFromBackground) => {
if (
responseFromBackground &&
responseFromBackground.success
responseFromBackground.status === "success"
) {
messageFromBackground =
"ChatGPT conversations downloaded successfully";
console.log(
"ChatGPTConversation downloaded successfully",
"ChatGPT conversations downloaded successfully",
);
} else {
messageFromBackground = `Failed to download ChatGPT conversations`;
console.error(
"Failed to download ChatGPT conversation:",
responseFromBackground?.error,
"Failed to download ChatGPT conversations:",
responseFromBackground,
);
}
},
Expand Down