不小心就花了2天时间在firefox上,耽搁了正事,懊恼不已啊。
话说是因为前2天在浏览网页时,看到了stylish,忍不住就想用用,于是就搜一些推荐的样式时又看到了userchrome.js,于是这2天时间就耗在了这2个东西和之后不得不用的dom inspector上。和以前搞greasemonkey一样,觉得那些脚本不合自己习惯,就自己写。而写了之后又不满意,像greasemonkey,我干脆卸了,再也不用。其实,总觉得这些东西实际上没什么用,徒增自己烦恼而已。
在网上没搜到合用的隐藏工具栏的脚本,于是就写了一个。我不用隐藏菜单栏,因为我用personal menu了,我也不隐藏导航栏,因为太常用了,我要隐藏的是收藏栏和google工具栏,另外我不想在点导航栏时,收藏栏和google工具栏跳出来,弄得眼花潦乱,所以我就用了alt键控制。写个userchrome.js真烦啊,写了之后都不知为什么不起作用,看来看去,头都晕了。好像firebug不能调试userchrome.js?
var hide = {
toolbar : document.getElementById("navigator-toolbox"),
bookmarks : document.getElementById("PersonalToolbar"),
googleBar : document.getElementById("gtbToolbar"),
hideTimer : null,
isCtrl : false,//记录按一下一次ctrl
isOver : false,//是否鼠标指到工具栏上
init : function() {
hide.bookmarks.style.display = 'none';
hide.googleBar.style.display = 'none';
// 按下alt或ctrl
window.addEventListener("keydown", function(event) {
if (event.keyCode == 18 && !event.ctrlKey)
hide.toolbar.altKey = true;//toolbar.altKey控制鼠标指到工具栏时显示收藏栏和google toolbar栏。
if (((event.keyCode == 18 && event.ctrlKey) || (event.keyCode == 17 && event.altKey))
&& hide.isOver)
{
hide.toolbar.altKey = true;
if (hide.isCtrl)
hide.isCtrl = false;
else
hide.isCtrl = true;
}
}, false);
// 释放alt
/*
window.addEventListener("keyup", function(event) {
if (event.keyCode == 18 || event.keyCode == 17 || event.altKey || event.ctrlKey)
toolbar.altKey = false;
}, false);
*/
hide.toolbar.addEventListener("mouseover", function(event) {
hide.isOver = true;
clearTimeout(hide.hideTimer);
if (!hide.toolbar.altKey)
return;
hide.toolbar.altKey = false;
setTimeout( function() {
hide.bookmarks.style.display = 'block';
hide.googleBar.style.display = 'block';
}, 0);
}, false);
hide.toolbar.addEventListener("dblclick", function(event) {
clearTimeout(hide.hideTimer);
setTimeout( function() {
hide.bookmarks.style.display = 'block';
hide.googleBar.style.display = 'block';
}, 500);
}, false);
hide.toolbar.addEventListener("mouseout", function(event) {
hide.isOver = false;
hide.hideTimer = setTimeout( function() {
if (!hide.isCtrl) {
hide.bookmarks.style.display = 'none';
hide.googleBar.style.display = 'none';
}
}, 200);
}, false);
}// end init function
};
hide.init();
也不知有什么bug,效率怎样,希望不会用几天就卸了吧。
作者在Firefox浏览器上花费两天时间尝试使用Stylish和UserChrome.js来自定义浏览器界面,包括隐藏工具栏等,并分享了自己编写UserChrome.js脚本的经验。

583

被折叠的 条评论
为什么被折叠?



