感谢
首先,感谢QQ的书签和下载,我是从那两个Addons里面学习了很多代码,是我能够快速开发这个出来。
背景
昨天发布了基于IE右键的在线代理,http://www.cleocn.com/?p=343001
为了方便使用Firefox的用户,开发了这个插件
功能
右键菜单,将用户选择的文本或链接发送到在线代理服务网站。实现快速方便访问。
当然你也可以直接收藏该网站:http://www.hole-on-the-wall.info
下载
https://addons.mozilla.org/en-US/firefox/addon/247541 (刚刚提交,目前可能还无法访问,还在Public Nomination状态)
效果
主要代码
function GetText() {
var focusedWindow = document.commandDispatcher.focusedWindow;
var winWrapper = new XPCNativeWrapper(focusedWindow, 'getSelection()');
var searchStr = winWrapper.getSelection().toString();
return searchStr;
}
function GetLink(){
if (!gContextMenu.onLink && !gContextMenu.onImage)
{
return "";
}
var strUrl = "";
if (gContextMenu.onLink && (-1 == gContextMenu.link.toString().indexOf("javascript:")))
{
strUrl = gContextMenu.link.toString();
}
else
{
strUrl = gContextMenu.target.src;
}
return strUrl;
}var hongxingextension = {
onLoad: function() {
// initialization code
this.initialized = true;
this.strings = document.getElementById("hongxingextension-strings");
},onMenuItemCommand: function(e) {
gtext = GetText();
glink = GetLink();
q = '';
if (glink!='' ){
q= glink;
}else if (gtext!=''){
q= gtext;
}
var browser = document.getElementById('content');
var content ='q='+ encodeURIComponent( q) ;//+ encodeURIComponent(q);
var referrer = null;
var postData = Components.classes['@mozilla.org/io/string-input-stream;1'].createInstance(Components.interfaces.nsIStringInputStream);
content = 'Content-Type: application/x-www-form-urlencoded\n'+
'Content-Length: '+content.length+'\n\n'+
content;
postData.setData(content, content.length);
var flags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
ProxyUrl = 'http://www.hole-on-the-wall.info/';
var tab = browser.addTab(ProxyUrl);
browser.selectedTab = tab;
browser.loadURIWithFlags(ProxyUrl, flags, referrer, null, postData);
},onToolbarButtonCommand: function(e) {
// just reuse the function above. you can change this, obviously!
hongxingextension.onMenuItemCommand(e);
}
};window.addEventListener("load", hongxingextension.onLoad, false);
--
Posted By GFW BLOG 功夫网 to GFW BLOG at 11/04/2010 09:58:00 PM --
1、我们的订阅地址:http://feeds2.feedburner.com/chinagfwblog。2、发一封标题为GFW的邮件到fanqiang70ma@gmail.com,就可获取翻墙利器赛风新地址。附《数字时代》赠阅版。3、本站热烈欢迎各位朋友投稿或推荐文章,请发邮件至chinagfwblog[at]gmail.com。
停止订阅,请发邮件到
gfw-blog+unsubscribe@googlegroups.com
没有评论:
发表评论