Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow copy of user input text #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
https://sethusenthil.com
`)

const USER_TEXT_SELECTOR = '.items-start';
const CHAT_TEXT_SELECTOR = '.markdown';
const CLIPBOARD_CLASS_NAME = 'copy-to-clipboard';

Expand Down Expand Up @@ -81,10 +82,19 @@
//console.log('chatbox', chatbox);
//first chat box needs to be from user, hence all the even chat bubbles are from bot
//plus users will have the first row as model selection
let text_selector;
if ((i > 0 && (i % 2 === 0) && plusUser) ||
((i + 1) % 2 === 0 && !plusUser)) {
text_selector = CHAT_TEXT_SELECTOR;
} else if ((i > 0 && (i % 2 === 1) && plusUser) ||
((i + 1) % 2 === 1 && !plusUser)) {
text_selector = USER_TEXT_SELECTOR;
} else {
text_selector = undefined;
}
if (text_selector !== undefined) {
//it is a chat box from bot
const addAfter = chatbox.querySelector(CHAT_TEXT_SELECTOR);
const addAfter = chatbox.querySelector(text_selector);

if (chatbox.querySelector(`.${CLIPBOARD_CLASS_NAME}`) === null) {

Expand All @@ -95,7 +105,7 @@
</div>`);
chatbox.querySelector(`.${CLIPBOARD_CLASS_NAME}`).addEventListener('click', function () {

const text = chatbox.querySelector(CHAT_TEXT_SELECTOR).innerText;
const text = chatbox.querySelector(text_selector).innerText;
copyToClipboard(text);

});
Expand Down
1 change: 1 addition & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
transition: 0.3s;
display: flex;
align-items: center;
width: fit-content;
}

.emoji {
Expand Down