K-Meleon

The JSBridge Plugin provides a javascript interface between the cross-platform user-interface language (XUL) and K-Meleon's core. K-Meleon supports XUL-based extensions, distributed as .xpi files. XUL-based extensions were designed for Mozilla applications which used XUL for the browser's interface. K-Meleon creates its lightweight interface using the native win32 APIs, so JSBridge is necessary to create K-Meleon menu items, toolbars, and buttons from within Mozilla-style extensions.


Calling JSBridge

Before using JSBridge functions you must call it either directly or via import:

  • Directly calling the interface
var KMeleon = Components.classes["@kmeleon/jsbridge;1"]
                         .getService(Components.interfaces["nsIJSBridge"]);

or

  • Import KMeleon module
Components.utils.import("resource:///modules/KMeleon.jsm");

.


Kmeleon.js

Kmeleon.js is a javascript file that K-Meleon will automatically load from the top-level of an xpi file. You can add K-Meleon-specific interface elements into this file, and they will not impact how the extension functions in other browsers.


JSBridge functions

List of All Functions

function (arguments)
SetMenuCallback (menu, label,function() {},before);
SetMenu (menuName,itemType,itemName,command,location);
RebuildMenu (menuName)
CreateButton (const char * cmd, menuName, tooltipText, itemName, kmIButton * *_retval)
CreateCallbackButton (kmICommandFunction *command, menuName, tooltipText, itemName, kmIButton * *_retval)
AddToolbar (toolbarName, uint32_t width, uint32_t height)
AddButton (toolbarName, command, menuName, tooltipText)
RemoveButton (toolbarName, command)
Id id(null ,commandID);
SendMessage (to,from,subject,data1,data2)
GetCmdList (uint32_t *length, kmICommand * **list)
RegisterCmd (commandName, statusbarText, function() {}, chrome://yourExtension/yourIcon.png, kmICallback *enabled, kmICallback *checked, COLD[, HOT[, DEAD]] , int32_t *_retval)
UnregisterCmd (commandName)
SetCmdIcon (commandName, chrome://yourExtension/yourIcon.png, COLD[, HOT[, DEAD]] )
SetButtonIcon (toolbarName, command, chrome://yourExtension/yourIcon.png, COLD[, HOT[, DEAD]] )
SetAccel (keys, command)
Open Open(url , state) ;
GetActiveBrowser (nsIWebBrowser * *_retval)
GetCurrentWindow (kmIWindow * *_retval)
GetWindows (uint32_t *length, kmIWindow * **list)
AddListener (nsIObserver *listener)
RemoveListener (nsIObserver *listener)
LoadPlugin (const char * path)
ShowMenu (commandName, bool sendCommand, int32_t *_retval)


Tested Functions

SetMenuCallback

Syntax SetMenuCallback(menu, label,function() {},before) ;
Result Set \ create Menu items , which will call Javascript function when menu is activated .

Example:

KMeleon.SetMenuCallback("&Tools", "open pref",function(mode) 
{KMeleon.Open('chrome://kmprefs/content/pref.xul', KMeleon.OPEN_NEWTAB); });


Open

Syntax Open( url , state ) ;
Result Open a local a external address in a new tab/window.
States OPEN_NORMAL, OPEN_NEW ,OPEN_BACKGROUND, OPEN_NEWTAB, OPEN_BACKGROUNDTAB, or OPEN_CLONE

Example:

var url='chrome://kmprefs/content/pref.xul';
 KMeleon.Open(url, KMeleon.OPEN_NEW);


Id

Syntax id(null ,commandID);
Result Open Command IDs.

Example:

KMeleon.id(null,'ID_PASSWORDS_VIEWER');


SetMenu

Syntax setmenu(menuName,itemType,itemName,command,location);
Result Create a new menu item. All items are not required to build menu entries, but all items must be present to display icons from SetCmdIcon?.
itemType inline, popup, separator, command, macro, or plugin

Example:

KMeleon.SetMenu("&Tools","macro","my macro","my_function");


RebuildMenu

Syntax RebuildMenu(menuName);
Result Rebuild a menu.
itemType inline, popup, separator, command, macro, or plugin

Example:

KMeleon.RebuildMenu("my_Menu");


RegisterCmd

Syntax RegisterCmd(commandName, statusbarText, function() {}, chrome://yourExtension/yourIcon.png, COLD[, HOT[, DEAD]]);
Result Register a command to be called. Icon is optional.

Example:

KMeleon.RegisterCmd(CmdName, 'Hello World', function(wind, mode, arg) {          
                      popupAlert('Alert', 'Hello World!');
  }, 'chrome://helloworld/content/icon.png');


SetCmdIcon

Syntax SetCmdIcon(commandName, chrome://yourExtension/yourIcon.png, COLD[, HOT[, DEAD]]);
Result Set the icon associated with a command. Only one image is required; separate cold/hot/dead icons are optional.

Example:

KMeleon.SetCmdIcon(CmdName, 'chrome://helloworld/content/icon.png')


UnregisterCmd

Syntax UnregisterCmd(commandName);
Result Unregister a command.

Example:

KMeleon.UnregisterCmd(CmdName);


AddButton

Syntax AddButton(toolbarName, commandName, menuName, tooltipText);
Result Adds a button to an existing toolbar.

Example:

KMeleon.AddButton('Browser Con&figuration', CmdName, "", "Hello World demo.");


RemoveButton

Syntax RemoveButton(toolbarName, commandName,);
Result Removes a button from a toolbar.

Example:

KMeleon.RemoveButton(Toolbar, CmdName);


Experimental Functions

SendMessage

Syntax SendMessage(to,from,subject,data1,data2);
Result Connect with plugins.*
Macro Macro file in string form.
Issues *This only works with the macro plugin. It only works on v76.X. Some macros may crash the browser.

Example:

KMeleon.SendMessage("macros", "kmAddon", "RunMacro", macro);

AddToolbar

The current implementation of this function does work as expected.


Example Extensions

Modified for K-Meleon

http://kmeleon.sourceforge.net/wiki/?binary=internal%3A%2F%2Fba049820350a1db8e41f3da56325e9bd.jpegAdBlock Classic

AdBlock Classic is a fork of ABPrime and AdBlock Plus. To see an example of JSBridge functions, extract the .xpi file and examine the K-Meleon.js file in the root directory. This is how K-Meleon is creating menus for AdBlock Classic. It provides a clear example of how to use localization files.

http://kmeleon.sourceforge.net/wiki/?binary=internal%3A%2F%2Fba049820350a1db8e41f3da56325e9bd.jpegNewsFox

K-Meleon version 74, can run a macro from inside xpi file ( withe the name 'load.kmm' ) , or run startup function from javascript file ( withe the name 'kmeleon.js' ) inside xpi file too.

The startup function can create k-meleon menu item , using SetMenuCallback function ,which mean that menu item could run javascript or macro function if you need it.

Note: In K-Meleon 74, if you want to try this method , then you will need to add the component " kmAddon.js" to k-meleon with modified versions of "jsbridge.xpt" & "JSBridge.dll" & "macros.dll" from this
Example: newsfox_test2.zip .


Written for K-Meleon

http://kmeleon.sourceforge.net/wiki/?binary=internal%3A%2F%2Fba049820350a1db8e41f3da56325e9bd.jpeg "Hello world!"

The hello world reference extensions use JSBridge in a variety of ways. You can test-install them on your browser to see how their process works. Extract the extensions with any archive like 7-Zip, Winzip, or PeaZip. You can open the program files in any text editor like Notepad, Notepad++, or Notepad2. Note that only the XUL-based extensions will use JSBridge.

http://kmeleon.sourceforge.net/wiki/?binary=internal%3A%2F%2Fba049820350a1db8e41f3da56325e9bd.jpeg Adodupan's macro reference

See Forum
This adds a menu line for calling a macro (incidentally also named "howtousejsbridge", but can be any other too) to the context menu of a xul page. As example the URL "about:config" was chosen in chrome.manifest.
Adodupan posted this 2019, saying that it works in KM74, crashed in KM75-76, and now works again since KM-Goanna76.
Howto change the text in the menu item: edit file howtousejsbridge.dtd
Howto call another macro: edit pref 'extensions.howtousejsbridge.macro'.

http://kmeleon.sourceforge.net/wiki/?binary=internal%3A%2F%2Fba049820350a1db8e41f3da56325e9bd.jpeg Kris' Screenshot Tool

Kris_88's screenshot tool is a fully functional extension that creates whole page screenshots. It uses JSBridge extensively. It's a native K-Meleon extension that runs entirely from a single .xpi and supports K-Meleon versions 74 and up.

K-Meleon

(c) 2000-2010 kmeleonbrowser.org. All rights reserved.
design by splif.