aboutsummaryrefslogtreecommitdiff
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
parent34ea3829e7cb435a4357b43fcfff514fdd39083e (diff)
update sentense-export to work with user.js
-rw-r--r--anki-card-template/back-template.html.m4 (renamed from anki-card-template/back-template.m4)2
-rw-r--r--anki-card-template/front-template.html.m4 (renamed from anki-card-template/front-template.m4)2
-rw-r--r--anki-card-template/makefile4
-rw-r--r--anki-card-template/template.html.m4 (renamed from anki-card-template/template.m4)5
-rw-r--r--assets/userscript.pngbin0 -> 14635 bytes
-rw-r--r--common.m44
-rw-r--r--common.mk8
-rw-r--r--readme.md5
-rw-r--r--yomichan-user/.gitignore7
-rw-r--r--yomichan-user/conf.d/custom.css (renamed from yomichan-user/custom.css)0
-rw-r--r--yomichan-user/conf.d/sentence-export.css.m41
-rw-r--r--yomichan-user/conf.d/sentence-export.js (renamed from yomichan-user/sentence-export.js)10
-rw-r--r--yomichan-user/header.txt.m45
-rw-r--r--yomichan-user/makefile32
-rw-r--r--yomichan-user/readme.md28
-rw-r--r--yomichan-user/sentence-export.css1
-rw-r--r--yomichan/makefile5
-rw-r--r--yomichan/readme.md27
18 files changed, 99 insertions, 47 deletions
diff --git a/anki-card-template/back-template.m4 b/anki-card-template/back-template.html.m4
index 79504dc..194c79b 100644
--- a/anki-card-template/back-template.m4
+++ b/anki-card-template/back-template.html.m4
@@ -1,2 +1,2 @@
define(`CARD_SIDE', `back')dnl
-include(`template.m4')dnl
+include(`template.html.m4')dnl
diff --git a/anki-card-template/front-template.m4 b/anki-card-template/front-template.html.m4
index dbfc810..384e112 100644
--- a/anki-card-template/front-template.m4
+++ b/anki-card-template/front-template.html.m4
@@ -1,3 +1,3 @@
define(`CARD_SIDE', `front')dnl
-include(`template.m4')dnl
+include(`template.html.m4')dnl
diff --git a/anki-card-template/makefile b/anki-card-template/makefile
index 013acb6..f567bab 100644
--- a/anki-card-template/makefile
+++ b/anki-card-template/makefile
@@ -5,8 +5,8 @@ all: back-template.html front-template.html
include ../common.mk
-back-template.html: card.min.js card.min.css template.m4
-front-template.html: card.min.js card.min.css template.m4
+back-template.html: card.min.js card.min.css template.html.m4
+front-template.html: card.min.js card.min.css template.html.m4
clean:
$(RM) back-template.html front-template.html card.min.js card.min.css
diff --git a/anki-card-template/template.m4 b/anki-card-template/template.html.m4
index 1b2a782..d3aba5d 100644
--- a/anki-card-template/template.m4
+++ b/anki-card-template/template.html.m4
@@ -1,7 +1,4 @@
-define(`EXEC',`translit(esyscmd($1),`
-')')dnl
-define(`TIMESTAMP',EXEC(`date'))dnl
-define(`VERSION',EXEC(`git describe --tags'))dnl
+include(`common.m4')dnl
<!-- lonkaars anki card template version VERSION()
generated at TIMESTAMP()
https://git.pipeframe.xyz/lonkaars/refold-tools -->
diff --git a/assets/userscript.png b/assets/userscript.png
new file mode 100644
index 0000000..eda73f4
--- /dev/null
+++ b/assets/userscript.png
Binary files differ
diff --git a/common.m4 b/common.m4
new file mode 100644
index 0000000..c9299e1
--- /dev/null
+++ b/common.m4
@@ -0,0 +1,4 @@
+define(`EXEC',`translit(esyscmd($1),`
+')')dnl
+define(`TIMESTAMP',EXEC(`date'))dnl
+define(`VERSION',EXEC(`git describe --tags'))dnl
diff --git a/common.mk b/common.mk
index d06ada1..0b18c7c 100644
--- a/common.mk
+++ b/common.mk
@@ -11,5 +11,9 @@ TRIM_WHITESPACE:=sed -E 's/^\s*(.*)\s+$$/\1/g'
%.min.css: %.css
cat $< | $(TO_SINGLE_LINE) | $(REMOVE_SLASH_STAR_COMMENTS) | $(REMOVE_TABS) | $(REMOVE_WHITESPACE) | $(TRIM_WHITESPACE) > $@
-%.html: %.m4
- m4 $< > $@
+%: %.m4
+ m4 -I.. $< > $@
+
+%.b64: %
+ base64 -w0 $< > $@
+
diff --git a/readme.md b/readme.md
index a25829c..7e3c082 100644
--- a/readme.md
+++ b/readme.md
@@ -3,6 +3,7 @@
this is a repo with language learning stuff:
- [anki sentence mining card template](anki-card-template/readme.md)
-- [yomichan stuff](yomichan/readme.md)
- (custom theme, sentence export/copy button patch)
+- [yomichan user.js patch](yomichan/readme.md)
+- [yomichan stuff](yomichan-user/readme.md)
+ (custom theme, sentence export/copy button plugin)
diff --git a/yomichan-user/.gitignore b/yomichan-user/.gitignore
new file mode 100644
index 0000000..6230d27
--- /dev/null
+++ b/yomichan-user/.gitignore
@@ -0,0 +1,7 @@
+*.b64
+header.txt
+user.css
+user.js
+yomichan-user.css
+yomichan-user.js
+conf.d/sentence-export.css
diff --git a/yomichan-user/custom.css b/yomichan-user/conf.d/custom.css
index 7ce95f8..7ce95f8 100644
--- a/yomichan-user/custom.css
+++ b/yomichan-user/conf.d/custom.css
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/sentence-export.js b/yomichan-user/conf.d/sentence-export.js
index 3b2a476..fb034d1 100644
--- a/yomichan-user/sentence-export.js
+++ b/yomichan-user/conf.d/sentence-export.js
@@ -63,23 +63,13 @@ function patchSearchBar() {
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() {
if (document.body.classList.contains("patched")) return;
patchSearchBar();
- patchCSS();
document.body.classList.add("patched");
}
run();
-window.onload = () => run();
diff --git a/yomichan-user/header.txt.m4 b/yomichan-user/header.txt.m4
new file mode 100644
index 0000000..f7f4152
--- /dev/null
+++ b/yomichan-user/header.txt.m4
@@ -0,0 +1,5 @@
+include(`common.m4')dnl
+/* yomichan user config version VERSION()
+ generated at TIMESTAMP()
+ https://git.pipeframe.xyz/lonkaars/refold-tools */
+
diff --git a/yomichan-user/makefile b/yomichan-user/makefile
new file mode 100644
index 0000000..b965974
--- /dev/null
+++ b/yomichan-user/makefile
@@ -0,0 +1,32 @@
+.PHONY: clean
+
+all: yomichan-user.js yomichan-user.css
+
+user.js: conf.d/sentence-export.js
+user.css: conf.d/sentence-export.css
+
+user.css: conf.d/custom.css
+
+include ../common.mk
+
+copy.svg.b64: copy.svg
+
+conf.d/sentence-export.css: copy.svg.b64
+conf.d/sentence-export.css: conf.d/sentence-export.css.m4
+
+user.js:
+ cat $^ > $@
+
+user.css:
+ cat $^ > $@
+
+header.txt: header.txt.m4
+
+yomichan-user.js: header.txt user.min.js
+ cat $^ > $@
+yomichan-user.css: header.txt user.min.css
+ cat $^ > $@
+
+clean:
+ $(RM) user.js user.css user.min.js user.min.css header.txt yomichan-user.css yomichan-user.js
+
diff --git a/yomichan-user/readme.md b/yomichan-user/readme.md
index e82bb00..6b0e0ed 100644
--- a/yomichan-user/readme.md
+++ b/yomichan-user/readme.md
@@ -1,32 +1,16 @@
# yomichan stuff
-## custom css
+this is a folder containing yomichan stuff
-this is just a custom theme, and can be easily installed by pasting the
-contents of [custom.css](custom.css) into yomichan's settings.
+all .js and .css files in conf.d get minified into user.min.js and
+user.min.css, and can be pasted into yomichan (with [user script
+patch](../yomichan/readme.md))
## sentence export
-this patches the yomichan plugin files to add an export button to the search
-bar for copying a sentence with furigana into my custom anki card template.
+adds an export button to the search bar for copying a sentence with furigana
+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)
-### set-up
-
-to download the latest yomichan version and patch it, leaving all files exposed
-for later updating (unpacked extension), run the following command:
-
-```
-make patch
-```
-
-to patch yomichan and convert it back to a zip (packed extension, non-signed,
-for use with kiwi browser), run:
-
-```
-make yomichan-chrome-patched.zip
-```
-
-if you want to update the patch or zip, replace `make` with `make -B`.
diff --git a/yomichan-user/sentence-export.css b/yomichan-user/sentence-export.css
deleted file mode 100644
index eb2ecea..0000000
--- a/yomichan-user/sentence-export.css
+++ /dev/null
@@ -1 +0,0 @@
-.icon[data-icon=copy] { --icon-image: url(/images/copy.svg); }
diff --git a/yomichan/makefile b/yomichan/makefile
index cc8b50d..1970755 100644
--- a/yomichan/makefile
+++ b/yomichan/makefile
@@ -34,8 +34,9 @@ yomichan/search.html.bak:
yomichan/search.html.patched: search.html.diff
yomichan/settings.html.patched: settings.html.diff
yomichan/manifest.json.patched: yomichan/manifest.json.bak
- jq '.content_scripts[0].js[.content_scripts[0].js | length] |= .+ "js/userscript-loader.js"' $< > $@
- jq '.content_security_policy |= .+ "'"; script-src 'self' 'unsafe-eval'"'"' $< > $@
+ jq '.content_scripts[0].js[.content_scripts[0].js | length] |= .+ "js/userscript-loader.js"' $< |\
+ jq '.content_security_policy |= .+ "'"; script-src 'self' 'unsafe-eval'"'"' |\
+ jq '.content_security_policy |= sub("img-src";"img-src data:")' > $@
download: yomichan
backup: download
diff --git a/yomichan/readme.md b/yomichan/readme.md
new file mode 100644
index 0000000..97f9904
--- /dev/null
+++ b/yomichan/readme.md
@@ -0,0 +1,27 @@
+# yomichan patch stuff
+
+adds a user.js script to your config and settings page that runs in the search
+page and popup window.
+
+![](../assets/userscript.png)
+
+## set-up
+
+to download the latest yomichan version and patch it, leaving all files exposed
+for later updating (unpacked extension), run the following command:
+
+> updating is currently broken, so you have to run `make clean` before `make
+> patch` to prevent the .html.patch files from being applied twice
+
+```
+make patch
+```
+
+to patch yomichan and convert it back to a zip (packed extension, non-signed,
+for use with kiwi browser), run:
+
+```
+make yomichan-chrome-patched.zip
+```
+
+if you want to update the patch or zip, replace `make` with `make -B`.