-
-
Save bjoerntx/3fbd2f83ce8be89c85be126470b5eece to your computer and use it in GitHub Desktop.
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
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