CreateButton, CreateCallbackButton
These functions are not implemented.
AddToolbar
Quote
AddToolbar
The current implementation of this function does not work as expected.
Somewhere i wrote almost the same comment, in fact this function works as expected.
You can try this function in error console, then open a new km window and you will see the new toolbar there.
const JSB = Components.classes['@kmeleon/jsbridge;1'].getService(Components.interfaces.nsIJSBridge);
JSB.SetMenuCallback('Misc', 'Test AddToolbar function', function () {
JSB.AddToolbar('TestToolbar');
}, '');
So, that's what Dorian was expecting
This function is unusable in km addons.
Id
Quote
Kris_88
Quote
siria
Regarding parameters, macros can use 1 (?), and it must be a string (?) not some object, which can inside be accessed as $ARG:
macros(mymacro(sometext));
Yes, it works surprisingly.
Thank you!
jsb.id( null, 'macros(mymacro(123))' );
mymacro{
alert($ARG);
}
GetCmdList
You can see the registered commands.
In practice, i did not see the need for such a function. Perhaps in some hypothetical circumstances when you use the SetAccel function and you need to check if some key combination is already being used.
AddListener
Paste this code into the error console, then open, switch, close tabs and windows:
Components.utils.import('resource://gre/modules/Services.jsm');
const JSB = Components.classes['@kmeleon/jsbridge;1'].getService(Components.interfaces.nsIJSBridge);
const TEST = {
observe: function (subject, topic, data) {
if (topic == 'kmeleon-switchtab')
Services.console.logStringMessage('kmeleon-switchtab: ' + subject.document.documentURIObject.spec);
else
Services.console.logStringMessage(topic);
}
};
JSB.AddListener(TEST);
GetActiveBrowser, GetCurrentWindow, GetWindows
Open several windows in km and several websites in different tabs, then paste this code into the error console and make some tests:
Components.utils.import('resource://gre/modules/Services.jsm');
const JSB = Components.classes['@kmeleon/jsbridge;1'].getService(Components.interfaces.nsIJSBridge);
JSB.SetMenuCallback('Misc', 'Test GetActiveBrowser (get url)', function () {
Services.console.logStringMessage('url: ' + JSB.GetActiveBrowser().contentDOMWindow.document.documentURIObject.spec);
}, '');
JSB.SetMenuCallback('Misc', 'Test GetCurrentWindow (get url)', function () {
Services.console.logStringMessage('wnd.tab.length: ' + JSB.GetCurrentWindow().getTabs().length);
for (var a in JSB.GetCurrentWindow().getTabs()) {
Services.console.logStringMessage(
'wnd.tab[' + a + '].url: ' +
JSB.GetCurrentWindow().getTabs()[a].contentDOMWindow.document.documentURIObject.spec);
}
}, '');
JSB.SetMenuCallback('Misc', 'Test GetWindows (get url)', function () {
Services.console.logStringMessage('wnd.length: ' + JSB.GetWindows().length);
for (var a in JSB.GetWindows()) {
Services.console.logStringMessage('wnd[' + a + '].tab.length: ' + JSB.GetWindows()[a].getTabs().length);
for (var z in JSB.GetWindows()[a].getTabs()) {
Services.console.logStringMessage(
'wnd[' + a + '].tab[' + z + '].url: ' +
JSB.GetWindows()[a].getTabs()[z].contentDOMWindow.document.documentURIObject.spec);
}
}
}, '');
RegisterCmd
One example from my old km when it is necessary for a menu item or a button to be checked or disabled. Paste this code into the error console:
Components.utils.import('resource://gre/modules/Preferences.jsm');
const JSB = Components.classes['@kmeleon/jsbridge;1'].getService(Components.interfaces.nsIJSBridge);
[
['network.cookie.cookieBehavior', 'Block Co&okies', [2, 0], 'cookie', 'Toggle cookie acceptance', ],
['javascript.enabled', 'Block Java&script', [false, true], 'javascript', 'Toggle JavaScript execution', 'VK_F7'],
['dom.disable_open_during_load', 'Block &Popups', [true, false], 'popup', 'Toggle popup blocking', 'VK_F8'],
['permissions.default.image', 'Block &Images', [2, 1], 'image', 'Toggle image loading', 'VK_F9'],
['image.animation_mode', 'Block Image Ani&mation', ['none', 'normal'], 'animation', 'Toggle image animation', ],
['permissions.default.object', 'Block Objec&ts', [2, 1], 'object', 'Toggle object loading', ],
['kmeleon.flashblock', 'Block F&lash', [true, false], 'flash', 'Toggle Flashblock', ],
['kmeleon.adblocking', 'Block A&dvertisement', [true, false], 'advertisement', 'Toggle Ad-Blocking StyleSheet', ],
['browser.display.use_document_colors', 'Block &Colors', [false, true], 'color', 'Toggle page colors', ],
['browser.frames.enabled', 'Block &Frames', [false, true], 'frame', 'Toggle frame support', ]
].forEach(function([pref, desc, value, cmnd, msg, accel]) {
JSB.RegisterCmd(
'privacy' + cmnd + 'cmnd',
msg,
function () {
Preferences.set(pref, Preferences.get(pref) == value[0] ? value[1] : value[0]);
},
'',
function () { /* enabled */
return ((cmnd == 'flash' && Preferences.get('javascript.enabled') == false) ? false : true);
},
function () { /* checked */
return (Preferences.get(pref) == value[0]);
}
);
JSB.SetMenu('TestPrivacy', 1, desc, 'privacy' + cmnd + 'cmnd', '');
if (typeof accel != 'undefined')
JSB.SetAccel(accel, 'privacy' + cmnd + 'cmnd');
});
JSB.RegisterCmd( /* button command */
'btncmnd',
'',
function () {
Preferences.set('javascript.enabled', !Preferences.get('javascript.enabled'));
},
'chrome://global/skin/icons/information-64.png',
function () { /* enabled */
return true; /* set a condition here when the button will be disabled */
},
function () { /* checked */
return !Preferences.get('javascript.enabled');
}
);
JSB.AddButton(
'&Go Buttons',
'btncmnd',
'TestPrivacy',
'Test RegisterCmd function\nRight click for more options.'
);
I wrote a small simple
addon, hoping it can help you in your tests. Inside, you can see how to use most of the jsbridge functions.
Important:
in pref "
kmeleon.install_firefox_extension" set value
false,
in pref "
consoleservice.enabled" set value
true.
Edited 1 time(s). Last edit at 08/16/2022 07:49PM by adodupan.