From 34ea3829e7cb435a4357b43fcfff514fdd39083e Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 29 Jan 2023 16:46:15 +0100 Subject: separate yomichan into user.js patch and sentence-export plugin --- yomichan/copy.svg | 3 -- yomichan/custom.css | 23 ----------- yomichan/makefile | 63 +++++++++++++++++------------ yomichan/readme.md | 32 --------------- yomichan/script.svg | 3 ++ yomichan/search.html.diff | 17 ++++++++ yomichan/sentence-export.css | 1 - yomichan/sentence-export.js | 85 ---------------------------------------- yomichan/settings.html.diff | 69 ++++++++++++++++++++++++++++++++ yomichan/userscript-loader.js | 6 +++ yomichan/userscript-settings.css | 11 ++++++ 11 files changed, 144 insertions(+), 169 deletions(-) delete mode 100644 yomichan/copy.svg delete mode 100644 yomichan/custom.css delete mode 100644 yomichan/readme.md create mode 100644 yomichan/script.svg create mode 100644 yomichan/search.html.diff delete mode 100644 yomichan/sentence-export.css delete mode 100644 yomichan/sentence-export.js create mode 100644 yomichan/settings.html.diff create mode 100644 yomichan/userscript-loader.js create mode 100644 yomichan/userscript-settings.css (limited to 'yomichan') diff --git a/yomichan/copy.svg b/yomichan/copy.svg deleted file mode 100644 index ff2f5a9..0000000 --- a/yomichan/copy.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/yomichan/custom.css b/yomichan/custom.css deleted file mode 100644 index 7ce95f8..0000000 --- a/yomichan/custom.css +++ /dev/null @@ -1,23 +0,0 @@ -.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/makefile b/yomichan/makefile index c4bd45e..cc8b50d 100644 --- a/yomichan/makefile +++ b/yomichan/makefile @@ -1,11 +1,23 @@ -all: sentence-export.min.js +all: -.PHONY: clean patch +.PHONY: clean patch download backup include ../common.mk -yomichan/js/user.js: yomichan sentence-export.min.js - ln -sf ../../sentence-export.min.js $@ +yomichan/images/%.svg: %.svg + cp $< $@ + +yomichan/css/%.css: %.css + cp $< $@ + +yomichan/js/%.js: %.js + cp $< $@ + +yomichan/%.patched: %.diff + patch -so - $(@:.patched=) < $< > $@ + +yomichan/%.bak: yomichan/% + cp $< $@ yomichan-chrome.zip: curl https://github.com/FooSoft/yomichan/releases/latest/download/$@ -Lso- > $@ @@ -19,29 +31,30 @@ yomichan/manifest.json.bak: yomichan/search.html.bak: cp yomichan/search.html $@ -yomichan/manifest-patched.json: yomichan/manifest.json.bak - jq '.content_scripts[0].js[.content_scripts[0].js | length] |= .+ "js/user.js"' $< > $@ - -yomichan/search-patched.html: yomichan/search.html.bak - sed 's##\n#' $< > $@ - -yomichan/images/%.svg: %.svg - ln -sf ../../copy.svg $@ - -yomichan/css/%.css: %.css - ln -sf ../../$< $@ - -patch: yomichan -patch: yomichan/search-patched.html -patch: yomichan/manifest-patched.json -patch: yomichan/js/user.js -patch: yomichan/images/copy.svg -patch: yomichan/css/sentence-export.css +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'"'"' $< > $@ + +download: yomichan +backup: download +backup: yomichan/manifest.json.bak +backup: yomichan/search.html.bak +backup: yomichan/settings.html.bak +patch: backup +patch: yomichan/js/userscript-loader.js +patch: yomichan/images/script.svg +patch: yomichan/css/userscript-settings.css +patch: yomichan/search.html.patched +patch: yomichan/settings.html.patched +patch: yomichan/manifest.json.patched patch: - ln -sf search-patched.html yomichan/search.html - ln -sf manifest-patched.json yomichan/manifest.json + mv yomichan/search.html.patched yomichan/search.html + mv yomichan/settings.html.patched yomichan/settings.html + mv yomichan/manifest.json.patched yomichan/manifest.json -yomichan-chrome-patched.zip: yomichan patch +yomichan-chrome-patched.zip: patch zip -qr $@ $< clean: diff --git a/yomichan/readme.md b/yomichan/readme.md deleted file mode 100644 index e82bb00..0000000 --- a/yomichan/readme.md +++ /dev/null @@ -1,32 +0,0 @@ -# yomichan stuff - -## custom css - -this is just a custom theme, and can be easily installed by pasting the -contents of [custom.css](custom.css) into yomichan's settings. - -## 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. - -![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/script.svg b/yomichan/script.svg new file mode 100644 index 0000000..721a36c --- /dev/null +++ b/yomichan/script.svg @@ -0,0 +1,3 @@ + + + diff --git a/yomichan/search.html.diff b/yomichan/search.html.diff new file mode 100644 index 0000000..75f815c --- /dev/null +++ b/yomichan/search.html.diff @@ -0,0 +1,17 @@ +--- yomichan-original/search.html 2022-10-30 12:39:42.000000000 +0100 ++++ yomichan/search.html 2023-01-29 15:40:23.336897401 +0100 +@@ -16,6 +16,7 @@ + + + ++ + + + +@@ -128,6 +129,5 @@ + + + +- + + diff --git a/yomichan/sentence-export.css b/yomichan/sentence-export.css deleted file mode 100644 index eb2ecea..0000000 --- a/yomichan/sentence-export.css +++ /dev/null @@ -1 +0,0 @@ -.icon[data-icon=copy] { --icon-image: url(/images/copy.svg); } diff --git a/yomichan/sentence-export.js b/yomichan/sentence-export.js deleted file mode 100644 index 3b2a476..0000000 --- a/yomichan/sentence-export.js +++ /dev/null @@ -1,85 +0,0 @@ -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 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/settings.html.diff b/yomichan/settings.html.diff new file mode 100644 index 0000000..2644ab3 --- /dev/null +++ b/yomichan/settings.html.diff @@ -0,0 +1,69 @@ +--- yomichan-original/settings.html 2022-10-30 12:39:42.000000000 +0100 ++++ yomichan/settings.html 2023-01-29 15:42:10.643564451 +0100 +@@ -14,6 +14,8 @@ + + + ++ ++ + + + +@@ -39,6 +41,7 @@ + Backup + Accessibility + Security ++ User script + + + + ++
++
++ ++
++
++
++
Configure user.js…
++
++ ++
++
++
++ + + + +@@ -3802,6 +3818,29 @@ + + + ++ ++ ++ + + + diff --git a/yomichan/userscript-loader.js b/yomichan/userscript-loader.js new file mode 100644 index 0000000..b9d9120 --- /dev/null +++ b/yomichan/userscript-loader.js @@ -0,0 +1,6 @@ +(async () => eval((await yomichan.api.getSettings([{ + scope: "profile", + optionsContext: { current: true }, + path: 'general.userScript' +}]))[0].result))(); + diff --git a/yomichan/userscript-settings.css b/yomichan/userscript-settings.css new file mode 100644 index 0000000..422096f --- /dev/null +++ b/yomichan/userscript-settings.css @@ -0,0 +1,11 @@ +.icon[data-icon=script] { --icon-image: url(/images/script.svg); } + +#user-script-container { + display: flex; + flex-flow: column nowrap; +} +#user-script-header { font-size: var(--font-size-small); } +#user-script-editor { + width: 100%; + flex: 1 1 auto; +} -- cgit v1.2.3