Skip to main content


Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Callbacks-Framework-SMP (Read 1031 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.



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.

Helper meant mostly for coders not for final users, although it may be easily included on any script (don't expect how to's by my side apart from these instructions).

The problem with current SMP callbacks
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.
  • Mimics mozilla implementation.
  • Implements SPM planned design.
  • Bypasess common limitation of including files with existing callbacks, wrapping, etc.

Just add an event listener to an specific event/callback.
Code: [Select]
const listener = () => {console.log('Hello world!');}
addEventListener('on_mouse_lbtn_up', listener);
That's all. To remove it just do:
Code: [Select]
removeEventListener('on_mouse_lbtn_up', listener);
Multiple listeners can be attached to the same event:
Code: [Select]
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:
Code: [Select]
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.

Download latest release (or nightly releases) at github:

Re: Callbacks-Framework-SMP

Reply #1
v1.1.0 - Added remove function Latest

    removeEventListeners: new function 'removeEventListeners(event)' to remove all listeners attached to a callback. Event may be a string or array of strings with the name of callbacks to remove, i.e. 'on_playlists_changed' or ['on_playlists_changed', 'on_script_unload'].


Re: Callbacks-Framework-SMP

Reply #2
[1.2.2] - 2023-02-23

    Fix to on_mouse_rbtn_up disable default menu behavior.