aboutsummaryrefslogtreecommitdiff
path: root/yomichan-user/conf.d
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-01-29 17:42:29 +0100
committerlonkaars <loek@pipeframe.xyz>2023-01-29 17:42:29 +0100
commite87f29e017a75af15d228d537bc20b9fc78ace24 (patch)
treecc4a7b76192d32290b569bedbcd8fedec9d7cda2 /yomichan-user/conf.d
parent34ea3829e7cb435a4357b43fcfff514fdd39083e (diff)
update sentense-export to work with user.js
Diffstat (limited to 'yomichan-user/conf.d')
-rw-r--r--yomichan-user/conf.d/custom.css23
-rw-r--r--yomichan-user/conf.d/sentence-export.css.m41
-rw-r--r--yomichan-user/conf.d/sentence-export.js75
3 files changed, 99 insertions, 0 deletions
diff --git a/yomichan-user/conf.d/custom.css b/yomichan-user/conf.d/custom.css
new file mode 100644
index 0000000..7ce95f8
--- /dev/null
+++ b/yomichan-user/conf.d/custom.css
@@ -0,0 +1,23 @@
+.search-header { margin-top: 12px; }
+.search-options { display: none; }
+:root[data-theme=dark] #content-body { background-color: #000000; }
+:root[data-theme=light] #content-body { background-color: #ffffff; }
+.tag .tag-label { background-color: unset; }
+.tag {
+ border: 2px solid var(--tag-color);
+ border-radius: 6px;
+}
+.frequency-group-tag .tag { border: none !important; }
+.tag .tag-body::before { display: none; }
+.frequency-value { font-weight: bold; }
+:root[data-theme=dark] .frequency-value { color: var(--tag-color); }
+.search-textbox-container {
+ border-radius: 6px;
+ overflow: hidden;
+}
+@media (hover: none) {
+ .entry .actions .action-button { padding: 16px; }
+ .search-header .search-button { width: 48px; }
+}
+:root[data-theme=light] { --tag-text-color: #333; }
+
diff --git a/yomichan-user/conf.d/sentence-export.css.m4 b/yomichan-user/conf.d/sentence-export.css.m4
new file mode 100644
index 0000000..eb0b5ac
--- /dev/null
+++ b/yomichan-user/conf.d/sentence-export.css.m4
@@ -0,0 +1 @@
+.icon[data-icon=copy] { --icon-image: url`(data:image/svg+xml;base64,'undivert(copy.svg.b64)`)'; }
diff --git a/yomichan-user/conf.d/sentence-export.js b/yomichan-user/conf.d/sentence-export.js
new file mode 100644
index 0000000..fb034d1
--- /dev/null
+++ b/yomichan-user/conf.d/sentence-export.js
@@ -0,0 +1,75 @@
+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 = "";
+
+ for (var child of inputHTML.children) {
+ for (var subchild of child.childNodes) {
+ if (subchild.nodeName == '#text') {
+ output += subchild.textContent;
+ continue;
+ }
+ if (subchild.nodeName == 'RUBY') {
+ output += `[${subchild.childNodes[0].innerText}](${subchild.childNodes[1].innerText})`;
+ continue;
+ }
+ }
+ }
+
+ 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);
+
+ return output;
+}
+
+function patchSearchBar() {
+ var searchBarOuter = document.getElementsByClassName("search-textbox-container")[0];
+ var button = document.createElement("button");
+ button.id = "anki-sentence-export-button";
+ button.classList.add("search-button");
+ button.onclick = exportSentence;
+ var icon = document.createElement("span");
+ icon.classList.add("icon");
+ icon.setAttribute("data-icon", "copy");
+ button.appendChild(icon);
+ searchBarOuter.insertBefore(button, searchBarOuter.childNodes[2]);
+}
+
+function run() {
+ if (document.body.classList.contains("patched")) return;
+
+ patchSearchBar();
+
+ document.body.classList.add("patched");
+}
+
+run();
+