Skip to content

Commit

Permalink
Updated button selectors to use newly restored data-testid attrs ↞ …
Browse files Browse the repository at this point in the history
…[auto-sync from `KudoAI/chatgpt.js`]
  • Loading branch information
adamlui authored and kudo-sync-bot committed Sep 23, 2024
1 parent 3ecbe40 commit 0cbc240
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
26 changes: 6 additions & 20 deletions starters/chrome/extension/lib/chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,12 +888,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
getHeaderDiv() { return chatgpt.header.get(); },
getLastPrompt() { return chatgpt.getChatData('active', 'msg', 'user', 'latest'); },
getLastResponse() { return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'); },

getNewChatButton() {
return document.querySelector('button:has([d*="M15.6729"],' // pencil-on-pad icon
+ '[d^="M3.06957"])'); // refresh icon if temp chat
},

getNewChatButton() { return document.querySelector('button[data-testid*="new-chat-button"]'); },
getNewChatLink() { return document.querySelector('nav a[href="/"]'); },
getRegenerateButton() { return document.querySelector('button:has([d^="M3.06957"])'); },

Expand All @@ -909,13 +904,8 @@ const chatgpt = { // eslint-disable-line no-redeclare
getResponseFromAPI(chatToGet, responseToGet) { return chatgpt.response.getFromAPI(chatToGet, responseToGet); },
getResponseFromDOM(pos) { return chatgpt.response.getFromDOM(pos); },
getScrollToBottomButton() { return document.querySelector('button[class*="cursor"][class*="bottom"]'); },

getSendButton() {
return document.querySelector('[data-testid="send-button"]') // pre-GPT-4o
|| document.querySelector('path[d*="M15.192 8.906a1.143"]')?.parentNode.parentNode; // post-GPT-4o
},

getStopButton() { return document.querySelector('button:has([d*="2 0 0 1 2"], rect)'); },
getSendButton() { return document.querySelector('[data-testid="send-button"]'); },
getStopButton() { return document.querySelector('button[data-testid="stop-button"]'); },

getUserLanguage() {
return navigator.languages[0] || navigator.language || navigator.browserLanguage ||
Expand Down Expand Up @@ -1797,13 +1787,9 @@ const chatgpt = { // eslint-disable-line no-redeclare
},

toggle() {
const isMobileDevice = chatgpt.browser.isMobile(),
navBtnSelector = isMobileDevice ? 'button' : 'nav button',
isToggleBtn = isMobileDevice ? () => true // since 1st one is toggle
: btn => btn.querySelector('svg path[d^="M8.857"]');
for (const btn of document.querySelectorAll(navBtnSelector))
if (isToggleBtn(btn)) { btn.click(); return; }
console.error('Sidebar toggle not found!');
const sidebarToggle = document.querySelector('button[data-testid*="sidebar-button"]');
if (!sidebarToggle) console.error('Sidebar toggle not found!');
sidebarToggle.click();
},

async isLoaded(timeout = 5000) {
Expand Down
2 changes: 1 addition & 1 deletion starters/chrome/extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "ChatGPT Extension",
"description": "A Chrome template to start using chatgpt.js like a boss!",
"version": "2024.9.16",
"version": "2024.9.23",
"author": "chatgpt.js",
"icons": {
"16": "icons/icon16.png",
Expand Down

0 comments on commit 0cbc240

Please sign in to comment.