Skip to content

Commit 732cea8

Browse files
committed
Update Copilot chatbot readiness check and reasoning effort selection
- wait until ready should do this instead: [Image] - in `apps/browser/src/content-scripts/send-prompt-content-script/chatbots/copilot.ts`, changing reasoning effort no longer works. the popup: [Pasted text] - [Fragment] appear after a while, should pool for it in 100ms interval
1 parent 1ca955b commit 732cea8

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

  • apps/browser/src/content-scripts/send-prompt-content-script/chatbots

‎apps/browser/src/content-scripts/send-prompt-content-script/chatbots/copilot.ts‎

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ export const copilot: Chatbot = {
1010
wait_until_ready: async () => {
1111
await new Promise((resolve) => {
1212
const check_for_element = () => {
13-
if (
14-
document.getElementById('gptModeSwitcher') &&
15-
document.getElementById('m365-chat-editor-target-element')
16-
) {
13+
if (document.querySelector('#greeting')?.textContent) {
1714
resolve(null)
1815
} else {
1916
setTimeout(check_for_element, 100)
@@ -75,7 +72,17 @@ export const copilot: Chatbot = {
7572
return
7673
}
7774

78-
const menu_items = Array.from(popover.querySelectorAll('[role="menuitem"]'))
75+
const menu_items = await new Promise<Element[]>((resolve) => {
76+
const check_for_items = () => {
77+
const items = Array.from(popover.querySelectorAll('[role="menuitem"]'))
78+
if (items.length > 0) {
79+
resolve(items)
80+
} else {
81+
setTimeout(check_for_items, 100)
82+
}
83+
}
84+
check_for_items()
85+
})
7986

8087
let target_text = ''
8188
if (reasoning_effort.toLowerCase() == 'auto') {
@@ -88,16 +95,18 @@ export const copilot: Chatbot = {
8895

8996
const target_item = menu_items.find((item) => {
9097
const title = item.querySelector('h4')?.textContent?.trim().toLowerCase()
91-
return title == target_text
98+
if (title == target_text) return true
99+
100+
const primary_text = item
101+
.querySelector('.fai-CapabilityPickerMenuItem__primaryContentWrapper')
102+
?.textContent?.trim()
103+
.toLowerCase()
104+
if (primary_text == target_text) return true
105+
106+
return false
92107
}) as HTMLElement
93108

94-
if (target_item) {
95-
target_item.click()
96-
} else {
97-
document.dispatchEvent(
98-
new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })
99-
)
100-
}
109+
target_item.click()
101110

102111
await new Promise((resolve) => requestAnimationFrame(resolve))
103112
},

0 commit comments

Comments
 (0)