feat: autofocus (#550)

This commit is contained in:
lencx
2023-03-05 10:12:46 +08:00
parent ce395e092b
commit e3e0c86aaf

View File

@@ -9,6 +9,9 @@ async function init() {
childList: true,
subtree: true,
});
document.addEventListener('visibilitychange', () =>
document.getElementsByTagName('textarea')[0]?.focus()
);
}
function chatBtns() {
@@ -92,6 +95,11 @@ function copyToClipboard(text, btn) {
}, 1000);
}
function focusOnInput() {
// This currently works because there is only a single `<textarea>` element on the ChatGPT UI page.
document.getElementsByTagName("textarea")[0].focus();
}
function setIcon(type) {
return {
copy: `<svg class="chatappico copy" stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"></path><rect x="8" y="2" width="8" height="4" rx="1" ry="1"></rect></svg>`,