Skip to content

Commit

Permalink
添加必应网页翻译
Browse files Browse the repository at this point in the history
  • Loading branch information
lmk123 committed Jan 27, 2016
1 parent 769b510 commit eb363d2
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/content-scripts/web.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* istanbul ignore next */
/**
* 网页翻译集合。
* 网页翻译的原理大多是在当前网页中插入一段 js 脚本,所以不需要单元测试
Expand All @@ -8,6 +7,7 @@
* 有道网页翻译。注意:它不支持 https 网站
* @see http://fanyi.youdao.com/web2/
*/
/* istanbul ignore next */
export function youdao() {
if ( 'https:' === location.protocol ) {
return alert( '有道网页翻译不支持 https 网站。' );
Expand All @@ -19,3 +19,30 @@ export function youdao() {
element.src = 'http://fanyi.youdao.com/web2/seed.js?' + Date.parse( new Date() );
document.body.appendChild( element );
}

/**
* 必应翻译窗口小部件
* @see http://www.bing.com/widget/translator
*/
/* istanbul ignore next */
export function bing() {
const alreadyHasBing = document.getElementById( 'TranslateSpan' );
if ( alreadyHasBing ) {
alreadyHasBing.click();
return;
}

const msw = document.createElement( 'div' );
msw.id = 'MicrosoftTranslatorWidget';
msw.classList.add( 'Dark' );
msw.style.cssText = 'color:white;background-color:#555555;position:fixed;top:-99999px;';
document.body.appendChild( msw );

setTimeout( function () {
var s = document.createElement( 'script' );
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=True&ui=true&settings=Auto&from=';
var p = document.getElementsByTagName( 'head' )[ 0 ] || document.documentElement;
p.insertBefore( s , p.firstChild );
} , 0 );
}

0 comments on commit eb363d2

Please sign in to comment.