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/lib.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 yomichan-user/conf.d/lib.js (limited to 'yomichan-user/conf.d/lib.js') diff --git a/yomichan-user/conf.d/lib.js b/yomichan-user/conf.d/lib.js new file mode 100644 index 0000000..6cb231e --- /dev/null +++ b/yomichan-user/conf.d/lib.js @@ -0,0 +1,44 @@ +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 escapeYomichanCopy(text) { + var userClipboardSettings = await getClipboardSettings(); + var tempSettings = { + enableBackgroundMonitor: false, + enableSearchPageMonitor: false, + autoSearchContent: false, + maximumSearchLength: userClipboardSettings.maximumSearchLength, + }; + await setClipboardSettings(tempSettings); + + navigator.clipboard.writeText(text); + + // execute on next JS event loop + setTimeout(async () => await setClipboardSettings(userClipboardSettings), 0); +} + +function rubyHelper(element, reading) { + var out = ""; + for (var child of element.childNodes) { + if (reading && child.nodeName != "RT") continue; + if (!reading && child.nodeName == "RT") continue; + out += child.innerText; + } + return out; +} + -- cgit v1.2.3