-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
110 lines (88 loc) · 2.69 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const $ = selector => document.querySelector(selector)
const $$ = selector => document.querySelectorAll(selector)
class Gemini {
newChat() {
const newChatBtn = $('[aria-label="New chat"] > button')
newChatBtn?.click()
}
toggleSidebar() {
const sideBarBtn = $('button[aria-label="Main menu"]')
sideBarBtn.click()
}
focusOnChatInput() {
const chatInput = $('[role="textbox"]')
chatInput.focus()
}
copyLastResponse() {
const moreBtns = $$('button[aria-label="Show more options"]')
const latestMoreBtn = moreBtns[moreBtns.length - 1]
latestMoreBtn?.click()
const copyBtn = $('button[aria-label="Copy"]')
if (latestMoreBtn) copyBtn?.click()
latestMoreBtn.blur()
}
copyLastCode() {
const copyBtns = $$('button[aria-label="Copy code"]')
const latestCopyBtn = copyBtns[copyBtns.length - 1]
latestCopyBtn?.click() // NOTE must scroll until the end of the answer to work
}
}
class BingCopilot {
newChat() {
const newChatBtn = $('.cib-serp-main')
.shadowRoot.querySelector('#cib-action-bar-main')
.shadowRoot.querySelector('button')
newChatBtn?.click()
}
toggleSidebar() {
const sideBarBtn = $('a[aria-label="Settings and quick links"]')
sideBarBtn.click()
}
focusOnChatInput() {
const chatInput = $('.cib-serp-main')
.shadowRoot.querySelector('#cib-action-bar-main')
.shadowRoot.querySelector('cib-text-input')
.shadowRoot.querySelector('textarea')
chatInput.focus()
}
copyLastResponse() {
const chats = $('.cib-serp-main')
.shadowRoot.querySelector('#cib-conversation-main')
.shadowRoot.querySelectorAll('cib-chat-turn')
const lastChats = chats[chats.length - 1]
const messageGroups = lastChats
const lastMessageGroup = messageGroups[messageGroups.length - 1]
// const copyBtn = lastMessageGroup?.shadowRoot
// .querySelector('cib-message')
// .shadowRoot.querySelector('cib-message-actions')
// .shadowRoot.querySelector('button#copy-button')
// console.log(copyBtn)
// copyBtn?.click()
}
copyLastCode() {}
}
const AI = window.location.href.includes('google.com')
? new Gemini()
: new BingCopilot()
document.addEventListener('keydown', function (e) {
if (e.ctrlKey && e.key === 'k') {
e.preventDefault()
AI.newChat()
}
if (e.ctrlKey && e.shiftKey && e.key === 'S') {
e.preventDefault()
AI.toggleSidebar()
}
if (e.shiftKey && e.key === 'Escape') {
e.preventDefault()
AI.focusOnChatInput()
}
if (e.ctrlKey && e.shiftKey && e.key === 'C') {
e.preventDefault()
AI.copyLastResponse()
}
if (e.ctrlKey && e.shiftKey && e.key === ':') {
e.preventDefault()
AI.copyLastCode()
}
})