Skip to content

Commit 48c2c07

Browse files
committed
fix firefox
1 parent 9bdee1e commit 48c2c07

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

doc/description.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Mouseover Translate Any Language At Once
1919
English, Russian, Japanese, Chinese and so on
2020

2121
# Change Log
22+
- 0.1.178
23+
- fix firefox text detect conflict
2224
- 0.1.177
2325
- fix mouseover performance on chrome
2426
- fix firefox mouseover text slice logic

src/event/mouseover.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function getTextFromRange(
132132
output["mouseoverText"] = util.extractTextFromRange(wordRange);
133133
output["mouseoverRange"] = wordRange;
134134
}
135-
console.log(output["mouseoverText"])
135+
// console.log(output["mouseoverText"])
136136
return output;
137137
}
138138

@@ -149,10 +149,10 @@ function expandRange(range, type, useSegmentation, x, y) {
149149

150150

151151

152-
console.time("expandRangeWithSeg");
152+
// console.time("expandRangeWithSeg");
153153
range = expandRangeWithSeg(range, type, x, y);
154154

155-
console.timeEnd("expandRangeWithSeg");
155+
// console.timeEnd("expandRangeWithSeg");
156156

157157
} else {
158158
// for chrome, use range expand
@@ -344,7 +344,7 @@ function expandRangeWithSeg(rangeOri, type = "word", x, y) {
344344

345345

346346

347-
console.time("expandRangeWithSeginit");
347+
// console.time("expandRangeWithSeginit");
348348
var range = rangeOri.cloneRange();
349349
var rangeContainer = expandRange(range, "container");
350350
const textNode = rangeContainer.commonAncestorContainer;
@@ -358,37 +358,37 @@ function expandRangeWithSeg(rangeOri, type = "word", x, y) {
358358

359359

360360

361-
console.log('==========================================================');
362-
var wholeText = textNode.innerText;
363-
var wordSliceInfo = getWordSegmentInfo(wholeText, type);
361+
// console.log('==========================================================');
362+
// var wholeText = textNode.innerText;
363+
// var wordSliceInfo = getWordSegmentInfo(wholeText, type);
364364

365-
console.log("wholeText:", wholeText);
366-
var textLength = wholeText.length;
367-
var newLineCount = (wholeText.match(/\n/g) || []).length;
365+
// console.log("wholeText:", wholeText);
366+
// var textLength = wholeText.length;
367+
// var newLineCount = (wholeText.match(/\n/g) || []).length;
368368

369-
console.log("Text Length:", textLength);
370-
console.log("New Line Count:", newLineCount);
369+
// console.log("Text Length:", textLength);
370+
// console.log("New Line Count:", newLineCount);
371371

372-
console.log("wordSliceInfo:", wordSliceInfo);
372+
// console.log("wordSliceInfo:", wordSliceInfo);
373373

374-
console.log('==========================================================2');
374+
// console.log('==========================================================2');
375375
var wholeText = getNodeText(textNode);
376376

377377
var wordSliceInfo = getWordSegmentInfo(wholeText, type);
378-
console.log("wholeText:", wholeText);
379-
var textLength = wholeText.length;
380-
var newLineCount = (wholeText.match(/\n/g) || []).length;
378+
// console.log("wholeText:", wholeText);
379+
// var textLength = wholeText.length;
380+
// var newLineCount = (wholeText.match(/\n/g) || []).length;
381381

382-
console.log("Text Length:", textLength);
383-
console.log("New Line Count:", newLineCount);
384-
console.log("wordSliceInfo:", wordSliceInfo);
382+
// console.log("Text Length:", textLength);
383+
// console.log("New Line Count:", newLineCount);
384+
// console.log("wordSliceInfo:", wordSliceInfo);
385385

386386

387387
// get all word range by segment
388-
console.time("findWordRange");
388+
// console.time("findWordRange");
389389
const currentWordNode = findWordRange(wordSliceInfo, textNode, x, y);
390-
console.timeEnd("findWordRange");
391-
console.log("Current Word Node:", currentWordNode);
390+
// console.timeEnd("findWordRange");
391+
// console.log("Current Word Node:", currentWordNode);
392392
return currentWordNode;
393393
}
394394

@@ -416,15 +416,15 @@ function getWordSegmentInfo(text, type) {
416416
function findWordRange(wordSegInfo, textNode, x, y) {
417417
var newLineCount = 0;
418418

419-
console.log(wordSegInfo)
420-
console.log(textNode)
419+
// console.log(wordSegInfo)
420+
// console.log(textNode)
421421

422422
// console.time("wordSegInfoExtract");
423423
var wordSegInfoExtract = wordSegInfo
424424
.map((wordMeta) => {
425425
var word = wordMeta.segment;
426426
var index = wordMeta.index;
427-
// var newLine=0
427+
var newLine=0
428428
// if (word.includes("\n")) {
429429
// var newLine = (word.match(/\n/g) || []).length; // count new line
430430
// word = word.replace(/\n/g, "");

0 commit comments

Comments
 (0)