From 99146502259dfc324ec427169e25554aaa91ab97 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 9 May 2023 20:19:22 +0200 Subject: WIP handwriting panel (added libs + button to search bar) --- .gitmodules | 3 +++ common.mk | 4 ++-- yomichan-user/.gitignore | 1 + yomichan-user/assets/draw.svg | 5 +++++ yomichan-user/conf.d/handwriting.css.m4 | 1 + yomichan-user/conf.d/handwriting.js | 24 ++++++++++++++++++++++++ yomichan-user/conf.d/sentence-export.js | 8 ++++++-- yomichan-user/conf.d/word-export.js | 8 ++++++-- yomichan-user/lib/handwriting.js | 1 + yomichan-user/makefile | 10 ++++++++++ yomichan-user/readme.md | 6 ++++++ 11 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 .gitmodules create mode 100644 yomichan-user/assets/draw.svg create mode 100644 yomichan-user/conf.d/handwriting.css.m4 create mode 100644 yomichan-user/conf.d/handwriting.js create mode 160000 yomichan-user/lib/handwriting.js diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..47bb06d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "yomichan-user/lib/handwriting.js"] + path = yomichan-user/lib/handwriting.js + url = https://github.com/ChenYuHo/handwriting.js diff --git a/common.mk b/common.mk index 9a3a5c3..7462e15 100644 --- a/common.mk +++ b/common.mk @@ -4,10 +4,10 @@ JSMIN ?= ../scripts/js2min CSSMIN ?= ../scripts/css2min %.min.js: %.js - $(JSMIN) < $< > $@ + $(JSMIN) $< > $@ %.min.css: %.css - $(CSSMIN) < $< > $@ + $(CSSMIN) $< > $@ %: %.m4 m4 $(M4FLAGS) $< > $@ diff --git a/yomichan-user/.gitignore b/yomichan-user/.gitignore index 6473ba0..513b772 100644 --- a/yomichan-user/.gitignore +++ b/yomichan-user/.gitignore @@ -6,3 +6,4 @@ yomichan-user.css yomichan-user.js conf.d/sentence-export.css conf.d/word-export.css +conf.d/handwriting.css diff --git a/yomichan-user/assets/draw.svg b/yomichan-user/assets/draw.svg new file mode 100644 index 0000000..fe0cfb9 --- /dev/null +++ b/yomichan-user/assets/draw.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/yomichan-user/conf.d/handwriting.css.m4 b/yomichan-user/conf.d/handwriting.css.m4 new file mode 100644 index 0000000..6b3727b --- /dev/null +++ b/yomichan-user/conf.d/handwriting.css.m4 @@ -0,0 +1 @@ +.icon[data-icon=draw] { --icon-image: url`(data:image/svg+xml;base64,'undivert(draw.svg.b64)`)'; } diff --git a/yomichan-user/conf.d/handwriting.js b/yomichan-user/conf.d/handwriting.js new file mode 100644 index 0000000..7e63224 --- /dev/null +++ b/yomichan-user/conf.d/handwriting.js @@ -0,0 +1,24 @@ +{ + +function patchSearchBar() { + var searchBarOuter = document.getElementsByClassName("search-textbox-container")[0]; + var button = document.createElement("button"); + button.id = "handwriting-input-toggle"; + button.classList.add("search-button"); + button.onclick = () => console.log("AAAA"); + var icon = document.createElement("span"); + icon.classList.add("icon"); + icon.setAttribute("data-icon", "draw"); + button.appendChild(icon); + searchBarOuter.insertBefore(button, searchBarOuter.childNodes[2]); +} + +(() => { + if (document.body.classList.contains("handwriting-patched")) return; + + patchSearchBar(); + + document.body.classList.add("handwriting-patched"); +})(); + +} diff --git a/yomichan-user/conf.d/sentence-export.js b/yomichan-user/conf.d/sentence-export.js index 176cdcd..f187b64 100644 --- a/yomichan-user/conf.d/sentence-export.js +++ b/yomichan-user/conf.d/sentence-export.js @@ -1,3 +1,5 @@ +{ + async function exportSentence() { var inputHTML = document.getElementById("query-parser-content"); var output = ""; @@ -43,10 +45,12 @@ function patchSearchBar() { } (() => { - if (document.body.classList.contains("patched")) return; + if (document.body.classList.contains("sentence-export-patched")) return; patchSearchBar(); - document.body.classList.add("patched"); + document.body.classList.add("sentence-export-patched"); })(); +} + diff --git a/yomichan-user/conf.d/word-export.js b/yomichan-user/conf.d/word-export.js index de036e4..8f512d6 100644 --- a/yomichan-user/conf.d/word-export.js +++ b/yomichan-user/conf.d/word-export.js @@ -1,3 +1,5 @@ +{ + function exportWord(entry) { var wordElement = entry.getElementsByClassName("headword-term")[0]; var hasKanji = false; @@ -43,7 +45,7 @@ function exportWord(entry) { function addWordCopyButtons() { var definitions = document.getElementById("dictionary-entries").getElementsByClassName("entry"); for (var definition of definitions) { - if (definition.classList.contains("patched")) continue; + if (definition.classList.contains("word-export-patched")) continue; var actions = definition.getElementsByClassName("actions")[0]; var button = document.createElement("button"); @@ -59,7 +61,7 @@ function addWordCopyButtons() { icon.setAttribute("data-title-default", title); button.appendChild(icon); actions.insertBefore(button, actions.childNodes[0]); - definition.classList.add("patched"); + definition.classList.add("word-export-patched"); } } @@ -75,3 +77,5 @@ function addWordCopyButtons() { exportWord(document.getElementsByClassName("entry-current")[0]); }); })(); + +} diff --git a/yomichan-user/lib/handwriting.js b/yomichan-user/lib/handwriting.js new file mode 160000 index 0000000..6d41109 --- /dev/null +++ b/yomichan-user/lib/handwriting.js @@ -0,0 +1 @@ +Subproject commit 6d41109d3293295a7d7678d0cb97f483d28f47ec diff --git a/yomichan-user/makefile b/yomichan-user/makefile index e0e543d..68a103b 100644 --- a/yomichan-user/makefile +++ b/yomichan-user/makefile @@ -2,27 +2,37 @@ M4FLAGS += -I./assets/ +JSMIN := uglifyjs +CSSMIN := uglifycss + all: yomichan-user.js yomichan-user.css user.js: conf.d/lib.js +user.js: lib/handwriting.js/handwriting.canvas.js + user.js: conf.d/sentence-export.js 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 +user.js: conf.d/handwriting.js +user.css: conf.d/handwriting.css include ../common.mk assets/copy.svg.b64: assets/copy.svg assets/copy-bitmap.svg.b64: assets/copy-bitmap.svg +assets/draw.svg.b64: assets/draw.svg GARBAGE += assets/copy.svg.b64 GARBAGE += assets/copy-bitmap.svg.b64 +GARBAGE += assets/draw.svg.b64 # extra dependencies conf.d/sentence-export.css: assets/copy.svg.b64 conf.d/sentence-export.css: conf.d/sentence-export.css.m4 conf.d/word-export.css: assets/copy-bitmap.svg.b64 +conf.d/handwriting.css: assets/draw.svg.b64 user.js: cat $^ > $@ diff --git a/yomichan-user/readme.md b/yomichan-user/readme.md index cead831..50f9423 100644 --- a/yomichan-user/readme.md +++ b/yomichan-user/readme.md @@ -35,3 +35,9 @@ adds the following shortcuts to yomichan: |Alt+J|select next definition (move down)| |Alt+K|select previous definition (move up)| |Alt+G|scroll back to top| + +## handwriting + +adds handwriting input panel to yomichan (WIP) + + -- cgit v1.2.3