diff options
-rw-r--r-- | yomichan/sentence-export.js | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/yomichan/sentence-export.js b/yomichan/sentence-export.js index e38f001..3b2a476 100644 --- a/yomichan/sentence-export.js +++ b/yomichan/sentence-export.js @@ -1,4 +1,22 @@ -function exportSentence() { +async function getClipboardSettings() { + return (await yomichan.api.getSettings([{ + scope: "profile", + optionsContext: { current: true }, + path: 'clipboard' + }]))[0].result; +} + +async function setClipboardSettings(settings) { + await yomichan.api.modifySettings([{ + scope: "profile", + optionsContext: { current: true }, + path: 'clipboard', + action: 'set', + value: settings + }]); +} + +async function exportSentence() { var inputHTML = document.getElementById("query-parser-content"); var output = ""; @@ -14,7 +32,21 @@ function exportSentence() { } } } + + var userClipboardSettings = await getClipboardSettings(); + var tempSettings = { + enableBackgroundMonitor: false, + enableSearchPageMonitor: false, + autoSearchContent: false, + maximumSearchLength: userClipboardSettings.maximumSearchLength, + }; + await setClipboardSettings(tempSettings); + navigator.clipboard.writeText(output); + + // execute on next JS event loop + setTimeout(async () => await setClipboardSettings(userClipboardSettings), 0); + return output; } |