if ( ! this .lastChild ) {
var mc = document .getElementById( "bookmarksMenuPopup" );
var mcc = mc.cloneNode( true );
this .appendChild( mcc );
}
var bo = document .getBoxObjectFor( this );
this .lastChild.showPopup ( this , -1, -1, "popup" , "bottomleft" , "topleft" );
* This source code was highlighted with Source Code Highlighter .
if ( ! this .lastChild ) {
var mc = document .getElementById( "bookmarksMenuPopup" );
var mcc = mc.cloneNode( true );
this .appendChild( mcc );
}
var bo = document .getBoxObjectFor( this );
this .lastChild.showPopup ( this , -1, -1, "popup" , "bottomleft" , "topleft" );
* This source code was highlighted with Source Code Highlighter .
var bo = document.getBoxObjectFor( this );
this.lastChild.showPopup ( this, -1, -1, "popup", "bottomleft", "topleft" );
var mitems = [
{
"label" : "localhost" ,
"tip" : "localhost" ,
"image" : "" ,
"type" : "url" ,
"val" : "localhost"
},
"separator" ,
{
"label" : "Google" ,
"tip" : "Google" ,
"image" : "" ,
"type" : "url" ,
"val" : "http://www.google.ru"
},
"separator" ,
{
"label" : "Notepad" ,
"tip" : "Notepad" ,
"image" : "" ,
"type" : "exec" ,
"val" : "c:/windows/notepad.exe"
},
"separator" ,
{
"label" : "other" ,
"tip" : "other" ,
"image" : "" ,
"type" : "submenu" ,
"val" :
[
{
"label" : "JS test" ,
"tip" : "JS test" ,
"image" : "" ,
"type" : "js" ,
"val" : "alert( 'js testing...' );"
},
{
"label" : " FF" ,
"tip" : " FF" ,
"image" : "" ,
"type" : "js" ,
"val" : "goQuitApplication();"
}
]
}
];
function createMenu( label, tip, image ) {
var m = document .createElement( "menu" );
m.setAttribute( "label" , label );
if ( image ) {
m.setAttribute( "class" , "menu-iconic" );
m.setAttribute( "image" , image );
}
if ( tip ) m.tooltipText = tip;
return m;
}
function createMenuItem( label, tip, image ) {
var mi = document .createElement( "menuitem" );
mi.setAttribute( "label" , label );
if ( image ) {
mi.setAttribute( "class" , "menuitem-iconic" ); // "menuitem-iconic bookmark-item"
mi.setAttribute( "image" , image );
}
if ( tip ) mi.tooltipText = tip;
return mi;
}
function executeFile( progPath, arg ) {
progPath = progPath.replace( /\ //gi, "\\" );
try {
var argArray = arg ? arg.split(/\s+/) : [];
var nsILocalFile = Components.classes[ "@mozilla.org/file/local;1" ].getService(Components.interfaces.nsILocalFile);
var nsIProcess = Components.classes[ "@mozilla.org/process/util;1" ].getService(Components.interfaces.nsIProcess);
nsILocalFile.initWithPath(progPath);
nsIProcess.init(nsILocalFile);
nsIProcess.run( false , argArray, argArray.length);
// nsIProcess.close();
return nsILocalFile;
}
catch ( ex ) {
alert( ex.toString() );
return null ;
}
}
function buildMenu( items ) {
var menu, i, t, mi, item;
var self = this ;
menu = document .createElement( "menupopup" );
menu.type = "menu" ;
menu.orient = "horizontal" ;
// menu.id = "myCustomMenu";
for ( i in items ) {
item = items[i];
if ( typeof ( item ) == "string" ) {
switch ( item ) {
case "separator" :
mi = document .createElement( "menuseparator" );
break ;
default :
mi = null ;
break ;
}
}
else {
switch ( item.type ) {
case "url" :
mi = createMenuItem( item.label, item.tip, item.image );
mi.onclick = function () {
var b = getBrowser();
b.selectedTab = b.addTab( this .onclick.addr );
b.selectedTab.onload = function () {}
};
mi.onclick.addr = item.val;
break ;
case "urlForm" :
mi = createMenuItem( item.label, item.tip, item.image );
mi.onclick = function () {
var item = this .onclick.item;
var b = getBrowser();
var tab = gBrowser.addTab( item.val.addr );
var newTabBrowser = b.getBrowserForTab( tab );
b.selectedTab = tab;
var lf = function ( event ) {
var fields = item.val.fields;
newTabBrowser.removeEventListener( 'load' , lf, true );
setTimeout(
function () {
var doc = newTabBrowser.contentDocument;
var inputs = doc.getElementsByTagName( "input" );
for ( var i in fields ) {
for ( var j = 0; j < inputs.length; j++ ) if ( inputs[j].name == i ) inputs[j].value = fields[i];
}
},
100
);
};
newTabBrowser.addEventListener( "load" , lf, true );
};
mi.onclick.item = item;
break ;
case "js" :
mi = createMenuItem( item.label, item.tip, item.image );
mi.onclick = new Function( item.val );
break ;
case "submenu" :
mi = createMenu( item.label, item.tip, item.image );
mi.appendChild( buildMenu( item.val ) );
break ;
case "exec" :
mi = createMenuItem( item.label, item.tip, item.image );
mi.onclick = new Function( "this.onclick.executeFile('" + item.val + "')" );
mi.onclick.executeFile = executeFile;
break ;
default :
mi = null ;
break ;
}
}
if ( mi ) menu.appendChild( mi );
}
return menu;
}
this .appendChild( buildMenu( mitems, false ) );
* This source code was highlighted with Source Code Highlighter .
var mitems = [
{
"label" : "localhost" ,
"tip" : "localhost" ,
"image" : "" ,
"type" : "url" ,
"val" : "localhost"
},
"separator" ,
{
"label" : "Google" ,
"tip" : "Google" ,
"image" : "" ,
"type" : "url" ,
"val" : "http://www.google.ru"
},
"separator" ,
{
"label" : "Notepad" ,
"tip" : "Notepad" ,
"image" : "" ,
"type" : "exec" ,
"val" : "c:/windows/notepad.exe"
},
"separator" ,
{
"label" : "other" ,
"tip" : "other" ,
"image" : "" ,
"type" : "submenu" ,
"val" :
[
{
"label" : "JS test" ,
"tip" : "JS test" ,
"image" : "" ,
"type" : "js" ,
"val" : "alert( 'js testing...' );"
},
{
"label" : " FF" ,
"tip" : " FF" ,
"image" : "" ,
"type" : "js" ,
"val" : "goQuitApplication();"
}
]
}
];
function createMenu( label, tip, image ) {
var m = document .createElement( "menu" );
m.setAttribute( "label" , label );
if ( image ) {
m.setAttribute( "class" , "menu-iconic" );
m.setAttribute( "image" , image );
}
if ( tip ) m.tooltipText = tip;
return m;
}
function createMenuItem( label, tip, image ) {
var mi = document .createElement( "menuitem" );
mi.setAttribute( "label" , label );
if ( image ) {
mi.setAttribute( "class" , "menuitem-iconic" ); // "menuitem-iconic bookmark-item"
mi.setAttribute( "image" , image );
}
if ( tip ) mi.tooltipText = tip;
return mi;
}
function executeFile( progPath, arg ) {
progPath = progPath.replace( /\ //gi, "\\" );
try {
var argArray = arg ? arg.split(/\s+/) : [];
var nsILocalFile = Components.classes[ "@mozilla.org/file/local;1" ].getService(Components.interfaces.nsILocalFile);
var nsIProcess = Components.classes[ "@mozilla.org/process/util;1" ].getService(Components.interfaces.nsIProcess);
nsILocalFile.initWithPath(progPath);
nsIProcess.init(nsILocalFile);
nsIProcess.run( false , argArray, argArray.length);
// nsIProcess.close();
return nsILocalFile;
}
catch ( ex ) {
alert( ex.toString() );
return null ;
}
}
function buildMenu( items ) {
var menu, i, t, mi, item;
var self = this ;
menu = document .createElement( "menupopup" );
menu.type = "menu" ;
menu.orient = "horizontal" ;
// menu.id = "myCustomMenu";
for ( i in items ) {
item = items[i];
if ( typeof ( item ) == "string" ) {
switch ( item ) {
case "separator" :
mi = document .createElement( "menuseparator" );
break ;
default :
mi = null ;
break ;
}
}
else {
switch ( item.type ) {
case "url" :
mi = createMenuItem( item.label, item.tip, item.image );
mi.onclick = function () {
var b = getBrowser();
b.selectedTab = b.addTab( this .onclick.addr );
b.selectedTab.onload = function () {}
};
mi.onclick.addr = item.val;
break ;
case "urlForm" :
mi = createMenuItem( item.label, item.tip, item.image );
mi.onclick = function () {
var item = this .onclick.item;
var b = getBrowser();
var tab = gBrowser.addTab( item.val.addr );
var newTabBrowser = b.getBrowserForTab( tab );
b.selectedTab = tab;
var lf = function ( event ) {
var fields = item.val.fields;
newTabBrowser.removeEventListener( 'load' , lf, true );
setTimeout(
function () {
var doc = newTabBrowser.contentDocument;
var inputs = doc.getElementsByTagName( "input" );
for ( var i in fields ) {
for ( var j = 0; j < inputs.length; j++ ) if ( inputs[j].name == i ) inputs[j].value = fields[i];
}
},
100
);
};
newTabBrowser.addEventListener( "load" , lf, true );
};
mi.onclick.item = item;
break ;
case "js" :
mi = createMenuItem( item.label, item.tip, item.image );
mi.onclick = new Function( item.val );
break ;
case "submenu" :
mi = createMenu( item.label, item.tip, item.image );
mi.appendChild( buildMenu( item.val ) );
break ;
case "exec" :
mi = createMenuItem( item.label, item.tip, item.image );
mi.onclick = new Function( "this.onclick.executeFile('" + item.val + "')" );
mi.onclick.executeFile = executeFile;
break ;
default :
mi = null ;
break ;
}
}
if ( mi ) menu.appendChild( mi );
}
return menu;
}
this .appendChild( buildMenu( mitems, false ) );
* This source code was highlighted with Source Code Highlighter .
var mitems = [
{
"label" : "localhost" ,
"tip" : "localhost" ,
"image" : "" ,
"type" : "url" ,
"val" : "localhost"
},
"separator" ,
{
"label" : "Google" ,
"tip" : "Google" ,
"image" : "" ,
"type" : "url" ,
"val" : "http://www.google.ru"
},
"separator" ,
{
"label" : "Notepad" ,
"tip" : "Notepad" ,
"image" : "" ,
"type" : "exec" ,
"val" : "c:/windows/notepad.exe"
},
"separator" ,
{
"label" : "other" ,
"tip" : "other" ,
"image" : "" ,
"type" : "submenu" ,
"val" :
[
{
"label" : "JS test" ,
"tip" : "JS test" ,
"image" : "" ,
"type" : "js" ,
"val" : "alert( 'js testing...' );"
},
{
"label" : " FF" ,
"tip" : " FF" ,
"image" : "" ,
"type" : "js" ,
"val" : "goQuitApplication();"
}
]
}
];
function createMenu( label, tip, image ) {
var m = document .createElement( "menu" );
m.setAttribute( "label" , label );
if ( image ) {
m.setAttribute( "class" , "menu-iconic" );
m.setAttribute( "image" , image );
}
if ( tip ) m.tooltipText = tip;
return m;
}
function createMenuItem( label, tip, image ) {
var mi = document .createElement( "menuitem" );
mi.setAttribute( "label" , label );
if ( image ) {
mi.setAttribute( "class" , "menuitem-iconic" ); // "menuitem-iconic bookmark-item"
mi.setAttribute( "image" , image );
}
if ( tip ) mi.tooltipText = tip;
return mi;
}
function executeFile( progPath, arg ) {
progPath = progPath.replace( /\ //gi, "\\" );
try {
var argArray = arg ? arg.split(/\s+/) : [];
var nsILocalFile = Components.classes[ "@mozilla.org/file/local;1" ].getService(Components.interfaces.nsILocalFile);
var nsIProcess = Components.classes[ "@mozilla.org/process/util;1" ].getService(Components.interfaces.nsIProcess);
nsILocalFile.initWithPath(progPath);
nsIProcess.init(nsILocalFile);
nsIProcess.run( false , argArray, argArray.length);
// nsIProcess.close();
return nsILocalFile;
}
catch ( ex ) {
alert( ex.toString() );
return null ;
}
}
function buildMenu( items ) {
var menu, i, t, mi, item;
var self = this ;
menu = document .createElement( "menupopup" );
menu.type = "menu" ;
menu.orient = "horizontal" ;
// menu.id = "myCustomMenu";
for ( i in items ) {
item = items[i];
if ( typeof ( item ) == "string" ) {
switch ( item ) {
case "separator" :
mi = document .createElement( "menuseparator" );
break ;
default :
mi = null ;
break ;
}
}
else {
switch ( item.type ) {
case "url" :
mi = createMenuItem( item.label, item.tip, item.image );
mi.onclick = function () {
var b = getBrowser();
b.selectedTab = b.addTab( this .onclick.addr );
b.selectedTab.onload = function () {}
};
mi.onclick.addr = item.val;
break ;
case "urlForm" :
mi = createMenuItem( item.label, item.tip, item.image );
mi.onclick = function () {
var item = this .onclick.item;
var b = getBrowser();
var tab = gBrowser.addTab( item.val.addr );
var newTabBrowser = b.getBrowserForTab( tab );
b.selectedTab = tab;
var lf = function ( event ) {
var fields = item.val.fields;
newTabBrowser.removeEventListener( 'load' , lf, true );
setTimeout(
function () {
var doc = newTabBrowser.contentDocument;
var inputs = doc.getElementsByTagName( "input" );
for ( var i in fields ) {
for ( var j = 0; j < inputs.length; j++ ) if ( inputs[j].name == i ) inputs[j].value = fields[i];
}
},
100
);
};
newTabBrowser.addEventListener( "load" , lf, true );
};
mi.onclick.item = item;
break ;
case "js" :
mi = createMenuItem( item.label, item.tip, item.image );
mi.onclick = new Function( item.val );
break ;
case "submenu" :
mi = createMenu( item.label, item.tip, item.image );
mi.appendChild( buildMenu( item.val ) );
break ;
case "exec" :
mi = createMenuItem( item.label, item.tip, item.image );
mi.onclick = new Function( "this.onclick.executeFile('" + item.val + "')" );
mi.onclick.executeFile = executeFile;
break ;
default :
mi = null ;
break ;
}
}
if ( mi ) menu.appendChild( mi );
}
return menu;
}
this .appendChild( buildMenu( mitems, false ) );
* This source code was highlighted with Source Code Highlighter .
{
"addr" : " " ,
"fields" : {
"1" : " 1" ,
"2" : " 2" ,
..
}
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/57413/
All Articles