-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webextension): support multiple workers
- Loading branch information
Showing
4 changed files
with
93 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
// @ts-ignore - replace webcomponent to shim | ||
import "@webcomponents/custom-elements"; | ||
import { browser } from "webextension-polyfill-ts"; | ||
import { attachToTextArea } from "textchecker-element"; | ||
import { attachToTextArea, LintEngineAPI } from "textchecker-element"; | ||
import { createEndpoint } from "comlink-extension"; | ||
import * as Comlink from "comlink"; | ||
import type { backgroundExposedObject } from "./background"; | ||
|
||
const port = Comlink.wrap<backgroundExposedObject>(createEndpoint(browser.runtime.connect())); | ||
const targetElement = document.querySelectorAll("textarea"); | ||
targetElement.forEach((element) => { | ||
const extOfTextarea = ".md"; | ||
return attachToTextArea({ | ||
textAreaElement: element, | ||
lintText: (args) => port.lintText({ ...args, ext: extOfTextarea }), | ||
fixText: (args) => port.fixText({ ...args, ext: extOfTextarea }), | ||
lintingDebounceMs: 200 | ||
|
||
async function contentScriptMain() { | ||
const lintEngine: LintEngineAPI = { | ||
lintText: port.lintText, | ||
fixText: port.fixText, | ||
fixAll: port.fixAll, | ||
fixRule: port.fixRule | ||
}; | ||
console.log("[ContentScript]", lintEngine); | ||
targetElement.forEach((element) => { | ||
return attachToTextArea({ | ||
textAreaElement: element, | ||
lintingDebounceMs: 200, | ||
lintEngine: lintEngine | ||
}); | ||
}); | ||
} | ||
|
||
console.log("[ContentScript]", "main"); | ||
contentScriptMain().catch((error) => { | ||
console.error("[texlint editor ContentScriptError]", error); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters