Skip to content

Commit

Permalink
Fixed textarea focus
Browse files Browse the repository at this point in the history
  • Loading branch information
mantou132 committed Dec 11, 2020
1 parent 2b5c8c8 commit 5ea7bd0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ipcRenderer, clipboard } from 'electron';
import { ipcRenderer } from 'electron';

import config from '../config';
import { CUSTOM_EVENT } from '../consts';
Expand All @@ -13,7 +13,6 @@ import './animate';

export interface InitPageOption {
sourceTextArea: string;
responseContainer: string;
sourceTTS: string;
responseTTS: string;
responseCopy: string;
Expand Down Expand Up @@ -66,11 +65,8 @@ const initTranslatePage = async (opt: InitPageOption) => {
}
// command + 3
if (e.keyCode === 51 && !e.altKey && (e.metaKey || e.ctrlKey)) {
const responseContainerEle = document.querySelector(opt.responseContainer);
const responseCopyEle = document.querySelector(opt.responseCopy) as HTMLElement | null;
const response = responseContainerEle && responseContainerEle.textContent?.trim();
if (response && responseCopyEle) {
clipboard.writeText(response);
if (responseCopyEle) {
click(responseCopyEle);
}
}
Expand Down Expand Up @@ -142,7 +138,6 @@ if (href.startsWith(config.translateUrl) || href.startsWith(config.translateUrlF
injectCSS();
initTranslatePage({
sourceTextArea: 'textarea[aria-autocomplete="list"]',
responseContainer: '[role="region"] > [jsaction][jsname] > [data-language] > div > span[lang][jsaction][jsname]',
sourceTTS: 'div[data-enable-toggle-playback-speed][data-location="1"] > button[aria-label][jscontroller][jsname]',
responseTTS: 'div[data-enable-toggle-playback-speed][data-location="2"] > button[aria-label][jscontroller][jsname]',
responseCopy: 'div[data-enable-toggle-playback-speed][data-location="2"] + button',
Expand Down
2 changes: 1 addition & 1 deletion src/preload/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function click(ele: HTMLElement) {
ele.dispatchEvent(new MouseEvent('mouseup'));
ele.click();
if (activeElement instanceof HTMLElement) {
activeElement.focus();
setTimeout(() => activeElement.focus(), 1000);
}
}

Expand Down

0 comments on commit 5ea7bd0

Please sign in to comment.