|
阅读:2927回复:3
关于创建Google Notebook脚本的问题
俺一直用下面的GoogleNotebook.uc.js脚本摘取页面内容创建Google Notebook,但最近升级FF到4.0b12pre后脚本用起来有点不灵光了,弹出的Google Notebook小窗口不能改变大小,点击关闭和全页面显示都不行了,哪位脚本达人能给看看是哪里出问题了吗?
// ==UserScript==
// Google Notebook Light by userChrome.js (available in context menu) / Version 1.0.4
// @description 页面右键菜单添加Google Notebook
// ==/UserScript==
(function()
{
var gnurl = 'http://www.google.com/notebook/onpage?client=gnotesff&v=1.0.0.20';
var gnbox_id = 'gnotes-byucjs-box', gnfrm_id = 'gnotes-byucjs-frm';
function $(id){
return document.getElementById(id);
}
function getWindow(){
var win = document.commandDispatcher.focusedWindow;
if(!win || win == window || win._GN_interface || (win.wrappedJSObject && win.wrappedJSObject._GN_interface) || win.document.URL.indexOf(gnurl) == 0)
return window.content;
else
return win;
}
function getGNInterface(){
var gnfrm = $(gnfrm_id);
try{ return gnfrm.contentWindow._GN_interface || gnfrm.contentWindow.wrappedJSObject._GN_interface; }
catch(e){ return null; }
}
window.gnotes_byucjs_reserve = {
_flag: false, _sel: null, _ctxt: null,
setData: function(sel, ctxt){ this._sel = sel; this._ctxt = ctxt; this._flag = true; },
getData: function(){ if(!this._flag) return null; this._flag = false; return { sel: this._sel, ctxt: this._ctxt }; }
};
window.gnotes_byucjs_context_add = function(event){
var encodeEntity = function(url){
return url.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/&(?!([a-z]+|#[0-9]+|#x[0-9a-f]+);)/gi, "&");
}
var getContent = function(sel, ctxt){
var content = null, re = /^\s+|\s+$/g;
try{
if(!sel) sel = getWindow().getSelection();
if(sel && sel.rangeCount > 0){
var range = sel.getRangeAt(sel.rangeCount - 1);
if(!/^(\s*)$/.test(sel.toString()) && sel.toString().replace(re, '').length > 1) content = range.cloneRange();
else{
var ca = range.commonAncestorContainer;
if(ca && ca.getElementsByTagName){
var imgs = ca.getElementsByTagName('IMG');
for(var i in imgs) if(range.compareNode(imgs[i]) == range.NODE_INSIDE){ content = range.cloneRange(); break; }
}
}
if(content){
var div = gnfrm.contentDocument.createElement('div');
div.appendChild(content.cloneContents());
content = div.innerHTML.replace(re, '');
}
}
if(!content && ctxt){
if(ctxt.onImage){
var img = ctxt.target, size = "";
if(img.height > 150 || img.width > 150) size = img.height > img.width ? ' height="150"' : ' width="150"';
content = '<img src="' + encodeEntity(img.src) + '"' + size + ' />';
}
else if(ctxt.onLink){
content = '<a href="' + encodeEntity(ctxt.linkURL) + '">' + encodeEntity(ctxt.linkText()) + '</a>';
}
}
}
catch(e){}
var title = getWindow().document.title.replace(re, ''), url = getWindow().document.URL;
if(url.indexOf('file:') == 0) url = 'http://localhost/';
if(url.indexOf('bbs2ch:') == 0) url = url.substring(url.indexOf('http:'));
return { _content: content, _title: title, _url: url };
}
var addNote = function(data, wait){
if(!data) return;
var gnif = getGNInterface(), content = getContent(data.sel, data.ctxt);
if(gnif && content) window.setTimeout(function(){ gnif._addNote(content._content, content._url, content._title, null, 'ctxt'); }, wait);
}
try{
var gnbox = $(gnbox_id), gnfrm = $(gnfrm_id), first = !Boolean(gnbox);
if(event) window.gnotes_byucjs_reserve.setData(getWindow().getSelection(), gContextMenu);
if(first){
gnbox = document.createElement('vbox'); gnbox.id = gnbox_id; gnbox.pack = 'center'; gnbox.style.display = 'block';
gnfrm = document.createElement('browser'); gnfrm.id = gnfrm_id; gnfrm.setAttribute('type', 'content');
}
with(gnbox.style){
position='fixed';top=$('content')._browsers[0].boxObject.y+'px';right='20px';width='356px';height='201px';zIndex='9999';
}
with(gnfrm.style){ width='100%';height='100%'; }
if(first){
gnfrm.addEventListener('load', function(){
try{
var gnif = getGNInterface();
if(gnif){
gnif._setResizeHandler(function(w,h){ with(gnbox.style){ width=w+'px';height=h+'px'; } });
gnif._setCloseHandler(function(){ gnbox.style.display = 'none'; });
gnif._setGetCurrentPageHandler(function(){ return getContent(); });
gnif._setMaximizeHandler(function(u){ var t = gBrowser.addTab(u); gnif._tryClose(); gBrowser.selectedTab = t; });
gnif._setOpenHandler(function(u,w){ window._content.document.location.href = u; });
addNote(window.gnotes_byucjs_reserve.getData(), 250);
}
}
catch(e){ alert(e); }
}, true);
gnfrm.setAttribute('src', gnurl); gnbox.appendChild(gnfrm); $('main-window').appendChild(gnbox);
}
else if(gnbox.style.display == 'none'){
gnbox.style.display = 'block';
if("PlacesUtils" in window) addNote(window.gnotes_byucjs_reserve.getData(), 250);
}
else{
addNote(window.gnotes_byucjs_reserve.getData(), 1);
}
}
catch(e){ alert(e); }
};
window.gnotes_byucjs_on_tab_select = function(){
var gnif = getGNInterface(); if(gnif) gnif._tryClose();
};
window.gnotes_byucjs_on_resize = function(){
var gnbox = $(gnbox_id), bws = $('content')._browsers;
if(gnbox && bws){ gnbox.style.top = bws[0].boxObject.y + 'px'; }
};
try{
var menu_gnotes = {
id: 'context-gnotes-byucjs-add'
,label: decodeURI('\uFEFF\u521B\u5EFA\u7B14\u8BB0\u672C(GoogleNotebook) ')
,accesskey: 'b'
,oncommand: 'gnotes_byucjs_context_add(event)'
};
if($(menu_gnotes.id)) return;
var menuitem = document.createElement('menuitem');
for(var attr in menu_gnotes) menuitem.setAttribute(attr, menu_gnotes[attr]);
var menusep = document.createElement('menuseparator');
menusep.id = 'context-sep-gnotes-byucjs';
var cmenu = $('contentAreaContextMenu');
cmenu.insertBefore(menusep, cmenu.firstChild);
cmenu.insertBefore(menuitem, cmenu.firstChild);
$('content').mTabBox.addEventListener('select', gnotes_byucjs_on_tab_select, true);
$('content').addEventListener('resize', window.gnotes_byucjs_on_resize, true);
}
catch(e){}
})(); |
|
|
1楼#
发布于:2011-02-11 11:52
这个服务google停了还挺可惜的
|
|
|
|
2楼#
发布于:2011-02-11 11:52
4.0遇到同样的问题,这个uc脚本的作者貌似是个日本人?不知道会不会更新。
|
|
|
|
3楼#
发布于:2011-02-11 11:52
我也在找
|
|