From b49925b09a8962411706b00a446f5cd84007a086 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 31 Dec 2022 12:47:27 +0100 Subject: temporarily turn off clipboard monitor on sentence export --- yomichan/sentence-export.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3