Skip to content

Commit bcf3541

Browse files
authored
v0.6 (#1)
* Half hearted attempt to convert to real project. Fix for counting syllables in words containing erhua that is actually pronounced (ex 婴儿). * Allow setting HSK threshold for vocabulary list. * Further refactoring. * Add verbose vocab feature. Fix issue with settings defaults. * Add word spacing feature. Make translation hints bigger. * Add toggle pinyin and translation features. Remove useless toggle story button. * Improvements to punctuation handling when generating pinyin text. * Allow hovering pinyin words to see hanzi and definition. * Add Makefile and userscript header, update docs. * Housekeeping, clean up build process. * Make some CSS rules a bit less strict. * Add changelog.md * Disable a few local fonts used for testing
1 parent 44c6f61 commit bcf3541

25 files changed

+9284
-1467
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

.eslintrc.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"extends": "./node_modules/gts/",
3+
"env": {
4+
"es2022": true,
5+
"browser": true,
6+
"greasemonkey": true
7+
},
8+
"parserOptions": {"ecmaVersion": 13, "sourceType": "module"},
9+
"ignorePatterns": ["build/**/*", "dist/**/*"],
10+
"rules": {
11+
"no-unused-vars": [
12+
"warn",
13+
{
14+
"argsIgnorePattern": "^_",
15+
"varsIgnorePattern": "^_",
16+
"caughtErrorsIgnorePattern": "^_"
17+
}
18+
],
19+
"@typescript-eslint/no-unused-vars": [
20+
"warn",
21+
{
22+
"argsIgnorePattern": "^_",
23+
"varsIgnorePattern": "^_",
24+
"caughtErrorsIgnorePattern": "^_"
25+
}
26+
],
27+
"node/no-unsupported-features/es-syntax": [
28+
"error",
29+
{"ignores": ["modules"]}
30+
]
31+
}
32+
}

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build/
2+
dist/
3+
.vscode/
4+
node_modules/
5+
*.bak
6+
*~
7+
.editorconfig

.prettierrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require('gts/.prettierrc.json')
3+
}

Makefile

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
DEPS=$(wildcard src/*.js src/*.ts ./asserts/userscript_header.txt ./package.json ./package-lock.json ./tsconfig.json ./webpack.config.js)
2+
VERSION=$(shell ( ( git describe --exact-match --tags || ( git symbolic-ref --short HEAD && git log --date=format:%y%m%d_%H%M --pretty=format:%h_%cd -1 ) || echo -n UNKNOWN ) | tr '\n' '-' ) 2>/dev/null )
3+
4+
.DEFAULT_TARGET: all
5+
6+
all: build-dev
7+
8+
.PHONY: clean
9+
clean:
10+
rm -f ./dist/*.js
11+
rm -fr ./build/
12+
13+
.PHONY: distclean
14+
distclean: clean
15+
rm -r ./node_modules
16+
17+
.PHONY: node-modules
18+
node-modules:
19+
npm install --ignore-scripts
20+
21+
build-dev: dist/duchinese-helper.userscript.js
22+
23+
build-prod: dist/duchinese-helper.min.userscript.js
24+
25+
.PHONY: dist/header.txt
26+
dist/header.txt:
27+
@sed 's@UNKNOWNVERSION@$(VERSION)@' < assets/userscript_header.txt > dist/header.txt
28+
29+
dist/duchinese-helper.userscript.js: node-modules dist/header.txt $(DEPS)
30+
npm run compile
31+
cat dist/header.txt dist/bundle.js > $@
32+
33+
dist/duchinese-helper.min.userscript.js: node-modules dist/header.txt $(DEPS)
34+
npm run compile-prod
35+
cat dist/header.txt dist/bundle.js > $@

README.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ The annotation position can also be set to appear before, after, above or below
4646

4747
##### Tone Color
4848

49-
Characters can be colored based on the tone of the syllable.
49+
Characters can be colored based on the tone of the syllable.
5050

5151
##### Sandhi
5252

@@ -69,7 +69,8 @@ You can copy the text of the lesson to clipboard.
6969
## Interface
7070

7171
* ⚙️ — Toggle configuration section visibility.
72-
* 👀 — Toggle lesson text visibility.
72+
* 👀 — Toggle pinyin section visibility.
73+
* 📜 — Toggle translation section visibility.
7374
* 💬 — Copy lesson text to clipboard.
7475
* 📚 — Toggle vocabulary section visibility.
7576

@@ -109,8 +110,16 @@ I wouldn't go that far, but DuChinese is aware of it, had access to the source a
109110

110111
### Is There Tracking/Monetization
111112

112-
None of the code I wrote does or will do anything like that. There is one small external dependency which is used to provide some functions. I verified that it doesn't do anything sinister, but I also can't control other people. It's unlikely to ever be a problem, but just saying "No" here technically wouldn't be 100% true.
113+
None of the code I wrote does or will do anything like that.
113114

114-
### Oh No I Saw The Word Spy
115+
## Building
115116

116-
Don't worry, this doesn't mean you're being spied on or tracked. The extension uses a third party library (mentioned above) called `xspy` which allows a script to watch what requests occur _only in its own window_. This is only used to collect the lesson content when the main site requests it.
117+
You will need a recent version of Node and NPM available. Describing how to get to that point is beyond the scope of this document.
118+
119+
On a Unix-type system, you can just use the `Makefile`
120+
121+
* Running `make` (or `make build-dev`) should generate the development, unminimized version of the userscript in `dist/duchinese-helper.userscript.js`
122+
123+
* Running `make build-prod` should create the minimized version of the userscript in `dist/duchinese-helper.min.userscript.js`
124+
125+
If you want, you can run `npm` yourself. `npm run compile` or `npm run compile-prod` (for minimized) will generate `dist/bundle.js`. This will need to be manually combined with the userscript header in `assets/userscript_header.txt`

assets/userscript_header.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ==UserScript==
2+
// @name DC Helper
3+
// @namespace https://github.com/KerfuffleV2/
4+
// @match https://duchinese.net/*
5+
// @match https://www.duchinese.net/*
6+
// @version UNKNOWNVERSION
7+
// @run-at document-start
8+
// @inject-into page
9+
// @grant GM_setClipboard
10+
// @grant GM_registerMenuCommand
11+
// @grant GM_setValue
12+
// @grant GM_getValue
13+
// @grant GM_deleteValue
14+
// @grant GM_addValueChangeListener
15+
// @author KerfuffleV2
16+
// @description Unofficial extensions for DuChinese (Mandarin Chinese learning site)
17+
// ==/UserScript==

changelog.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changes
2+
3+
Changelist, from most to last recent.
4+
5+
## 0.6
6+
7+
1. Convert to a real project.
8+
2. Fix for counting syllables in words containing erhua that is actually pronounced (for example 婴儿).
9+
3. Allow setting a minimum threshold for the vocabulary list (for example, only show items HSK 3 or higher).
10+
4. Add a feature to allow showing the vocabulary list in a more verbose format, including pinyin and definition.
11+
5. Add a feature to allow showing a space in between words.
12+
6. Increased the size of the hoverable translation hints (at the end of sentences).
13+
7. Remove the "toggle story text" feature (used the 👀) button.
14+
8. Add "toggle pinyin visibility" feature which will show the pinyin transliteration of the whole story. (Uses 👀.)
15+
9. Add "toggle translation visibility" feature which will show the translation of the whole story. (Uses 📜.)

0 commit comments

Comments
 (0)