From 97b6e373ba2f654dadd9c299c09098879de964fc Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 29 Jan 2023 22:29:48 +0100 Subject: add copy button for copying word to custom card template --- yomichan-user/conf.d/sentence-export.js | 38 +++------------------------------ 1 file changed, 3 insertions(+), 35 deletions(-) (limited to 'yomichan-user/conf.d/sentence-export.js') diff --git a/yomichan-user/conf.d/sentence-export.js b/yomichan-user/conf.d/sentence-export.js index f15d890..176cdcd 100644 --- a/yomichan-user/conf.d/sentence-export.js +++ b/yomichan-user/conf.d/sentence-export.js @@ -1,21 +1,3 @@ -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 = ""; @@ -42,19 +24,7 @@ async 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); + escapeYomichanCopy(output); return output; } @@ -72,13 +42,11 @@ function patchSearchBar() { searchBarOuter.insertBefore(button, searchBarOuter.childNodes[2]); } -function run() { +(() => { if (document.body.classList.contains("patched")) return; patchSearchBar(); document.body.classList.add("patched"); -} - -run(); +})(); -- cgit v1.2.3