Skip to content

Commit a3d74d1

Browse files
Enhance CLI and agent functionality by adding source map support, updating target URLs, changing default model, and improving module exports. Refactor action command handling and agent initialization for better options management.
1 parent 957847c commit a3d74d1

31 files changed

+1144
-318
lines changed

extensions/chrome/js/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function handleServerMessage(message) {
6868
// If the 'useOpenAI' flag is true in the message
6969
if (message.useOpenAI) {
7070
// Search for the first tab with the URL 'chat.openai.com'
71-
chrome.tabs.query({ url: "*://chat.openai.com/*" }, function (tabs) {
71+
chrome.tabs.query({ url: "*://chatgpt.com/*" }, function (tabs) {
7272
let targetTab = tabs[0]; // Assuming you want to use the first tab that matches
7373
if (targetTab && targetTab.id) {
7474
// After injecting the openai_content.js into the target tab
@@ -86,7 +86,7 @@ function handleServerMessage(message) {
8686
return;
8787
}
8888
console.log("Executed openai_content.js on:", targetTab.url);
89-
89+
console.log(message)
9090
// Send a message to the tab to set the user's input and click send
9191
chrome.tabs.sendMessage(
9292
targetTab.id,

extensions/chrome/js/island.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function() {
2-
const targetUrl = 'https://chat.openai.com/backend-api/conversation';
2+
const targetUrl = 'https://chatgpt.com/backend-api/conversation';
33
const originalFetch = window.fetch;
44

55
function handleStream(reader, requestUrl) {

extensions/chrome/js/openai_content.js

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,73 @@
11
// Combined content script
2-
32
if (!window.hasOpenAIScriptInjected) {
43
window.hasOpenAIScriptInjected = true;
54

6-
// Function to set the user's input in the textarea and click the send button
5+
// Function to set the user's input in the textarea and trigger the Enter key
76
function setAndSend(userInput) {
8-
const textarea = document.getElementById("prompt-textarea");
9-
textarea.value = userInput;
10-
// Dispatch an input event to simulate user typing
11-
const event = new Event("input", {
12-
bubbles: true,
13-
cancelable: true,
14-
});
15-
textarea.dispatchEvent(event);
7+
const textarea = document.getElementById("prompt-textarea");
8+
if (!textarea) {
9+
console.error("Textarea element not found");
10+
return;
11+
}
12+
13+
// Set the content of the contenteditable element
14+
textarea.textContent = userInput;
15+
16+
// Dispatch an input event to simulate typing
17+
const inputEvent = new Event("input", { bubbles: true, cancelable: true });
18+
textarea.dispatchEvent(inputEvent);
1619

17-
// Simulate a click on the send button
18-
document.querySelector('[data-testid="send-button"]').click();
20+
// Simulate Enter key press
21+
const enterKeyEvent = new KeyboardEvent("keydown", {
22+
key: "Enter",
23+
code: "Enter",
24+
bubbles: true,
25+
cancelable: true,
26+
});
27+
textarea.dispatchEvent(enterKeyEvent);
1928
}
2029

30+
// Function to process received SSE data
2131
function processReceivedData(data) {
22-
// Process the received SSE data
23-
console.log("Processed data:", data);
24-
chrome.runtime.sendMessage({
25-
action: "receivedResponse",
26-
responseText: data,
27-
});
32+
console.log("Processed data:", data);
33+
chrome.runtime.sendMessage({
34+
action: "receivedResponse",
35+
responseText: data,
36+
});
2837
}
2938

3039
// Function to create and inject the script
3140
async function injectScript() {
32-
const script = document.createElement("script");
33-
script.src = chrome.runtime.getURL('js/island.js');
34-
document.documentElement.appendChild(script);
35-
script.remove();
41+
const script = document.createElement("script");
42+
script.src = chrome.runtime.getURL('js/island.js');
43+
document.documentElement.appendChild(script);
44+
script.remove();
3645
}
3746

3847
// Content script listener for messages from the injected script
3948
window.addEventListener("message", (event) => {
40-
if(typeof event.data == 'string') {
41-
event.data = JSON.parse(event.data);
42-
}
43-
if (event.data && event.data.type === "FROM_PAGE_STREAM") {
44-
console.log("Content script received stream message :", event.data);
45-
chrome.runtime.sendMessage(event.data, response => {
46-
if (chrome.runtime.lastError) {
47-
console.error(chrome.runtime.lastError.message);
48-
} else {
49-
console.log("Content script received response:", response)
50-
}
51-
});
52-
}
49+
if (typeof event.data === "string") {
50+
event.data = JSON.parse(event.data);
51+
}
52+
if (event.data && event.data.type === "FROM_PAGE_STREAM") {
53+
console.log("Content script received stream message:", event.data);
54+
chrome.runtime.sendMessage(event.data, (response) => {
55+
if (chrome.runtime.lastError) {
56+
console.error(chrome.runtime.lastError.message);
57+
} else {
58+
console.log("Content script received response:", response);
59+
}
60+
});
61+
}
5362
});
5463

55-
// Listen for messages from the background script
64+
// Listener for messages from the background script
5665
chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
57-
if (request.action === "setAndSend") {
58-
setAndSend(request.userInput);
59-
await injectScript();
60-
sendResponse({ status: "Script injected" });
61-
}
66+
if (request.action === "setAndSend") {
67+
setAndSend(request.userInput); // Update the text and simulate Enter key press
68+
await injectScript();
69+
sendResponse({ status: "Script injected" });
70+
}
6271
});
6372

6473
console.log("openai content script loaded");

extensions/chrome/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
],
2626
"content_scripts": [
2727
{
28-
"matches": ["*://*.openai.com/*"],
28+
"matches": ["*://*.openai.com/*", "*://chatgpt.com/*"],
2929
"js": ["js/openai_content.js"],
3030
"run_at": "document_end"
3131
},
3232
{
33-
"matches": ["*://chat.openai.com/*"],
33+
"matches": ["*://chat.openai.com/*", "*://chatgpt.com/*"],
3434
"js": ["js/inject.js"],
3535
"run_at": "document_end"
3636
}

0 commit comments

Comments
 (0)