Google Translate Auto Languages

Auto switch Chinese/English

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Google Translate Auto Languages
// @name:zh-CN  Google谷歌翻译自动中英互译
// @description Auto switch Chinese/English
// @description:zh-CN 自动切换目标语言为中/英文
// @namespace   https://greasyfork.org/users/197529
// @version     1.6
// @author      kkocdko
// @license     Unlicense
// @match       *://translate.google.com/*
// @match       *://translate.google.cn/*
// @noframes
// ==/UserScript==
"use strict";

const firstLangRule = /English|英语/;
const firstLang = "en";
const secondLang = "zh-CN";

const detectTab = document.querySelector("[role=tab]");
new MutationObserver(() => {
  const isFirstLang = firstLangRule.test(detectTab.textContent);
  const lang = isFirstLang ? secondLang : firstLang;
  const selector = `[data-popup-corner]~* [data-language-code=${lang}]`;
  const tab = document.querySelector(selector);
  if (tab.getAttribute("aria-selected") !== "true") tab.click();
}).observe(detectTab, { characterData: true, subtree: true });
if (detectTab.getAttribute("aria-selected") !== "true") detectTab.click();