Huggle/JS/hello world.js
Appearance
// Note: all functions prefixed with "ext_" are function hooks, huggle will try to locate them and execute
// on certain events
// This hook needs to return true as long as the extension is considered operational.
// If this function ever returns false, Huggle will consider it defunct and will halt its execution.
// It may be useful when your extension reach or catches some exceptional condition and further
// execution is dangerous or impossible.
// Extensions can't unload or remove themselves from operating memory, but can send indications
// to Huggle that they are defunct through this hook
function ext_is_working()
{
return true;
}
function register_menus()
{
// Create all sample menus, list of available menus is here on github:
// https://github.com/huggle/huggle3-qt-lx/blob/master/src/huggle_core/scripting/ecma/types.js
huggle_ui.create_menu_item(huggle_ui_menu_scripting, "Hello world: HTML", "html");
huggle_ui.create_menu_item(huggle_ui_menu_scripting, "Hello world: Message box", "message_box");
huggle_ui.create_menu_item(huggle_ui_menu_scripting, "Hello world: Console", "console_hello");
huggle_ui.create_menu_item(huggle_ui_menu_scripting, "Hello world: Error", "hello_error");
}
function console_hello()
{
// Print to standard huggle system window
huggle.log("Hello world!");
}
function hello_error()
{
// Same as console_hello but marked as error
huggle.error_log("yep");
}
function html()
{
// Replaces current browser window HTML code with this. This function locks the user interface by default as well.
huggle_ui.render_html("<big>Hello world</big>");
}
function message_box()
{
huggle_ui.message_box("Example", "Hello world");
}
// Main entry point, called when extension is being loaded. Should return true.
// If doesn't return true, extension is considered to fail to load and is later removed from memory
function ext_init()
{
// Scripts can be loaded anytime, but menus can be created only if main window exists,
// which is not when you start huggle. So in case main window doesn't exist yet, we just
// register a hook which is triggered when it is open. Otherwise we register menus now.
if (huggle_ui.mainwindow_is_loaded())
{
// Main window already exists so we can register our menus
register_menus()
} else if (!huggle.register_hook("main_open", "register_menus"))
{
// We were unable to register main_open hook for some reason
return false;
}
return true;
}
// Returns various information about the script
function ext_get_info()
{
var info = {};
info["name"] = "hello world";
info["version"] = "1.0.0";
info["description"] = "Shows some possibilities of scripting engine";
info["author"] = "Petr Bena";
// info["min_huggle_version"] = "3.4.0";
// info["required_context"] = "huggle_ui";
// info["requires_unsafe"] = false;
return info;
}