Skip to content

Commit

Permalink
fix auto reader space stop
Browse files Browse the repository at this point in the history
  • Loading branch information
ttop32 committed Jan 12, 2025
1 parent 8fd3e21 commit ccfb255
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions doc/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Mouseover Translate Any Language At Once
English, Russian, Japanese, Chinese and so on

# Change Log
- 0.1.163
- fix auto reader space stop (requested by Neon Velvet)
- 0.1.162
- fix browser tts
- 0.1.161
Expand Down
16 changes: 12 additions & 4 deletions src/contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,21 +591,25 @@ function holdKeydownList(key) {
}
if (util.isCharKey(key)) {
util.requestStopTTS(Date.now() + 500);
killAutoReader();
}
}

async function startAutoReader() {
if (!keyDownList[setting["keyDownAutoReader"]]) {
return;
}
util.clearSelection();
util.requestKillAutoReaderTabs();
await killAutoReader();
await initAutoReader();
var hoveredData = await getMouseoverText(clientX, clientY);
var { mouseoverRange } = extractMouseoverText(hoveredData);
processAutoReader(mouseoverRange);
}

async function initAutoReader() {
util.clearSelection();
await killAutoReader(true);
}

async function processAutoReader(stagedRange) {
if (!stagedRange || isStopAutoReaderOn) {
hideTooltip();
Expand Down Expand Up @@ -655,10 +659,14 @@ function scrollAutoReader(range) {
scrollContainer.animate({ scrollTop: scrollTopValue }, autoReaderScrollTime);
}

async function killAutoReader() {
async function killAutoReader(request=false) {
if (request) {
util.requestKillAutoReaderTabs();
}
if (!isAutoReaderRunning || isStopAutoReaderOn) {
return;
}
util.clearSelection();
isStopAutoReaderOn = true;
util.requestStopTTS(Date.now(), true);
await util.waitUntilForever(() => !isAutoReaderRunning);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ var speechTabData = {
var advancedTabData = {
keyDownAutoReader: {
description: browser.i18n.getMessage("Auto_Reader_When"),
optionList: keyListWithAlways,
optionList: keyList,
},
keyDownTranslateWriting: {
description: browser.i18n.getMessage("Translate_Writing_When"),
Expand Down
2 changes: 1 addition & 1 deletion src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export function isLocalFileUrl(url) {
}

export function isCharKey(key) {
return /Key|Digit|Numpad/.test(key);
return /Key|Digit|Numpad|Space/.test(key);
}

export function isEdge() {
Expand Down

0 comments on commit ccfb255

Please sign in to comment.