为Firefox添加一个简单的Bing屏幕取词翻译
Firefox中真的不缺少翻译类的addons,但你是否觉得他们太强大了,反而不便于平时的利用.我们需要的只是一个选中取词翻译.在chrome里面已经有google dictionary,现在我们给firefox也安装一个.
介绍两个方法:
- 给Firefox添加一个书签
BingTranslator拖动这个书签到你的firefox书签工具栏,当你打开一个网页需要翻译功能的时候,点击此书签即可进行翻译。书签的javascript代码:
javascript:(function(){jsNode=document.createElement('script');jsNode.src='http://dict.bing.com.cn/cloudwidget/Scripts/Generated/BingTranslate_Selection_ShowIcon.js';jsNode.onload=INIT;document.body.appendChild(jsNode);})();function INIT(){BingCW.Init( { AppId: "GM foo" MachineTranslation:true, WebDefinition: true});}让js脚本作为一个addons运行前提:需要安装GreaseMonkey.
然后你可以从这里安装Bing Translator:http://userscripts.org/scripts/show/106048
也可以自己创建一个文件进行安装,新建一个文本文件,命名为bing.user.js
copy以下代码:
// Bing Translator// version 0.1 BETA!// Released under the GPL license// http://www.gnu.org/copyleft/gpl.html//// ????????????????????????????????????????????????????????????????????//// This is a Greasemonkey user script.//// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/// Then restart Firefox and revisit this script.// Under Tools, there will be a new menu item to "Install User Script".// Accept the default configuration and install.//// To uninstall, go to Tools/Manage User Scripts,// select "Hello World", and click Uninstall.//// ????????????????????????????????????????????????????????????????????//// ==UserScript==// @name Bing Translator// @namespace http://feedlover.com// @description Bing Translator// @include *// @exclude// ==/UserScript==//--- Load the library.//--- Load the library.var D = document;var appTarg = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;var jsNode = D.createElement ('script');jsNode.src = 'http://dict.bing.com.cn/cloudwidget/Scripts/Generated/BingTranslate_Selection_ShowIcon.js';jsNode.addEventListener ("load", initBingTranslatorOnDelay, false);appTarg.appendChild (jsNode);//--- Allow some time for the library to initialize after loading.function initBingTranslatorOnDelay () { setTimeout (initBingTranslator, 666);}//--- Call the library's start-up function, if any. Note needed use of unsafeWindow.function initBingTranslator () { unsafeWindow.BingCW.Init ( { AppID: "GM Foo", MachineTranslation: true, WebDefinition: true } );}可以直接将文件drag and drop到Firefox窗口,即可安装。详细的安装方法可以参考GreaseMonkey Manual.
javascript代码是运行在sandbox内,所以必须满足sandbox要求,一些说明如下: