Ticket #140: moretools.2.js

File moretools.2.js, 2.0 KB (added by morac99-firefox@…, 18 months ago)

Fixed so menu items after the "Options" entry are moved as well. (replaces first attachment)

Line 
1(function() {
2
3// duplicate original window (drastic, but anything else either prevents node insertion or throws an exception)
4var originalWindow = document.lastChild.cloneNode(true);
5
6function mungeMenus(event) {
7    window.removeEventListener('DOMContentLoaded', mungeMenus, true);
8
9    var toolsMenu=
10        document.getElementById('menu_ToolsPopup') || // firefox
11        document.getElementById('taskPopup') ;        // thunderbird
12
13    var moreToolsMenu=document.getElementById('more-tools-menupopup');
14
15    // Find the original tools menu popup
16    var originalMenuPopups = originalWindow.getElementsByTagName("menupopup");
17    var originalToolsMenu=null;
18    for (i=0; i<originalMenuPopups.length; i++) {
19        if (originalMenuPopups[i].id == "menu_ToolsPopup" || // firefox
20            originalMenuPopups[i].id == "taskPopup") {       // thunderbird
21            originalToolsMenu = originalMenuPopups[i];
22        }
23    }
24    originalMenuPopups = null;
25       
26    var mungeFlag=false;
27   
28    // function to move menu item from tools menu to more tools menu
29    var moveElem = function(el) {
30        toolsMenu.removeChild(el);
31        moreToolsMenu.appendChild(el);
32       
33        mungeFlag=true;
34    }
35   
36    // loop through the original menu toolbar and the current menu toolbar.  Move anything
37    // that's in the current one that wasn't there originally
38    var i=0;
39    for (j=0; j<originalToolsMenu.childNodes.length; j++) {
40        while ((originalToolsMenu.childNodes[j].id != toolsMenu.childNodes[i].id) &&
41                 (originalToolsMenu.childNodes[j].id != toolsMenu.childNodes[i].id)) {
42       
43            moveElem(toolsMenu.childNodes[i]);
44        }
45        i++;
46    }
47   
48    // Move remaining menu items from tools menu
49    while (i < toolsMenu.childNodes.length) {
50        moveElem(toolsMenu.childNodes[i]);
51    }       
52   
53    // don't need cloned window any more so get rid of it
54    originalToolsMenu = null;
55    originalWindow = null;
56
57    if (mungeFlag) {
58        // we did munge something into this menu; remove the label and separator
59        document.getElementById('more-tools-label').setAttribute('hidden', true);
60        document.getElementById('more-tools-sep').setAttribute('hidden', true);
61    }
62}
63
64
65window.addEventListener('DOMContentLoaded', mungeMenus, true);
66
67
68})();