From ece7589e582f7da42b81484ce77ada9953c94dcd Mon Sep 17 00:00:00 2001 From: daniel k Date: Mon, 5 Feb 2024 21:12:16 +0900 Subject: [PATCH] fix ocr build conflict --- src/contentScript.js | 5 +++-- src/ocr/ocrIframe.js | 14 +++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/contentScript.js b/src/contentScript.js index 84909373..3a83be77 100644 --- a/src/contentScript.js +++ b/src/contentScript.js @@ -7,6 +7,7 @@ import tippy, { sticky, hideAll } from "tippy.js"; import { encode } from "he"; import matchUrl from "match-url-wildcard"; import delay from "delay"; +import browser from "webextension-polyfill"; import { enableSelectionEndEvent, @@ -746,7 +747,7 @@ function openPdfIframe(url) { $("embed").remove(); $("", { - src: util.getUrlExt( + src: browser.runtime.getURL( `/pdfjs/web/viewer.html?file=${encodeURIComponent(url)}` ), css: { @@ -790,7 +791,7 @@ function injectGoogleDocAnnotation() { return; } var s = document.createElement("script"); - s.src = util.getUrlExt("googleDocInject.js"); //chrome.runtime.getURL("js/docs-canvas.js"); + s.src = browser.runtime.getURL("googleDocInject.js"); //chrome.runtime.getURL("js/docs-canvas.js"); document.documentElement.appendChild(s); } diff --git a/src/ocr/ocrIframe.js b/src/ocr/ocrIframe.js index c0621712..20fd272b 100644 --- a/src/ocr/ocrIframe.js +++ b/src/ocr/ocrIframe.js @@ -4,8 +4,8 @@ //3. resend result to host import Tesseract from "tesseract.js"; - -import * as util from "/src/util"; +import { waitUntil, WAIT_FOREVER } from "async-wait-until"; +import browser from "webextension-polyfill"; var schedulerList = {}; var loadingList = {}; @@ -105,15 +105,19 @@ async function getScheduler(lang, mode) { if (schedulerList[id]) { return schedulerList[id]; } else if (loadingList[id]) { - await util.waitUntilForever(() => schedulerList[id]); + await waitUntil(() => schedulerList[id], { + timeout: WAIT_FOREVER, + }); return schedulerList[id]; } loadingList[id] = true; var scheduler = Tesseract.createScheduler(); var workerIndexList = mode.includes("auto") ? [0] : [0, 1, 2, 3, 4]; - var workerPath = util.getUrlExt("/tesseract/worker.min.js"); - var corePath = util.getUrlExt("/tesseract/tesseract-core-lstm.wasm.js"); + var workerPath = browser.runtime.getURL("/tesseract/worker.min.js"); + var corePath = browser.runtime.getURL( + "/tesseract/tesseract-core-lstm.wasm.js" + ); var tessedit_pageseg_mode = mode.includes("auto") ? Tesseract.PSM.AUTO_ONLY