Skip to content

Commit f6c241f

Browse files
committed
Support the 'Temporary' chat option in ChatGPT, replacing 'Reason' and 'Search'
1 parent 21fa0d5 commit f6c241f

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

  • packages

packages/browser/src/content-scripts/send-prompt-content-script/chatbots/chatgpt.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { Message } from '@/types/messages'
1111

1212
export const chatgpt: Chatbot = {
1313
wait_until_ready: async () => {
14+
const max_wait_time = 2000
15+
const start_time = Date.now()
16+
1417
await new Promise((resolve) => {
1518
const check_for_element = () => {
1619
if (
@@ -19,6 +22,8 @@ export const chatgpt: Chatbot = {
1922
)
2023
) {
2124
resolve(null)
25+
} else if (Date.now() - start_time >= max_wait_time) {
26+
resolve(null)
2227
} else {
2328
setTimeout(check_for_element, 100)
2429
}
@@ -29,16 +34,27 @@ export const chatgpt: Chatbot = {
2934
set_options: async (options: string[]) => {
3035
const supported_options = CHATBOTS['ChatGPT'].supported_options
3136
for (const option of options) {
32-
if (option == 'reason' && supported_options['reason']) {
33-
const reason_button = document.querySelector(
34-
'button[data-testid="composer-button-reason"]'
35-
) as HTMLButtonElement
36-
reason_button.click()
37-
} else if (option == 'search' && supported_options['search']) {
38-
const search_button = document.querySelector(
39-
'button[data-testid="composer-button-search"]'
40-
) as HTMLButtonElement
41-
search_button.click()
37+
if (option == 'temporary' && supported_options['temporary']) {
38+
const buttons = document.querySelectorAll('button')
39+
for (const item of Array.from(buttons)) {
40+
const path_element = item.querySelector(
41+
'path[d="M6.319 1.334a.667.667 0 0 1-.512.792 5.43 5.43 0 0 0-2.602 1.362.667.667 0 1 1-.918-.967A6.76 6.76 0 0 1 5.527.822a.667.667 0 0 1 .792.512m1.363 0a.667.667 0 0 1 .791-.512 6.76 6.76 0 0 1 3.24 1.699.667.667 0 1 1-.917.967 5.43 5.43 0 0 0-2.602-1.362.667.667 0 0 1-.512-.792M1.51 4.614c.348.12.533.5.413.848a4.7 4.7 0 0 0 0 3.076.667.667 0 0 1-1.26.435 6.04 6.04 0 0 1 0-3.945.666.666 0 0 1 .847-.413m10.979 0a.667.667 0 0 1 .847.414A6 6 0 0 1 13.667 7a6 6 0 0 1-.33 1.973.667.667 0 1 1-1.26-.435 4.7 4.7 0 0 0 0-3.076.667.667 0 0 1 .413-.847M2.27 10.352a.667.667 0 0 1 .479.812q-.052.2-.111.397.629-.097 1.228-.267a.67.67 0 0 1 .496.054c.445.238.93.417 1.445.528a.667.667 0 1 1-.28 1.303 7 7 0 0 1-1.553-.533c-.73.189-1.479.305-2.266.354a.667.667 0 0 1-.664-.905c.164-.425.305-.844.414-1.264a.667.667 0 0 1 .812-.48m9.468.186a.666.666 0 0 1-.024.942 6.76 6.76 0 0 1-3.24 1.7.667.667 0 0 1-.28-1.304 5.43 5.43 0 0 0 2.601-1.362.667.667 0 0 1 .943.024"]'
42+
)
43+
if (path_element) {
44+
;(item as HTMLElement).click()
45+
break
46+
}
47+
}
48+
await new Promise((resolve) => {
49+
const check_for_param = () => {
50+
if (window.location.search.includes('temporary-chat=true')) {
51+
resolve(null)
52+
} else {
53+
setTimeout(check_for_param, 100)
54+
}
55+
}
56+
check_for_param()
57+
})
4258
}
4359
}
4460
},
@@ -58,7 +74,10 @@ export const chatgpt: Chatbot = {
5874
let has_eligible_block = false
5975
for (const code_block of Array.from(code_blocks)) {
6076
const first_line_text = code_block?.textContent?.split('\n')[0]
61-
if (first_line_text && extract_path_from_line_of_code(first_line_text)) {
77+
if (
78+
first_line_text &&
79+
extract_path_from_line_of_code(first_line_text)
80+
) {
6281
has_eligible_block = true
6382
break
6483
}

packages/shared/src/constants/chatbots.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ export const CHATBOTS = {
7777
default_system_instructions: "You're a helpful coding assistant.",
7878
supported_options: {},
7979
default_top_p: 1,
80-
models: {
81-
// Populated dynamically
82-
}
80+
models: {}
8381
},
8482
ChatGPT: {
8583
url: 'https://chatgpt.com/',
@@ -90,8 +88,7 @@ export const CHATBOTS = {
9088
supports_user_provided_port: false,
9189
default_system_instructions: '',
9290
supported_options: {
93-
reason: 'Reason',
94-
search: 'Search'
91+
temporary: 'Temporary'
9592
},
9693
default_top_p: 0,
9794
models: {}

0 commit comments

Comments
 (0)