this repo has been put into chatkit, you can find more about it in chat-play/packages/chatkit/bingchat.
getSubmitButton, getTextarea, getRegenerateButton, getNewChatButton...
just copy and paste the code below
function getActionBar() {
return document.querySelector("cib-serp")?.shadowRoot?.querySelector("cib-action-bar")?.shadowRoot;
};function getSubmitButton() {
const actionBar = getActionBar();
if (!actionBar) { return null; }
return actionBar.querySelector('button[aria-label="Submit"]');
};function getTextarea() {
const actionBar = getActionBar();
if (!actionBar) { return null; }
return actionBar.querySelector('textarea');
};function getStopGeneratingButton() {
const actionBar = getActionBar();
if (!actionBar) { return null; }
const stopGeneratingButton = actionBar.querySelector('cib-typing-indicator')?.shadowRoot?.querySelector('button[aria-label="Stop Responding"]');
if (!stopGeneratingButton) { return null; }
if (stopGeneratingButton.disabled) { return null; }
return stopGeneratingButton;
};function getNewChatButton() {
const actionBar = getActionBar();
if (!actionBar) { return null; }
return actionBar.querySelector('button[aria-label="New topic"]');
};function getConversation() {
return document.querySelector("cib-serp")?.shadowRoot?.querySelector("cib-conversation")?.shadowRoot;
};function getChatTurns() {
const conversation = getConversation();
if (!conversation) { return null; }
return Array.from(conversation.querySelectorAll('cib-chat-turn')).map(t => t.shadowRoot);
};function getLastChatTurn() {
const chatTurns = getChatTurns();
if (!chatTurns) { return null; }
return chatTurns[chatTurns.length - 1];
};function getLastResponse() {
const lastChatTurn = getLastChatTurn();
if (!lastChatTurn) { return null; }
return lastChatTurn.querySelectorAll('cib-message-group')[1]?.shadowRoot;
};function getLastResponseText() {
const lastResponse = getLastResponse();
if (!lastResponse) { return null; }
return Array.from( lastResponse.querySelectorAll('cib-message') )
.map(m => m.shadowRoot)
.find(m => m.querySelector('cib-shared'))
.textContent.trim();
};function send(text) {
const textarea = getTextarea();
if (!textarea) { return null; }
textarea.value = text;
textarea.dispatchEvent(new Event('input'));
const submitButton = getSubmitButton();
if (!submitButton) { return null; }
submitButton.click();
};Contributions, issues and feature requests are welcome!
This project is licensed under the terms of the MIT license.