aboutsummaryrefslogtreecommitdiff
path: root/yomichan-user/conf.d/lib.js
diff options
context:
space:
mode:
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;
+}
+