-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
19 changed files
with
13,589 additions
and
10,459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { PlasmoMessaging } from "@plasmohq/messaging"; | ||
import { callOpenAIReturn } from "~lib/openAITypeCall"; | ||
|
||
export type RequestBody = { | ||
prompt: string; | ||
selectedText: string; | ||
}; | ||
|
||
const handler: PlasmoMessaging.MessageHandler = async (request, response) => { | ||
const { prompt, selectedText } = request.body; | ||
|
||
const responseFromApi = await callOpenAIReturn(prompt, selectedText); | ||
response.send(responseFromApi); | ||
}; | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { PlasmoMessaging } from "@plasmohq/messaging"; | ||
|
||
export type RequestBody = { | ||
errorMessage: string; | ||
data: string; | ||
}; | ||
|
||
export type RequestResponse = string; | ||
|
||
export async function copyTextToClipboardHandler(req) { | ||
if (!req.errorMessage) { | ||
try { | ||
chrome.tabs.query( | ||
{ active: true, currentWindow: true }, | ||
function (tabs) { | ||
if (tabs[0]?.id) { | ||
chrome.tabs.sendMessage(tabs[0].id, { | ||
action: "copyToClipboard", | ||
text: req.data, | ||
}); | ||
} else { | ||
throw new Error("No active tab found."); | ||
} | ||
} | ||
); | ||
} catch (error) { | ||
console.error("Failed to copy text to clipboard:", error); | ||
} | ||
} else { | ||
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { | ||
if (tabs[0]?.id) { | ||
chrome.tabs.sendMessage(tabs[0].id, { | ||
action: "error", | ||
text: req.errorMessage, | ||
}); | ||
} else { | ||
throw new Error("No active tab found."); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
const handler: PlasmoMessaging.MessageHandler< | ||
RequestBody, | ||
RequestResponse | undefined | ||
> = async (req, res) => { | ||
copyTextToClipboardHandler(req.body); | ||
}; | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { PlasmoMessaging } from "@plasmohq/messaging"; | ||
import { Storage } from "@plasmohq/storage"; | ||
|
||
const storage = new Storage(); | ||
|
||
export async function openOptionsPageHandler() { | ||
await storage.set("activeTab", "promptFactory"); | ||
chrome.runtime.openOptionsPage(); | ||
return { | ||
message: "Options page opened", | ||
}; | ||
} | ||
|
||
const handler: PlasmoMessaging.MessageHandler = async (req, res) => { | ||
const result = await openOptionsPageHandler(); | ||
res.send(result); | ||
}; | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { PlasmoMessaging } from "@plasmohq/messaging"; | ||
|
||
const handler: PlasmoMessaging.MessageHandler = async (req, res) => { | ||
await chrome.sidePanel.open({ | ||
tabId: req.sender.tab.id ?? undefined, // Use nullish coalescing to handle undefined or null | ||
}); | ||
|
||
res.send("ok"); | ||
}; | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { PlasmoMessaging } from "@plasmohq/messaging"; | ||
|
||
export async function sendLoadingActionHandler() { | ||
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { | ||
if (tabs[0]?.id) { | ||
chrome.tabs.sendMessage(tabs[0].id, { | ||
action: "loadingAction", | ||
}); | ||
} else { | ||
throw new Error("No active tab found."); | ||
} | ||
}); | ||
return { | ||
message: "Options page opened", | ||
}; | ||
} | ||
|
||
const handler: PlasmoMessaging.MessageHandler = async (req, res) => { | ||
const result = await sendLoadingActionHandler(); | ||
res.send(result); | ||
}; | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { PlasmoMessaging } from "@plasmohq/messaging"; | ||
|
||
export type RequestBody = { | ||
data: string; | ||
}; | ||
|
||
const handler: PlasmoMessaging.MessageHandler = async (request, response) => { | ||
try { | ||
await chrome.runtime.sendMessage({ | ||
action: "send_to_sidepanel", | ||
payload: request.body.data, | ||
}); | ||
} catch (error) { | ||
response.send("Ok"); | ||
} | ||
response.send("Ok"); | ||
}; | ||
|
||
export default handler; |
Oops, something went wrong.