Skip to content

Instantly share code, notes, and snippets.

@yume-chan
Created March 24, 2012 02:39
Show Gist options
  • Save yume-chan/2177706 to your computer and use it in GitHub Desktop.
Save yume-chan/2177706 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name AHUB
// @author simon
// @desc auto hide your url-bar
// @compatibility Fx4+
// @include chrome://browser/content/browser.xul
// ==/UserScript==
var navbar = document.getElementById('nav-bar');
navbar.style.position = 'fixed';
navbar.style.left = '30px';
navbar.style.width = '400px';
navbar.style.minHeight = '35px';
navbar.style.height = '35px';
navbar.style.MozTransition = 'opacity 0.2s ease';
var urlbar = document.getElementById('urlbar');
urlbar.style.width = '380px';
var locationTimeoutHandle = { value: -1 };
var hideTimeoutHandle = { value: -1 };
function hide(timeoutId, url) {
url = url || urlbar.value;
if (navbar.style.display != 'none' &&
url != 'about:home' &&
url != 'about:newtab' &&
url != 'about:blank' &&
url != '') {
console.log(url);
navbar.style.opacity = '0';
safeTimeout(hideTimeoutHandle, function () { navbar.style.display = 'none'; }, 200);
}
}
function show() {
safeTimeout(locationTimeoutHandle);
safeTimeout(hideTimeoutHandle);
navbar.style.left = (gBrowser.mCurrentTab.boxObject.x - 50).toString() + 'px';
navbar.style.display = '-moz-box';
navbar.style.opacity = '1';
if (!urlbar.focused)
urlbar.focus();
}
var urlBarListener = {
QueryInterface: function (aIID) {
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
aIID.equals(Components.interfaces.nsIWebProgressListener2) ||
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
},
onLocationChange: function (aWebProgress, aRequest, aURI) {
show();
safeTimeout(locationTimeoutHandle, function () { hide(null, aURI.spec) }, 1500);
},
onStateChange: function (a, b, c, d) { },
onProgressChange: function (a, b, c, d, e, f) { },
onStatusChange: function (a, b, c, d) { },
onSecurityChange: function (a, b, c) { }
};
gBrowser.addProgressListener(urlBarListener);
window.addEventListener('mousedown', function (e) {
if (e.target.className == 'tabbrowser-tab') {
if (e.button == 0)
show();
}
else {
var temp = e.target;
while (temp && temp.id != 'main-window') {
if (temp.id == 'nav-bar') {
show();
return;
}
else
temp = temp.parentNode;
}
hide();
}
}, true);
/*
window.addEventListener('mousedown', function (e) {
console.log('========= Output Start ===========');
console.log('e.button = ' + e.button.toString());
var temp = e.target;
while (temp && temp.id != 'main-window') {
console.log('id: ' + temp.id);
temp = temp.parentNode;
}
console.log('========= Output Done ===========');
}, true);
*/
gBrowser.tabContainer.addEventListener('TabClose', function (e) {
setTimeout(function () {
console.info((gBrowser.selectedTab.boxObject.x - 50).toString());
navbar.style.left = (gBrowser.selectedTab.boxObject.x - 50).toString() + 'px';
}, 1);
}, true);
function safeTimeout(handle, expression, timeout) {
if (handle.value != -1) {
clearTimeout(handle.value);
handle.value = -1;
}
if (timeout)
handle.value = setTimeout(expression, timeout);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment