aboutsummaryrefslogtreecommitdiff
path: root/yomichan/sentence-export.js
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-12-28 19:41:06 +0100
committerlonkaars <loek@pipeframe.xyz>2022-12-28 19:41:06 +0100
commit76327f1d26a6bce69192a140fc4fa05528fc2f6d (patch)
treef7cc08650389074925c4fdf3ac49b9b8ba497191 /yomichan/sentence-export.js
parent8f75fa200e1042f09f0fe3c4805f5600e3567f54 (diff)
sentence export working
Diffstat (limited to 'yomichan/sentence-export.js')
-rw-r--r--yomichan/sentence-export.js48
1 files changed, 47 insertions, 1 deletions
diff --git a/yomichan/sentence-export.js b/yomichan/sentence-export.js
index c01e985..e38f001 100644
--- a/yomichan/sentence-export.js
+++ b/yomichan/sentence-export.js
@@ -1,5 +1,51 @@
+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;
+ }
+ }
+ }
+ navigator.clipboard.writeText(output);
+ 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 patchCSS() {
+ var csslink = document.createElement("link");
+ csslink.setAttribute("rel", "stylesheet");
+ csslink.setAttribute("type", "text/css");
+ csslink.setAttribute("href", "/css/sentence-export.css");
+ document.head.appendChild(csslink);
+}
+
function run() {
- console.log("it workey");
+ if (document.body.classList.contains("patched")) return;
+
+ patchSearchBar();
+ patchCSS();
+
+ document.body.classList.add("patched");
}
run();