diff --git a/doc/description.md b/doc/description.md index 0868dbca..06f2b747 100644 --- a/doc/description.md +++ b/doc/description.md @@ -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) diff --git a/src/popup.vue b/src/popup.vue index b56d40c1..df410cb9 100644 --- a/src/popup.vue +++ b/src/popup.vue @@ -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 = { @@ -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 = { @@ -521,7 +520,7 @@ var advancedTabData = { }, translateReverseTarget: { description: chrome.i18n.getMessage("Reverse_Translate_Language"), - optionList: translateListWithNone, + optionList: langListWithNone, }, useTransliteration: { description: "Enable Transliteration (Experimental)", @@ -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 = []; diff --git a/src/translator/baseTranslator.js b/src/translator/baseTranslator.js index 71c32434..b92208b4 100644 --- a/src/translator/baseTranslator.js +++ b/src/translator/baseTranslator.js @@ -1,4 +1,4 @@ -import { isEmpty, swapJsonKeyValue } from "/src/util"; +import { isEmpty, invert } from "lodash"; export default class BaseTranslator { static langCodeJson = {}; @@ -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] diff --git a/src/util/index.js b/src/util/index.js index 917c5c01..8b2562f2 100644 --- a/src/util/index.js +++ b/src/util/index.js @@ -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() @@ -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 = {};