https://github.com/mefengl/bard-utils
getSubmitButton, getTextarea, getRegenerateButton, getNewChatButton...
https://github.com/mefengl/bard-utils
Last synced: 3 months ago
JSON representation
getSubmitButton, getTextarea, getRegenerateButton, getNewChatButton...
- Host: GitHub
- URL: https://github.com/mefengl/bard-utils
- Owner: mefengl
- License: mit
- Created: 2023-03-27T04:58:53.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-06T16:37:33.000Z (over 2 years ago)
- Last Synced: 2025-02-10T06:32:53.322Z (5 months ago)
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bard Utils
[](https://github.com/mefengl/made-by-ai)
[](https://github.com/mefengl/made-by-ai)
[](https://github.com/mefengl/made-by-ai)## Notice
this repo has been put into `chatkit`, you can find more about it in [chat-play/packages/chatkit/bard](https://github.com/mefengl/chat-play).
## Description
getSubmitButton, getTextarea, getRegenerateButton, getNewChatButton...
## Usage
just copy and paste the code below
```js
function getInputArea() {
return document.querySelector(".input-area");
};
``````js
function getSubmitButton() {
return document.querySelector('button[aria-label="Send message"]');
};
``````js
function getTextarea() {
const inputArea = getInputArea();
return inputArea.querySelector('textarea');
};
``````js
function getRegenerateButton() {
return document.querySelector('button[aria-label="Retry"]');
};
``````js
function getNewChatButton() {
const navButtons = document.querySelector('mat-nav-list').children;
return Array.from(navButtons).find(b => b.textContent.trim().toLowerCase().includes('reset chat'));
};
``````js
function getLastResponse() {
const responseElements = document.querySelectorAll('.model-response-text');
const lastResponse = responseElements[responseElements.length - 1];
return lastResponse;
};
``````js
function getLastResponseText() {
const lastPrompt = this.getLastPrompt();
if (!lastPrompt) return "";
const lastPromptText = lastPrompt.textContent;
return lastPromptText;
};
``````js
function getLastPrompt() {
const promptElements = document.querySelectorAll('.query-text');
const lastPrompt = promptElements[promptElements.length - 1];
return lastPrompt;
};
``````js
function getLastPromptText() {
const lastPrompt = getLastPrompt();
return lastPrompt.textContent;
};
``````js
function send(text) {
const textarea = getTextarea();
textarea.value = text;
textarea.dispatchEvent(new Event('input'));
getSubmitButton().click();
};
```## Contributing
Contributions, issues and feature requests are welcome!
## License
This project is licensed under the terms of the [MIT license](/LICENSE).