Skip to content

Instantly share code, notes, and snippets.

@Griever
Created April 13, 2009 14:08
Show Gist options
  • Save Griever/94460 to your computer and use it in GitHub Desktop.
Save Griever/94460 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name goToUpperDirectory.uc.js
// @namespace http://d.hatena.ne.jp/Griever/
// @include main
// @version 0.0.2
// ==/UserScript==
var upperDirectory = {
about : ['about:', 'about:blank', 'about:buildconfig', 'about:cache', 'about:cache?device=memory',
'about:cache?device=disk', 'about:config', 'about:crashes', 'about:credits', 'about:mozilla',
'about:licence', 'about:logo', 'about:plugins', 'about:robots'],
init : function(){
this.identityBox = document.getElementById('identity-box');
this.popup = document.createElement('menupopup');
this.popup.id = 'upperDirectoryPopup';
this.popup.setAttribute('onpopupshowing', "upperDirectory.createMenuitem();");
this.popup.setAttribute('onpopuphidden', "var c; while(c = this.firstChild){ this.removeChild(c) }");
document.getElementById('mainPopupSet').appendChild(this.popup);
this.identityBox.addEventListener('click', this, false);
},
uninit: function(){
this.identityBox.removeEventListener('click', this, false);
},
handleEvent : function(event){
if (event.button == 2){
event.preventDefault();
event.stopPropagation();
this.popup.openPopup(this.identityBox, 'after_start');
}
},
createMenuitem : function(urls){
if (!urls)
urls = this.createURL();
var s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var l = s.length;
urls.forEach(function(url, index){
var menuitem = document.createElement('menuitem');
menuitem.setAttribute("label", url);
menuitem.setAttribute("accesskey", s[index % l]);
menuitem.setAttribute("acceltext", s[index % l]);
menuitem.setAttribute("oncommand", "openUILink(this.label, event)");
menuitem.setAttribute("onclick", "checkForMiddleClick(this, event)");
this.popup.appendChild(menuitem);
},this);
},
createURL : function(){
var prePath = gBrowser.currentURI.prePath;
if (prePath == 'about:')
return this.about;
var path = gBrowser.currentURI.path;
var h = [];
var p = path.indexOf('#');
if (p > 0){
path = path.substr(0, p);
h.push(prePath + path);
}
while(path){
p = path.substr(-1) == '/'? path.lastIndexOf('/', path.length-2) : path.lastIndexOf('/');
path = path.substr(0, p);
h.push(prePath + path + '/');
}
return h;
}
}
upperDirectory.init();
window.addEventListener('unload', function(){
upperDirectory.uninit();
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment