Skip to content

Instantly share code, notes, and snippets.

@xulapp
Created March 3, 2010 23:49
Show Gist options
  • Save xulapp/321205 to your computer and use it in GitHub Desktop.
Save xulapp/321205 to your computer and use it in GitHub Desktop.
moreToolsMenu.uc.js
// ==UserScript==
// @name moreToolsMenu.uc.js
// @description adds moreTools-menu to menubar
// @include main
// @compatibility Firefox
// @namespace http://twitter.com/xulapp
// @author xulapp
// @license MIT License
// @version 2011/04/03 15:30 +09:00
// ==/UserScript==
// @version 2010/07/26 22:00 +09:00
// @version 2010/03/04 08:00 +09:00
(function() {
const XUL_NS = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
var toolsPopup = $('menu_ToolsPopup');
var menu = $E(<menu id="moreTools-menu" label={U('追加ツール')} accesskey="m"/>);
var popup = $E(<menupopup id="menu_MoreToolsPopup"/>);
$A(toolsPopup.childNodes).forEach(absorb);
$W('popupshowing popupshown popuphiding popuphidden').forEach(function(type) {
popup.addEventListener(type, MTM_forwardEvent, true);
});
menu.appendChild(popup);
$('main-menubar').insertBefore(menu, $('tools-menu').nextSibling);
toolsPopup.addEventListener('DOMNodeInserted', function MTM_onDOMNodeInserted(event) {
var target = event.originalTarget;
if (target.parentNode === this)
absorb(target);
}, false);
function U(text) 1 < 'あ'.length ? decodeURIComponent(escape(text)) : text;
function $A(arr) Array.slice(arr);
function $W(str) str.split(' ');
function $(id) document.getElementById(id);
function $E(xml, doc) {
doc = doc || document;
xml = <root xmlns={doc.documentElement.namespaceURI}>{xml}</root>;
var pp = XML.prettyPrinting;
XML.prettyPrinting = false;
var root = new DOMParser().parseFromString(xml.toXMLString(), 'application/xml').documentElement;
XML.prettyPrinting = pp;
doc.adoptNode(root);
var range = doc.createRange();
range.selectNodeContents(root);
var frag = range.extractContents();
range.detach();
return frag.childNodes.length < 2 ? frag.firstChild : frag;
}
function isMoreTools(item) {
switch (item.getAttribute('id')) {
case 'menu_search':
case 'browserToolsSeparator':
case 'menu_openDownloads':
case 'menu_openAddons':
case 'sync-setup':
case 'sync-syncnowitem':
case 'devToolsSeparator':
case 'javascriptConsole':
case 'webConsole':
case 'menu_pageInfo':
case 'sanitizeSeparator':
case 'privateBrowsingItem':
case 'sanitizeItem':
case 'prefSep':
case 'menu_preferences':
return false;
}
return true;
}
function absorb(item) {
if (!isMoreTools(item)) return;
if (item.localName === 'menuseparator') {
setTimeout(function() document.adoptNode(item), 0);
return;
}
var itemLabel = item.getAttribute('label').toLowerCase();
var nodes = $A(popup.children);
for (var index = 0, len = nodes.length; index < len; index++) {
if (itemLabel < nodes[index].getAttribute('label').toLowerCase()) break;
}
popup.insertBefore(item, nodes[index]);
}
function MTM_forwardEvent({type}) {
var _event = document.createEvent('PopupEvents');
_event.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
toolsPopup.dispatchEvent(_event);
}
})();
@Endor8
Copy link

Endor8 commented Feb 20, 2013

Hi. Please update this Script for Firefox 20. There is necessary to remove e4x.
This is never supported since Firefox 20. Thank you for this great script.
Cheers
Endor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment