Skip to content

Commit

Permalink
fix shadow dom performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ttop32 committed Dec 27, 2023
1 parent e438cd9 commit f1cbb80
Show file tree
Hide file tree
Showing 31 changed files with 125 additions and 116 deletions.
3 changes: 3 additions & 0 deletions config/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ const common = {
{
from: "**/*",
context: "public",
filter: (resourcePath) => {
return !resourcePath.includes(".map");
},
},
],
}),
Expand Down
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.104
- fix shadow dom performance
- 0.1.103
- update tesseract js v5.0.3
- fix pdf shortcut key (request by woong park)
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/el/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Μεταφραστής εργαλείων ποντικιού : Translate Image"
"message": "Μεταφραστής εργαλείων ποντικιού: Translate Image"
},
"appDesc": {
"message": "Μεταφραστής εργαλείων ποντικιού Μεταφράστε κείμενο ποντικιού χρησιμοποιώντας το Google Translate"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Traductor de información sobre herramientas del mouse"
"message": "Traductor de información sobre herramientas del mouse for Education"
},
"appDesc": {
"message": "El traductor de información sobre herramientas de mouse traducir el texto de mouseover usando Google Translate"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/es_419/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Traductor de información sobre herramientas del mouse for Education"
"message": "Traductor de información sobre herramientas del mouse : deepl google translate"
},
"appDesc": {
"message": "El traductor de información sobre herramientas de mouse traducir el texto de mouseover usando Google Translate"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/et/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Hiire tööriistavihje tõlkija for Studying Language"
"message": "Hiire tööriistavihje tõlkija : TTS"
},
"appDesc": {
"message": "Hiire tööriistapeal tõlkija tõlkida hiireoveri teksti Google'i abil"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/fil/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Mouse Tooltip Translator For Chrome and Edge"
"message": "Mouse Tooltip Translator For Chrome Edge"
},
"appDesc": {
"message": "Mouse Tooltip Translator translate mouseover text using google translate"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/gu/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "માઉસ ટૂલટિપ અનુવાદક : TTS"
"message": "માઉસ ટૂલટિપ અનુવાદક: TTS"
},
"appDesc": {
"message": "ગૂગલ ટ્રાન્સલેશનનો ઉપયોગ કરીને માઉસ ટૂલટિપ અનુવાદક માઉસઓવર ટેક્સ્ટનું ભાષાંતર કરે છે"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/hi/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "माउस टूलटिप अनुवादक With Voice Speech translator"
"message": "माउस टूलटिप अनुवादक : PDF Translator"
},
"appDesc": {
"message": "माउस टूलटिप ट्रांसलेटर अनुवाद करें माउसओवर पाठ Google अनुवाद का उपयोग करके"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/hr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Translator Alat -a za miša : Dictionary & Papago"
"message": "Translator Alat -a za miša: Dictionary & Papago"
},
"appDesc": {
"message": "Translator Mouse Tooltip Prevodite tekst MouseOver pomoću Google Translatea"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/hu/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Egér ToolTip fordító : Subtitle Epub Reader Translator"
"message": "Egér ToolTip fordító : Subtitle Translator"
},
"appDesc": {
"message": "Egér ToolTip Translator fordítása MouseOver szöveget a Google Translate segítségével"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/id/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Judul "
},
"appName": {
"message": "Penerjemah Tooltip Mouse : Penerjemah AI"
"message": "Penerjemah Tooltip Mouse: Penerjemah AI"
},
"appDesc": {
"message": "Penerjemah Tooltip Mouse yang Menerjemahkan Teks Saat Diarahkan Mouse Menggunakan Google Translate"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/it/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Traduttore di tooltip del mouse With TTS OCR"
"message": "Traduttore di tooltip del mouse: TTS OCR"
},
"appDesc": {
"message": "Traduttore di tooltip del mouse Translate Testo del mouseover usando Google Translate"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/lt/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Pelės patarimų vertėjas : Translate Youtube"
"message": "Pelės patarimų vertėjas: Translate Youtube"
},
"appDesc": {
"message": "Pelės patarimo vertėjas vertėjas versti pelės viršų"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/lv/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Peles rīku padomu tulkotājs : Translate Manga, Epub Viewer"
"message": "Peles rīku padomu tulkotājs: Translate Manga"
},
"appDesc": {
"message": "Peles rīka padomu tulkotājs tulkot peles pārsniegšanas tekstu, izmantojot Google tulkojumu"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/ml/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "മൗസ് ടൂൾടിപ്പ് പരിഭാഷകൻ : translate pdf subtitle"
"message": "മൗസ് ടൂൾടിപ്പ് പരിഭാഷകൻ: translate pdf subtitle"
},
"appDesc": {
"message": "മ mouse സ് ടൂൾടിപ്പ് ട്രാൻസ്ലേറ്റർ വിവർത്തനം ചെയ്യുക മസോവർ ടെക്സ്റ്റ് Google വിവർത്തനം ഉപയോഗിച്ച്"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/mr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "माउस टूलटिप ट्रान्सलेटर With Dual Subtitles & translate ebook viewer"
"message": "माउस टूलटिप ट्रान्सलेटर: Dual Subtitles"
},
"appDesc": {
"message": "माउस टूलटिप ट्रान्सलेटर Google भाषांतर वापरून माउसओव्हर मजकूराचे भाषांतर करा"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/ms/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Penterjemah Tooltip Mouse for PDF GOOGLE DOCS"
"message": "Penterjemah Tooltip Mouse: PDF GOOGLE DOCS"
},
"appDesc": {
"message": "Penterjemah Tooltip Mouse Terjemahkan Teks Mouseover Menggunakan Google Translate"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/nl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Muise -gereedschap vertaler with translate chatgpt, ebook viewer"
"message": "Muise -gereedschap vertaler: translate chatgpt ebook viewer"
},
"appDesc": {
"message": "Muis Toltip Translator vertaalt mouseover -tekst met behulp van Google Translate"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/no/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Mus ToolTip Translator : PDF, Manga"
"message": "Mus ToolTip Translator : PDF Manga"
},
"appDesc": {
"message": "Mus ToolTip Translator Translate Mouseover -tekst ved hjelp av Google Translate"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/pl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Tłumacz myszy : Translate Writing"
"message": "Tłumacz myszy: Translate Writing"
},
"appDesc": {
"message": "Tłumacz myszy tłumacz tłumacza tekst myszy za pomocą tłumacza Google"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/pt_BR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Tradutor da dica de ferramenta do mouse With PDF Viewer"
"message": "Tradutor da dica de ferramenta do mouse With Epub PDF Viewer"
},
"appDesc": {
"message": "Mouse Tooltip Tradutor Traduzir Texto do MouseOver usando o Google Translate"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/sk/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Prekladateľ myši : Voice Speech Reader Translator"
"message": "Prekladateľ myši: Voice Speech Reader"
},
"appDesc": {
"message": "Prekladač prekladateľ myši prekladač Mouseover text pomocou prekladu Google"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/sl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"message": "Title "
},
"appName": {
"message": "Prevajalec orodij za miško For Productivity"
"message": "Prevajalec orodij za miško: Translator Extension"
},
"appDesc": {
"message": "Prevajalec za mišjo orodje Translate MuseOver besedilo z uporabo Google Translate"
Expand Down
10 changes: 4 additions & 6 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import browser from "webextension-polyfill";
import { waitUntil } from "async-wait-until";
import delay from "delay";

import translator from "./translator/index.js";
import * as util from "/src/util";
Expand Down Expand Up @@ -310,7 +309,7 @@ function getBase64Url(blob) {

async function playSound(source, rate, volume) {
await createOffscreen();
await chrome.runtime.sendMessage({
await util.sendMessage({
play: {
source,
rate,
Expand All @@ -321,14 +320,13 @@ async function playSound(source, rate, volume) {

async function stopTtsOffscreen() {
await createOffscreen();
await chrome.runtime.sendMessage({ stop: {} });
// removeOffscreen();
util.sendMessage({ stop: {} });
}

// Create the offscreen document
async function createOffscreen() {
try {
await chrome.offscreen.createDocument({
await browser.offscreen.createDocument({
url: "offscreen.html",
reasons: ["AUDIO_PLAYBACK"],
justification: "play tts", // details for using the API
Expand All @@ -340,7 +338,7 @@ async function createOffscreen() {

function removeOffscreen() {
return new Promise((resolve, reject) => {
chrome.offscreen.closeDocument(() => resolve());
browser.offscreen.closeDocument(() => resolve());
});
}

Expand Down
43 changes: 15 additions & 28 deletions src/ocr/ocrIframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ window.addEventListener(
async function ({ data }) {
if (data.type === "ocr") {
doOcr(data);
} else if (data.type === "initTesseract") {
initTesseract(data);
}
},
false
Expand All @@ -31,7 +29,6 @@ async function doOcr(request) {
try {
var canvas = await loadImage(request.base64Url);
// document.body.appendChild(canvas);

ocrData = await useTesseract(
canvas,
request.lang,
Expand Down Expand Up @@ -75,7 +72,7 @@ function useTesseract(image, lang, rectangles, mode) {
var data = [];
var scheduler = await getScheduler(lang, mode);
// //ocr on plain image
if (mode == "auto") {
if (mode.includes("auto")) {
var d = await scheduler.addJob("recognize", image);
data = [d];

Expand All @@ -99,32 +96,29 @@ function useTesseract(image, lang, rectangles, mode) {
}
async function getScheduler(lang, mode) {
var id = lang + "_" + mode;
await waitUntil(() => schedulerList[id], {
timeout: WAIT_FOREVER,
});
return schedulerList[id];
}

async function loadScheduler(lang, mode) {
var id = lang + "_" + mode;
if (loadingList[id]) {
return;
if (schedulerList[id]) {
return schedulerList[id];
} else if (loadingList[id]) {
await waitUntil(() => schedulerList[id], {
timeout: WAIT_FOREVER,
});
return schedulerList[id];
}
loadingList[id] = true;

var scheduler = Tesseract.createScheduler();
var workerIndexList = mode == "auto" ? [0] : [0, 1, 2, 3];
var workerIndexList = mode.includes("auto") ? [0] : [0, 1, 2, 3];
var workerPath = chrome.runtime.getURL("/tesseract/worker.min.js");
var corePath = chrome.runtime.getURL(
"/tesseract/tesseract-core-lstm.wasm.js"
);

var tessedit_pageseg_mode =
mode == "auto"
? Tesseract.PSM.AUTO_ONLY
: lang.includes("vert")
? Tesseract.PSM.SINGLE_BLOCK_VERT_TEXT
: Tesseract.PSM.SINGLE_BLOCK;
var tessedit_pageseg_mode = mode.includes("auto")
? Tesseract.PSM.AUTO_ONLY
: lang.includes("vert")
? Tesseract.PSM.SINGLE_BLOCK_VERT_TEXT
: Tesseract.PSM.SINGLE_BLOCK;

await Promise.all(
workerIndexList.map(async (i) => {
Expand All @@ -145,14 +139,7 @@ async function loadScheduler(lang, mode) {
);

schedulerList[id] = scheduler;
}

function initTesseract(request) {
loadScheduler(request.lang, request.mode);

response({
windowPostMessageProxy: request.windowPostMessageProxy,
});
return schedulerList[id];
}

function response(data) {
Expand Down
Loading

0 comments on commit f1cbb80

Please sign in to comment.