A helper script for Spider Monkey Panel and foobar2000 which allows to easily attach and manage event listeners associated to SMP callbacks without wrapping or repeating code. A lifesaver.
Complex scripts, like those with UI, usually have interactive items at multiple places which must be linked to a callback to perform actions at certain events. While SMP allows modularization using include(), callbacks must be placed within a main file since redefinition of the function simply overwrites the previous one. That clearly limits the ability to just mix modules and or add event listeners to non-final scripts.
Using this framework it would translate into this:
- Adds event listeners to SMP callbacks.
- Removes event listeners on demand.
- Allows to find if an event listener is active.
- Listeners are able to self-remove.
- Mimics mozilla implementation.
- Implements SPM planned design.
- Bypasses common limitation of including files with existing callbacks, wrapping, etc.
Just add an event listener to an specific event/callback.
const listener = () => {console.log('Hello world!');}
addEventListener('on_mouse_lbtn_up', listener);
That's all. To remove it just do:
removeEventListener('on_mouse_lbtn_up', listener);
Multiple listeners can be attached to the same event:
addEventListener('on_mouse_lbtn_up', () => {console.log('1!');});
addEventListener('on_mouse_lbtn_up', () => {console.log('2!');});
addEventListener('on_mouse_lbtn_up', () => {console.log('3!');});
addEventListener('on_mouse_lbtn_up', () => {console.log('14!');});
Listener removal may be done using their UUID or function:
const listener = () => {console.log('Hello world!');}
const uuid = addEventListener('on_mouse_lbtn_up', listener);
removeEventListener('on_mouse_lbtn_up', null, uuid);
There are more usage examples on the 'examples' folder.
Since the framework only requires 1 file, i.e. the main one, you can simply include it along any other script where you usually need a callback.