自动切换输出语言
当前为
// ==UserScript==
// @name Google翻译自动中英互译
// @description 自动切换输出语言
// @namespace https://greasyfork.org/users/197529
// @author kkocdko
// @license Unlicense
// @version 0.4
// @include *://translate.google.cn/*
// ==/UserScript==
'use strict'
replaceUrlHash(/sl=en|sl=zh-CN/, 'sl=auto')
document.querySelector('.sl-selector a').addEventListener('DOMSubtreeModified', function () {
replaceUrlHash(/tl=en|tl=zh-CN/, this.innerText === '检测到英语' ? 'tl=zh-CN' : 'tl=en')
})
function replaceUrlHash (selector, replaceValue) {
window.location.hash = window.location.hash.replace(selector, replaceValue)
}