Skip to content

Commit

Permalink
fix tooltip highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
ttop32 committed Jan 25, 2024
1 parent 9f91edd commit f41203d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 21 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.112
- fix tooltip highlight (request by marcello-pietrobon)
- 0.1.111
- support tooltip border (request by pussykiller)
- support writing translate on url search box (type "/ " to start) (request by Enlight432)
Expand Down
15 changes: 4 additions & 11 deletions src/popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@
import * as util from "/src/util";
import { isProxy, toRaw } from "vue";
import AboutPage from "./components/about.vue";
import { cloneDeep } from "lodash";
var langList = util.langList;
var langListWithAuto = util.concatJson({ Auto: "auto" }, langList); //copy lang and add auto
var langListWithNone = util.concatJson({ None: "null" }, langList); //copy lang and add none
var langListOpposite = util.langListOpposite;
var toggleList = {
Expand Down Expand Up @@ -358,10 +360,7 @@ var detectTypeList = {
Container: "container",
};
var translateListWithNone = util.copyJson(langList); //copy lang and add auto
translateListWithNone["None"] = "null";
var keyListWithAlways = util.copyJson(keyList); //copy lang and add auto
var keyListWithAlways = cloneDeep(keyList); //copy lang and add auto
keyListWithAlways["Always"] = "always";
var voiceTargetList = {
Expand Down Expand Up @@ -521,7 +520,7 @@ var advancedTabData = {
},
translateReverseTarget: {
description: chrome.i18n.getMessage("Reverse_Translate_Language"),
optionList: translateListWithNone,
optionList: langListWithNone,
},
useTransliteration: {
description: "Enable Transliteration (Experimental)",
Expand Down Expand Up @@ -663,12 +662,6 @@ export default {
link.download = "Mouse_Tooltip_Translator_History.csv";
link.click();
},
copyToClipboard(sourceText, targetText) {
var text = sourceText + " \n" + targetText;
navigator.clipboard.writeText(text).then((response) => {
this.copyAlertBar = true;
});
},
wrapWithTitleValueKey(inputList) {
// convert {key:item} as {title:key, value:item}
var textValList = [];
Expand Down
4 changes: 2 additions & 2 deletions src/translator/baseTranslator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEmpty, swapJsonKeyValue } from "/src/util";
import { isEmpty, invert } from "lodash";

export default class BaseTranslator {
static langCodeJson = {};
Expand Down Expand Up @@ -31,7 +31,7 @@ export default class BaseTranslator {
}
static decodeLangCode(lang) {
if (isEmpty(this.langCodeJsonSwapped)) {
this.langCodeJsonSwapped = swapJsonKeyValue(this.langCodeJson);
this.langCodeJsonSwapped = invert(this.langCodeJson);
}
return this.langCodeJsonSwapped[lang]
? this.langCodeJsonSwapped[lang]
Expand Down
60 changes: 52 additions & 8 deletions src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,14 +645,6 @@ export function copyJson(json) {
return JSON.parse(JSON.stringify(json));
}

export function isEmpty(obj) {
return Object.keys(obj).length === 0;
}

export function swapJsonKeyValue(json) {
return _.invert(json);
}

export function sortJsonByKey(json) {
return Object.keys(json)
.sort()
Expand Down Expand Up @@ -705,6 +697,58 @@ export function copyTextToClipboard(text) {
navigator.clipboard.writeText(text);
}

//rect===============================

export function filterOverlappedRect(rects) {
//filter duplicate rect
var rectSet = new Set();
rects = Array.from(rects).filter((rect) => {
var key = getRectKey(rect);
if (!rectSet.has(key)) {
rectSet.add(key);
return true;
}
return false;
});

//filter covered rect by other rect
rects = rects.filter((rect1) => {
for (const rect2 of rects) {
if (getRectKey(rect1) != getRectKey(rect2) && rectCovered(rect1, rect2)) {
return false;
}
}
return true;
});

return rects;
}

function getRectKey(rect) {
return `${rect.left}${rect.top}${rect.width}${rect.height}`;
}

function rectCovered(rect1, rect2) {
return (
rect2.top <= rect1.top &&
rect1.top <= rect2.bottom &&
rect2.top <= rect1.bottom &&
rect1.bottom <= rect2.bottom &&
rect2.left <= rect1.left &&
rect1.left <= rect2.right &&
rect2.left <= rect1.right &&
rect1.right <= rect2.right
);
}
function rectCollide(rect1, rect2) {
return !(
rect1.top > rect2.bottom ||
rect1.right < rect2.left ||
rect1.bottom < rect2.top ||
rect1.left > rect2.right
);
}

// performance=======================================================
export function cacheFn(fn) {
var cache = {};
Expand Down

0 comments on commit f41203d

Please sign in to comment.