aboutsummaryrefslogtreecommitdiff
path: root/yomichan-user
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-01-30 16:56:55 +0100
committerlonkaars <loek@pipeframe.xyz>2023-01-30 16:56:55 +0100
commit7722306155088966bd2e09a0a7ba910ca9141fd1 (patch)
tree69c990ec8cb645e383186c6f401140758bd82227 /yomichan-user
parentea06526ea33df1ae5b38065a87c72af1614ace22 (diff)
added shortcuts, fixed duplicate buttons and updated readme3.2.0
Diffstat (limited to 'yomichan-user')
-rw-r--r--yomichan-user/conf.d/shortcuts.js18
-rw-r--r--yomichan-user/conf.d/word-export.js15
-rw-r--r--yomichan-user/makefile2
-rw-r--r--yomichan-user/readme.md21
4 files changed, 53 insertions, 3 deletions
diff --git a/yomichan-user/conf.d/shortcuts.js b/yomichan-user/conf.d/shortcuts.js
new file mode 100644
index 0000000..0e2d2c8
--- /dev/null
+++ b/yomichan-user/conf.d/shortcuts.js
@@ -0,0 +1,18 @@
+(() => {
+ window.addEventListener("keydown", ev => {
+ if (ev.altKey != true) return;
+ if (ev.key == "j" || ev.key == "k") {
+ // alt j/k for moving up/down entries
+ var currentEntry = document.getElementsByClassName("entry-current")[0];
+ var sibling = currentEntry[ev.key == "j" ? "nextSibling" : "previousSibling"];
+ if (sibling == null) return;
+ currentEntry.classList.remove("entry-current");
+ sibling.classList.add("entry-current");
+ sibling.scrollIntoView({ behavior: "smooth", block: "center" });
+ }
+ else if (ev.key == "g") {
+ // g for going back to top
+ document.getElementById("content-scroll").scrollTo({ top: 0, behavior: "smooth" });
+ }
+ });
+})();
diff --git a/yomichan-user/conf.d/word-export.js b/yomichan-user/conf.d/word-export.js
index cbaece4..de036e4 100644
--- a/yomichan-user/conf.d/word-export.js
+++ b/yomichan-user/conf.d/word-export.js
@@ -1,5 +1,4 @@
-function exportWord() {
- var entry = this.parentNode.parentNode.parentNode;
+function exportWord(entry) {
var wordElement = entry.getElementsByClassName("headword-term")[0];
var hasKanji = false;
@@ -44,18 +43,23 @@ function exportWord() {
function addWordCopyButtons() {
var definitions = document.getElementById("dictionary-entries").getElementsByClassName("entry");
for (var definition of definitions) {
+ if (definition.classList.contains("patched")) continue;
var actions = definition.getElementsByClassName("actions")[0];
var button = document.createElement("button");
button.classList.add("action-button");
- button.onclick = exportWord;
+ button.onclick = function() { exportWord(this.parentElement.parentElement.parentElement); };
var icon = document.createElement("span");
+ var title = "Copy definition (Alt + C)";
icon.classList.add("icon");
icon.classList.add("color-icon");
icon.classList.add("action-icon");
icon.setAttribute("data-icon", "copy-bmp");
+ icon.setAttribute("title", title);
+ icon.setAttribute("data-title-default", title);
button.appendChild(icon);
actions.insertBefore(button, actions.childNodes[0]);
+ definition.classList.add("patched");
}
}
@@ -65,4 +69,9 @@ function addWordCopyButtons() {
if (ev.data.action == "renderMulti.response")
addWordCopyButtons();
});
+ window.addEventListener("keydown", ev => {
+ if (ev.key != "c") return;
+ if (ev.altKey != true) return;
+ exportWord(document.getElementsByClassName("entry-current")[0]);
+ });
})();
diff --git a/yomichan-user/makefile b/yomichan-user/makefile
index 4e93d1a..21b41d5 100644
--- a/yomichan-user/makefile
+++ b/yomichan-user/makefile
@@ -8,6 +8,7 @@ user.css: conf.d/sentence-export.css
user.css: conf.d/custom.css
user.js: conf.d/word-export.js
user.css: conf.d/word-export.css
+user.js: conf.d/shortcuts.js
include ../common.mk
@@ -26,6 +27,7 @@ user.css:
cat $^ > $@
header.txt: header.txt.m4
+header.txt: ../.git/HEAD
yomichan-user.js: header.txt user.min.js
cat $^ > $@
diff --git a/yomichan-user/readme.md b/yomichan-user/readme.md
index 6b0e0ed..cead831 100644
--- a/yomichan-user/readme.md
+++ b/yomichan-user/readme.md
@@ -14,3 +14,24 @@ into [my custom anki card template](../anki-card-template/readme.md).
![new copy button in yomichan search bar](../assets/copy-button-yomichan.png)
![copied sentence in anki](../assets/copy-button-anki.png)
+## word export
+
+adds a copy button to each definition for copying into [my custom anki card
+template](../anki-card-template/readme.md). (Should) automatically insert
+interpuncts, add pitch accent downfall step (if available), and marker if word
+is usually written as kana only. <kbd>Alt</kbd>+<kbd>C</kbd> to copy currently
+selected entry.
+
+![word copy button in yomichan](../assets/word-copy-yomichan.png)
+![copied word in anki](../assets/word-copy-anki.png)
+![copied word in anki (card display)](../assets/word-copy-anki-rendered.png)
+
+## shortcuts
+
+adds the following shortcuts to yomichan:
+
+|shortcut|action|
+|-|-|
+|<kbd>Alt</kbd>+<kbd>J</kbd>|select next definition (move down)|
+|<kbd>Alt</kbd>+<kbd>K</kbd>|select previous definition (move up)|
+|<kbd>Alt</kbd>+<kbd>G</kbd>|scroll back to top|