微软翻译组件

微软翻译组件 右下角点击翻译

当前为 2017-02-19 提交的版本,查看 最新版本

// ==UserScript==
// @name 微软翻译组件
// @description 微软翻译组件  右下角点击翻译
// @include     *
// @exclude     *.jpg
// @exclude     *.png
// @exclude     *.jpeg
// @exclude     *.gif
// @exclude     *.pdf
// @require  	http://code.jquery.com/jquery-1.11.3.min.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.3/js.cookie.min.js
// @grant       aogg
// @version 2.1.1
// @namespace https://gf.qytechs.cn/users/25818
// ==/UserScript==


// 重置cookie
console.log('remove cookie mstto');
Cookies.remove('mstto');

var locals = ''; // zh-chs
var status = false;

var scriptNode = document.createElement('script');
scriptNode.innerHTML = "setTimeout(function(){{var s=document.createElement('script');s.type='text/javascript';s.charset='UTF-8';s.src=((location && location.href && location.href.indexOf('https') == 0)?'https://ssl.microsofttranslator.com':'http://www.microsofttranslator.com')+'/ajax/v3/WidgetV3.ashx?siteData=ueOIGRSKkd965FeEGM5JtQ**&ctf=False&ui=false&settings=Manual&from=';var p=document.getElementsByTagName('head')[0]||document.documentElement;p.insertBefore(s,p.firstChild); }},0);"
document.body.appendChild(scriptNode);

var divNode = document.createElement('div');
divNode.id = 'MicrosoftTranslatorWidget';
divNode.style.color = 'white';
divNode.style.backgroundColor = '#555555';
divNode.style.position = 'fixed';
divNode.style.right = '0';
divNode.style.bottom = '0';
//divNode.setAttribute('style', 'color:white;background-color:#555555;position: fixed;right: 0;bottom: 0;');
document.body.appendChild(divNode);


document.onreadystatechange = function () {
  if (document.readyState == 'complete') {
    var selectHtml = document.createElement('select');
    selectHtml.onchange = function(){
      locals = this.value;
      translateStart();
    };
    // Microsoft.Translator.Widget.GetLanguagesForTranslateLocalized()获取所有支持的翻译选项
    selectHtml.innerHTML = "\
    <option value=''>请选择</option>\
    <option value='zh-chs'>简体中文</option>\
    <option value='zh-cht'>繁体中文</option>\
    <option value='yue'>粤语</option>\
    <option value='ja'>日文</option>\
    <option value='en'>英文</option>\
";
    document.getElementById('MicrosoftTranslatorWidget').appendChild(selectHtml);
    
    
    status = true;
    translateStart();
  }
}

function translateStart(){
  if (status && locals){
    // null, 'es', onProgress, onError, onComplete, onRestoreOriginal, 2000
    Microsoft.Translator.Widget.Translate(null, locals);
  }
}

	
function addGlobalStyle(css) {
	var head, style;
	head = document.getElementsByTagName('head')[0];
	if (!head) { return; }
	style = document.createElement('style');
	style.type = 'text/css';
	style.innerHTML = css;
	head.appendChild(style);
}
	
	
console.log('完成');


QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址