js_translate

6/8/2023, 2:23:49 PM

08.06.2023 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        js_translate
// @namespace   Violentmonkey Scripts
// @match       *://*/*
// @grant       none
// @version     0.1.0
// @author      liudonghua123
// @license     MIT
// @description 6/8/2023, 2:23:49 PM
// ==/UserScript==

// https://www.oschina.net/news/244182/leiming-2-3-released

/*
<script src="https://res.zvo.cn/translate/translate.js"></script>
<script>
translate.setUseVersion2(); //设置使用v2.x 版本
translate.language.setLocal('chinese_simplified'); //设置本地语种(当前网页的语种)。如果不设置,默认就是 'chinese_simplified' 简体中文。 可填写如 'english'、'chinese_simplified' 等,具体参见文档下方关于此的说明。
translate.execute();//进行翻译
</script>
*/

// https://stackoverflow.com/questions/5132488/how-can-i-insert-a-script-into-html-head-dynamically-using-javascript

const dynamicAddScript = (url) => {
    return new Promise(function(resolve, reject){
      const script = document.createElement('script');
      script.onload = resolve;
      script.onerror = reject;
      script.src = url;
      document.head.appendChild(script);
    });
}

function sleep(time){
   return new Promise(function(resolve){
     setTimeout(resolve, time);
   });
}


(async function process() {
  console.info(`loading translate.js ...`)
  await dynamicAddScript('https://res.zvo.cn/translate/translate.js');
  console.info(`loaded translate.js`)
  // TODO: detect the language of current page, only apply translating to non-chinese_simplified webpage
  translate.setUseVersion2(); //设置使用v2.x 版本
  translate.language.setLocal('chinese_simplified'); //设置本地语种(当前网页的语种)。如果不设置,默认就是 'chinese_simplified' 简体中文。 可填写如 'english'、'chinese_simplified' 等,具体参见文档下方关于此的说明。
  translate.execute();//进行翻译
})();