diff --git a/player/javascript/defaults.js b/player/javascript/defaults.js index d85653bd3f..9694b852d7 100644 --- a/player/javascript/defaults.js +++ b/player/javascript/defaults.js @@ -170,6 +170,28 @@ mp.abort_async_command = function abort_async_command(id) { mp._abort_async_command(id); } +// shared-script-properties - always an object, even if without properties +function shared_script_property_set(name, val) { + if (arguments.length > 1) + return mp.commandv("change-list", "shared-script-properties", "append", "" + name + "=" + val); + else + return mp.commandv("change-list", "shared-script-properties", "remove", name); +} + +function shared_script_property_get(name) { + return mp.get_property_native("shared-script-properties")[name]; +} + +function shared_script_property_observe(name, cb) { + return mp.observe_property("shared-script-properties", "native", + function shared_props_cb(_name, val) { cb(name, val[name]) } + ); +} + +mp.utils.shared_script_property_set = shared_script_property_set; +mp.utils.shared_script_property_get = shared_script_property_get; +mp.utils.shared_script_property_observe = shared_script_property_observe; + /********************************************************************** * key bindings *********************************************************************/