From 5df777b6235b8df3080480c12e385173b6cfbac2 Mon Sep 17 00:00:00 2001 From: cdpath Date: Sun, 30 Sep 2018 16:15:48 +0800 Subject: [PATCH] More notification --- sources/anki.popclipext/anki.sh | 54 +++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/sources/anki.popclipext/anki.sh b/sources/anki.popclipext/anki.sh index 3a3302b..6d42908 100644 --- a/sources/anki.popclipext/anki.sh +++ b/sources/anki.popclipext/anki.sh @@ -3,18 +3,18 @@ # Created by cdpath on 2018/4/19. # Copyright © 2018 cdpath. All rights reserved. -set -xeuo pipefail +#set -xeuo pipefail ## PopClip Env -entry=$POPCLIP_TEXT -safe_entry=$POPCLIP_URLENCODED_TEXT -dict_svc=$POPCLIP_OPTION_DICT_SVC -target_deck=$POPCLIP_OPTION_TARGET_DECK -note_type=$POPCLIP_OPTION_NOTE_TYPE -front_field=$POPCLIP_OPTION_FRONT_FIELD -back_field=$POPCLIP_OPTION_BACK_FIELD -tag=$POPCLIP_OPTION_TAG +entry=${POPCLIP_TEXT:-debug} +safe_entry=${POPCLIP_URLENCODED_TEXT:-debug} +dict_service=${POPCLIP_OPTION_DICT_SVC:-shanbay} +target_deck=${POPCLIP_OPTION_TARGET_DECK:-Default} +note_type=${POPCLIP_OPTION_NOTE_TYPE:-Basic} +front_field=${POPCLIP_OPTION_FRONT_FIELD:-Front} +back_field=${POPCLIP_OPTION_BACK_FIELD:-Back} +tag=${POPCLIP_OPTION_TAG:-debug} app_tag=${POPCLIP_APP_NAME// /_} # replace spaces with underscore @@ -31,6 +31,7 @@ dialog() { ## Dictionary Services _shanbay() { + local safe_entry=$1 url="https://api.shanbay.com/bdc/search/?word=$safe_entry" local definition=$(curl -sSL $url | perl -pe 's/^.*?(?<="definition":)(.*?[^\\]")(?=\,).*?$/$1/' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/^"//' -e 's/"$//') if [[ $definition = *'"status_code": 1'* ]]; then @@ -42,6 +43,7 @@ _shanbay() _youdao() { + local safe_entry=$1 url="http://dict.youdao.com/m/search?q=$safe_entry" curl -sSL $url \ | sed -ne '/网络释义/,/更多释义/p' \ @@ -52,20 +54,21 @@ _youdao() look_up() { - local definition='' - if [ "$dict_svc" = "shanbay" ] + local safe_entry=$1 + if [ "$dict_service" = "shanbay" ] then - definition=$(_shanbay) - elif [ "$dict_svc" = "youdao" ] + definition=$(_shanbay $safe_entry) + elif [ "$dict_service" = "youdao" ] then - definition=$(_youdao) + definition=$(_youdao $safe_entry) else + definition='' echo "Not Implemented" exit 1 fi if [[ -z "$definition" ]]; then - dialog "$dict_svc" "未找到单词" 3 + dialog "$dict_service" "未找到单词" 3 exit 1 else echo $definition @@ -76,6 +79,7 @@ look_up() ## AnkiConnect gen_post_data() { + local definition=$1 cat <