Skip to content

Commit

Permalink
大幅度优化订阅规则和订阅界面显示,以及界面跳转逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
juewuy authored and juewuy committed Jul 31, 2020
1 parent c1f2e6d commit 0772d7a
Showing 1 changed file with 49 additions and 30 deletions.
79 changes: 49 additions & 30 deletions clash/clashsh
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,34 @@ EOF`
Https="https://$Server/sub?target=clashr&new_name=true&url=$Url&insert=false&config=$Config"
echo -----------------------------------------------
echo 正在连接服务器获取配置文件…………链接地址为:
echo $Https
echo -e "\033[4;32m$Https\033[0m"
echo 可以手动复制该链接到浏览器打开并查看数据是否正常!
echo -----------------------------------------------
echo '| |'
echo '| 需要一点时间,请耐心等待! |'
echo '| |'
echo -----------------------------------------------
echo -e "\033[36m-----------------------------------------------"
echo -e "| |"
echo -e "| 需要一点时间,请耐心等待! |"
echo -e "| |"
echo -e "-----------------------------------------------\033[0m"
#获取在线yaml文件
yamlnew=$yaml.new
rm $yamlnew > /dev/null 2>&1

result=$(curl -w %{http_code} -skLo $yamlnew $Https)
if [ "$result" != "200" ];then
echo -----------------------------------------------
echo 配置文件获取失败!请检查链接或者更换后端地址!
echo -e "\033[31m配置文件获取失败!\033[0m"
echo -----------------------------------------------
echo
read -p "是否更换后端地址后重试?[1/0] > " res
if [ "$res" = '1' ]; then
sed -i '/server_link=*/'d $ccfg
if [ "$server_link" = '4' ]; then
server_link=0
fi
server_link=$(($server_link + 1))
echo $server_link
sed -i "5i\server_link=$server_link" $ccfg
getyaml
fi
exit;
else
if cat $yamlnew | grep ', server:' >/dev/null;then
Expand Down Expand Up @@ -159,17 +172,21 @@ do
echo -----------------------------------------------
echo -e "\033[44m 实验性功能,遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m"
echo -----------------------------------------------
echo -e "\033[32m支持导入单个\033[30;47m Http \033[0;32m格式的订阅链接(多个会被覆盖)"
echo -e "支持批量导入\033[30;47m Vmess/SSR/SS/Trojan \033[0;32m格式的节点链接"
echo -e "多个较短的链接可以用|分隔以一次性输入"
echo -e "多个较长的链接请尽量分多次输入,可支持多达9次输入"
echo -e "\033[33m输入回车以开始导入链接!\033[0m"
echo -e "\033[33m支持批量导入\033[30;46m Http/Https/Clash \033[0;33m等格式的订阅链接"
echo -e "支持批量导入\033[30;42m Vmess/SSR/SS/Trojan/Sock5 \033[0;33m等格式的节点链接"
echo -e "\033[36m多个较短的链接可以用\033[30;47m | \033[0;36m分隔以一次性输入"
echo -e "多个较长的链接请尽量分多次输入,可支持多达\033[30;47m 9 \033[0;36m次输入"
echo -e "\033[0m注意SSR/SS不支持\033[30;47m chacha20加密 \033[0m"
echo -e "\033[44;37m直接输入回车以结束输入并开始导入链接!\033[0m"
echo -e "\033[33m 0 返回上级目录!\033[0m"
echo
url=""
read -p "请输入第"$i"个链接 > " url
test=$(echo $url | grep "://")
url=`echo ${url/\ \(*\)/''}` #删除恶心的超链接内容
url=`echo ${url/*\&url\=/""}` #将clash完整链接还原成单一链接
url=`echo ${url/\&config\=*/""}` #将clash完整链接还原成单一链接
url=`echo ${url//\&/\%26}` #将分隔符 & 替换成urlcode:%26
if [[ "$test" != "" ]];then
if [[ $i == 1 ]];then
Url="$url"
Expand All @@ -180,8 +197,8 @@ read -p "请输入第"$i"个链接 > " url
elif [ -z $url ];then
if [ -n $Url ];then
echo -----------------------------------------------
echo 请检查输入的链接是否正确
echo $Url
echo -e 请检查输入的链接是否正确
echo -e "\033[4m$Url\033[0m"
read -p "确认导入配置文件?原配置文件将被更名为config.bak![1/0] > " res
if [ "$res" = '1' ]; then
#将用户链接写入mark
Expand All @@ -191,18 +208,19 @@ read -p "请输入第"$i"个链接 > " url
getyaml
exit;
fi
clashlink
fi
elif [[ $url == 0 ]];then
clashlink
else
echo -----------------------------------------------
echo 请输入正确的订阅/分享链接!!!
echo -e "\033[31m请输入正确的订阅/分享链接!!!\033[0m"
fi
done
echo -----------------------------------------------
echo 输入太多啦,可能会导致订阅失败!
echo 多个较短的链接请尽量用|分隔以一次性输入!
echo 请检查输入的链接是否正确:$Url
echo "多个较短的链接请尽量用“|”分隔以一次性输入!"
echo -e "请检查输入的链接是否正确:\033[4m$Url\033[0m"
read -p "确认导入配置文件?原配置文件将被更名为config.bak![1/0] > " res
if [ "$res" = '1' ]; then
#将用户链接写入mark
Expand All @@ -216,7 +234,7 @@ read -p "确认导入配置文件?原配置文件将被更名为config.bak![1/
echo 操作已取消!返回上级菜单!
clashlink
fi

clashlink
}
clashlink(){
#获取订阅规则
Expand All @@ -228,12 +246,12 @@ fi
#获取后端服务器地址
if [ ! -n "$server_link" ]; then
sed -i '/server_link=*/'d $ccfg
sed -i "5i\server_link=1" $ccfg
server_link=1
sed -i "5i\server_link=3" $ccfg
server_link=3
fi
echo -----------------------------------------------
echo -e "\033[44m 实验性功能,遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m"
echo 欢迎使用订阅功能!
echo -e "\033[32m 欢迎使用订阅功能!\033[0m"
echo -e 1 输入订阅链接
echo -e 2 选取规则模版
echo -e 3 选择后端地址
Expand Down Expand Up @@ -268,7 +286,7 @@ elif [[ $num == 2 ]];then
sed -i '/rule_link*/'d $ccfg
sed -i "4i\rule_link="$num"" $ccfg
echo -----------------------------------------------
echo 设置成功!返回上级菜单!
echo -e "\033[32m设置成功!返回上级菜单!\033[0m"
clashlink
fi
elif [[ $num == 3 ]];then
Expand All @@ -293,27 +311,28 @@ elif [[ $num == 3 ]];then
sed -i '/server_link*/'d $ccfg
sed -i "4i\server_link="$num"" $ccfg
echo -----------------------------------------------
echo 设置成功!返回上级菜单!
echo -e "\033[32m设置成功!返回上级菜单!\033[0m"
clashlink
fi
elif [[ $num == 4 ]];then
yamlbak=$yaml.bak
if [ ! -f "$yaml".bak ];then
echo -----------------------------------------------
echo 没有找到配置文件的备份!
echo -e "\033[31m没有找到配置文件的备份!\033[0m"
else
echo -----------------------------------------------
echo 备份文件共有`wc -l < $yamlbak`行内容,当前文件共有`wc -l < $yaml`行内容
echo -e 备份文件共有"\033[32m`wc -l < $yamlbak`\033[0m"行内容,当前文件共有"\033[32m`wc -l < $yaml`\033[0m"行内容
read -p "确认还原配置文件?此操作不可逆![1/0] > " res
if [ "$res" = '1' ]; then
mv $yamlbak $yaml
echo -----------------------------------------------
echo 配置文件已还原!!!
echo -e "\033[32m配置文件已还原!请手动重启clash服务!\033[0m"
else
echo 操作已取消!返回上级菜单!
echo -----------------------------------------------
echo -e "\033[31m操作已取消!返回上级菜单!\033[0m"
fi
fi
clashlink
clashsh
elif [[ $num == 5 ]];then
if [ ! -n "$Url" ];then
echo -----------------------------------------------
Expand All @@ -322,8 +341,8 @@ elif [[ $num == 5 ]];then
else
echo -----------------------------------------------
echo -----------------------------------------------
echo 记录的订阅链接为:
echo $Url
echo -e "\033[33m当前系统记录的订阅链接为:\033[0m"
echo -e "\033[4;32m$Url\033[0m"
echo -----------------------------------------------
read -p "确认更新配置文件?[1/0] > " res
if [ "$res" = '1' ]; then
Expand Down

0 comments on commit 0772d7a

Please sign in to comment.