Skip to content

Commit d929637

Browse files
committed
replace shanbei with caiyun api
1 parent ecbc299 commit d929637

File tree

92 files changed

+72
-5507
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+72
-5507
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ Anki Tools for Mac
1818
- [wizyoung/googletranslate.popclipext](https://github.com/wizyoung/googletranslate.popclipext) for `cocoaDialog`
1919
- [wweir/popclip_exts](https://github.com/wweir/popclip_exts) for Youdao API
2020
- [Using curl POST with variables defined in bash script functions](https://stackoverflow.com/a/17032673)
21+
- [CaiyunWiki](https://open.caiyunapp.com/Main_Page)

sources/anki.popclipext/Config.plist

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<true/>
1616
<key>Title</key>
1717
<string>Anki</string>
18+
<key>After</key>
19+
<string>show-status</string>
1820
</dict>
1921
</array>
2022
<key>Options</key>
@@ -31,11 +33,33 @@
3133
<string>multiple</string>
3234
<key>Option Values</key>
3335
<array>
34-
<string>shanbay</string>
36+
<string>caiyun</string>
3537
<string>youdao</string>
3638
</array>
39+
<key>Option Value Labels</key>
40+
<array>
41+
<string>彩云小译</string>
42+
<string>有道词典</string>
43+
</array>
44+
<key>Option Default Value</key>
45+
<string>youdao</string>
46+
<key>Option Description</key>
47+
<string>choose Dictionary API</string>
48+
</dict>
49+
<dict>
50+
<key>Option Identifier</key>
51+
<string>api_token</string>
52+
<key>Option Label</key>
53+
<dict>
54+
<key>en</key>
55+
<string>API TOKEN</string>
56+
</dict>
57+
<key>Option Type</key>
58+
<string>string</string>
59+
<key>Option Default Value</key>
60+
<string>3975l6lr5pcbvidl6jl2</string>
3761
<key>Option Description</key>
38-
<string></string>
62+
<string>caiyun api token</string>
3963
</dict>
4064
<dict>
4165
<key>Option Identifier</key>
@@ -50,7 +74,7 @@
5074
<key>Option Default Value</key>
5175
<string>Default</string>
5276
<key>Option Description</key>
53-
<string></string>
77+
<string>choose Deck</string>
5478
</dict>
5579
<dict>
5680
<key>Option Identifier</key>
@@ -63,9 +87,9 @@
6387
<key>Option Type</key>
6488
<string>string</string>
6589
<key>Option Default Value</key>
66-
<string>Basic</string>
90+
<string>PopClip</string>
6791
<key>Option Description</key>
68-
<string></string>
92+
<string>choose Note Type</string>
6993
</dict>
7094
<dict>
7195
<key>Option Identifier</key>
@@ -80,7 +104,7 @@
80104
<key>Option Default Value</key>
81105
<string>Front</string>
82106
<key>Option Description</key>
83-
<string></string>
107+
<string>choose Front Field</string>
84108
</dict>
85109
<dict>
86110
<key>Option Identifier</key>
@@ -95,7 +119,22 @@
95119
<key>Option Default Value</key>
96120
<string>Back</string>
97121
<key>Option Description</key>
98-
<string></string>
122+
<string>choose Back Field</string>
123+
</dict>
124+
<dict>
125+
<key>Option Identifier</key>
126+
<string>source_field</string>
127+
<key>Option Label</key>
128+
<dict>
129+
<key>en</key>
130+
<string>Source Field</string>
131+
</dict>
132+
<key>Option Type</key>
133+
<string>string</string>
134+
<key>Option Default Value</key>
135+
<string>Source</string>
136+
<key>Option Description</key>
137+
<string>record the source</string>
99138
</dict>
100139
<dict>
101140
<key>Option Identifier</key>
@@ -110,13 +149,13 @@
110149
<key>Option Default Value</key>
111150
<string>PopClip</string>
112151
<key>Option Description</key>
113-
<string></string>
152+
<string>default tags</string>
114153
</dict>
115154
</array>
116155
<key>Extension Description</key>
117156
<string>Create a new Anki Note with selected word.</string>
118157
<key>Extension Identifier</key>
119-
<string>xyz.cdpath.anki</string>
158+
<string>blog.jingyi.anki</string>
120159
<key>Extension Name</key>
121160
<string>Anki</string>
122161
<key>Required Software Version</key>

sources/anki.popclipext/anki.sh

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,30 @@
99
## PopClip Env
1010
entry=${POPCLIP_TEXT:-debug}
1111
safe_entry=${POPCLIP_URLENCODED_TEXT:-debug}
12-
dict_service=${POPCLIP_OPTION_DICT_SVC:-shanbay}
12+
dict_service=${POPCLIP_OPTION_DICT_SVC:-caiyun}
1313
target_deck=${POPCLIP_OPTION_TARGET_DECK:-Default}
1414
note_type=${POPCLIP_OPTION_NOTE_TYPE:-Basic}
1515
front_field=${POPCLIP_OPTION_FRONT_FIELD:-Front}
1616
back_field=${POPCLIP_OPTION_BACK_FIELD:-Back}
17+
source_field=${POPCLIP_OPTION_SOURCE_FIELD:-Source}
1718
tag=${POPCLIP_OPTION_TAG:-debug}
1819
app_tag=${POPCLIP_APP_NAME// /_} # replace spaces with underscore
19-
20-
21-
## cocoaDialog
22-
dialog() {
23-
./dialog/Contents/MacOS/cocoaDialog bubble \
24-
--title "$1" \
25-
--text "$2" \
26-
--timeout "$3" \
27-
--icon-file anki.png
28-
}
20+
api_token=${POPCLIP_OPTION_API_TOKEN}
2921

3022

3123
## Dictionary Services
32-
_shanbay()
24+
_caiyun()
3325
{
3426
local safe_entry=$1
35-
url="https://api.shanbay.com/bdc/search/?word=$safe_entry"
36-
local definition=$(curl -sSL $url | perl -pe 's/^.*?(?<="definition":)(.*?[^\\]")(?=\,).*?$/$1/' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/^"//' -e 's/"$//')
37-
if [[ $definition = *'"status_code": 1'* ]]; then
38-
echo ''
39-
else
40-
echo ${definition//\\n/<br>}
41-
fi
27+
url="http://api.interpreter.caiyunai.com/v1/translator"
28+
DIRECTION="en2zh"
29+
BODY='{"source": ["'$safe_entry'"], "trans_type": "'$DIRECTION'", "replaced": true, "media": "text"}'
30+
31+
curl -sSL -XPOST $url \
32+
-H 'Content-Type: application/json' \
33+
-H "X-Authorization: token $api_token" \
34+
-d "$BODY" | python3 -c "import sys, json; print(json.load(sys.stdin)['target'][0])"
35+
4236
}
4337

4438
_youdao()
@@ -55,21 +49,21 @@ _youdao()
5549
look_up()
5650
{
5751
local safe_entry=$1
58-
if [ "$dict_service" = "shanbay" ]
52+
if [ "$dict_service" = "caiyun" ]
5953
then
60-
definition=$(_shanbay $safe_entry)
54+
definition=$(_caiyun "$safe_entry")
6155
elif [ "$dict_service" = "youdao" ]
6256
then
63-
definition=$(_youdao $safe_entry)
57+
definition=$(_youdao "$safe_entry")
6458
else
6559
definition=''
66-
echo "Not Implemented"
60+
echo "API Not Implemented"
6761
exit 1
6862
fi
6963

7064
if [[ -z "$definition" ]]; then
71-
dialog "$dict_service" "未找到单词" 3
72-
exit 1
65+
echo "Word Not Found"
66+
exit 2
7367
else
7468
echo $definition
7569
fi
@@ -88,7 +82,8 @@ gen_post_data()
8882
"note": {
8983
"fields": {
9084
"$front_field": "$entry",
91-
"$back_field": "$definition"
85+
"$back_field": "$definition",
86+
"$source_field": "<a href=\"${POPCLIP_BROWSER_URL}\">${POPCLIP_BROWSER_TITLE}</a>"
9287
},
9388
"modelName": "$note_type",
9489
"deckName": "$target_deck",
@@ -115,9 +110,9 @@ check_result()
115110
if [[ -z "$resp" ]]; then
116111
msg="Did you open anki?"
117112
fi
118-
dialog "AnkiConnect" "$msg" 5
113+
exit 2
119114
else
120-
dialog "$entry" "Saved to $target_deck" 5
115+
exit 0
121116
fi
122117
}
123118

Binary file not shown.

sources/anki.popclipext/dialog/Contents/Frameworks/Growl.framework/Headers/Growl.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)