aboutsummaryrefslogtreecommitdiff
path: root/yomichan-user/conf.d/lib.js
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-01-29 22:29:48 +0100
committerlonkaars <loek@pipeframe.xyz>2023-01-29 22:29:48 +0100
commit97b6e373ba2f654dadd9c299c09098879de964fc (patch)
treee0af41a66b133470394e34085dda61a21268ef1f /yomichan-user/conf.d/lib.js
parent2f74b3659b3aac4bd9bccee705f1b972a5332f4d (diff)
add copy button for copying word to custom card template
Diffstat (limited to 'yomichan-user/conf.d/lib.js')
-rw-r--r--yomichan-user/conf.d/lib.js44
1 files changed, 44 insertions, 0 deletions
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;
+}
+