aboutsummaryrefslogtreecommitdiff
path: root/ext/js/refold-tools.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/refold-tools.js')
-rw-r--r--ext/js/refold-tools.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/ext/js/refold-tools.js b/ext/js/refold-tools.js
new file mode 100644
index 00000000..99fc114f
--- /dev/null
+++ b/ext/js/refold-tools.js
@@ -0,0 +1,46 @@
+// TODO: how to get yomichan.api?
+
+export async function getClipboardSettings() {
+ return (await yomichan.api.getSettings([{
+ scope: "profile",
+ optionsContext: { current: true },
+ path: 'clipboard'
+ }]))[0].result;
+}
+
+export async function setClipboardSettings(settings) {
+ await yomichan.api.modifySettings([{
+ scope: "profile",
+ optionsContext: { current: true },
+ path: 'clipboard',
+ action: 'set',
+ value: settings
+ }]);
+}
+
+export 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);
+}
+
+export 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.textContent;
+ }
+ return out;
+}
+