为Firefox添加一个简单的Bing屏幕取词翻译
Firefox中真的不缺少翻译类的addons,但你是否觉得他们太强大了,反而不便于平时的利用.我们需要的只是一个选中取词翻译.在chrome里面已经有google dictionary,现在我们给firefox也安装一个.
介绍两个方法:
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运行// 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要求,一些说明如下: