谷歌翻译退出中国,如何恢复 Chrome 翻译?

谷歌翻译在大陆地区停止服务了,用惯了chrome的,少了一个免费又方便的翻译工具。

下面介绍一个自动化的脚本,可以恢复谷歌翻译服务。

把代码保存为bat文件,以管理员身份运行即可。

:: Copyright (c)2022 https://bookfere.com

:: This is a batch script for fixing Google Translate and making it available

:: in the Chinese mainland. If you experience any problem, visit the page below:

:: https://bookfere.com/post/1020.html

@echo off

setlocal enabledelayedexpansion

chcp 437 >NULL

set "source_domain=google.cn"

set "target_domain=translate.googleapis.com"

set "hosts_file=C:WindowsSystem32driversetchosts"

for /f "skip=4 tokens=2" %%a in ('"nslookup %source_domain% 2>NUL"') do set ip=%%a

set "old_rule=null"

set "new_rule=%ip% %target_domain%"

set "comment=# Fix Google Translate CN"

for /f "tokens=*" %%i in ('type %hosts_file%') do (

set "line=%%i"

:: Retrieve the rule If the target domain exists.

if not "!line:%target_domain%=!"=="%%i" set "old_rule=%%i"

)

if not "%old_rule%"=="null" (

echo A rule has been added to the hosts file.

echo [1] Update [2] Delete

set /p action="Enter a number to choose an action: "

if "!action!"=="1" (

if not "%old_rule%"=="%new_rule%" (

echo Deleting the rule "%old_rule%"

echo Adding the rule "%new_rule%"

set "new_line=false"

for /f "tokens=*" %%i in ('type %hosts_file% ^| find /v /n "" ^& break ^> %hosts_file%') do (

set "rule=%%i"

set "rule=!rule:*]=!"

if "%old_rule%"=="!rule!" set "rule=%new_rule%"

if "!new_line!"=="true" >>%hosts_file% echo.

>>%hosts_file% <NUL set /p="!rule!"

set "new_line=true"

)

) else (

echo The rule already exists, nothing to do.

)

)

if "!action!"=="2" (

echo Deleting the rule "%old_rule%"

set "new_line=false"

for /f "tokens=*" %%i in ('

type "%hosts_file%" ^| findstr /v /c:"%comment%" ^| findstr /v "%target_domain%" ^| find /v /n "" ^& break ^> "%hosts_file%"

') do (

set "line=%%i"

set "line=!line:*]=!"

if "!new_line!"=="true" >>%hosts_file% echo.

>>%hosts_file% <NUL set /p="!line!"

set "new_line=true"

)

)

) else (

echo Adding the rule "%new_rule%"

echo.>>%hosts_file%

echo %comment%>>%hosts_file%

<NUL set /p="%new_rule%">>%hosts_file%

)

echo Done.

pause


如果这里拷贝代码无法使用,可以直接到脚本托管网站下载。

https://gist.github.com/bookfere/c9baf1d03d6f488c7033effbd541e628

展开阅读全文

页面更新:2024-04-23

标签:中国   脚本   管理员   身份   代码   文件   地区   工具   网站

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top