旧版: v0.6 - 2019-08-05 - 1. 修复了各种奇怪的Bug 2. 精简代码
新版: v0.7 - 2019-08-09 - 匹配各国的Google Translate域名
- @@ -1,11 +1,11 @@
- // ==UserScript==
-// @name Google翻译自动中英互译
- +// @name Google谷歌翻译自动中英互译
- // @description 自动切换输出语言
- // @namespace https://greasyfork.org/users/197529
- // @author kkocdko
- // @license Unlicense
-// @version 0.6
-// @include *://translate.google.cn/*
- +// @version 0.7
- +// @match *://translate.google.*/*
- // ==/UserScript==
- 'use strict'
-
- @@ -20,10 +20,10 @@
- return
- }
- const isEnglish = sourceLangEl.textContent === '检测到英语'
- const rightValue = isEnglish ? 'tl=zh-CN' : 'tl=en'
- const leftValue = isEnglish ? 'tl=en' : 'tl=zh-CN'
- if (window.location.hash.indexOf(rightValue)) {
- window.location.hash = window.location.hash.replace(rightValue, leftValue)
- + const targetValue = isEnglish ? 'tl=zh-CN' : 'tl=en'
- + const sourceValue = isEnglish ? 'tl=en' : 'tl=zh-CN'
- + if (window.location.hash.indexOf(targetValue)) {
- + window.location.hash = window.location.hash.replace(targetValue, sourceValue)
- }
- window.location.hash = window.location.hash.replace(leftValue, rightValue)
- + window.location.hash = window.location.hash.replace(sourceValue, targetValue)
- }