Skip to content

Instantly share code, notes, and snippets.

@bjoerntx

bjoerntx/test.js Secret

Created July 6, 2023 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/3fbd2f83ce8be89c85be126470b5eece to your computer and use it in GitHub Desktop.
Save bjoerntx/3fbd2f83ce8be89c85be126470b5eece to your computer and use it in GitHub Desktop.
TXTextControl.addEventListener("textControlLoaded", async function () {
document.addEventListener("keydown", logKey);
async function logKey(e) {
if (e.key === "F8") {
const text = await getTextFromSelection();
const replacedText = await replaceWord(text);
if (replacedText !== undefined) {
await loadReplacedText(replacedText);
}
}
}
function getTextFromSelection() {
return new Promise(resolve => {
TXTextControl.selectWord(() => {
TXTextControl.selection.getText(text => resolve(text));
});
});
}
async function loadReplacedText(replacedText) {
const encodedText = btoa(replacedText);
await TXTextControl.selection.load(TXTextControl.StreamType.HTMLFormat, encodedText);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment