Link Search Menu Expand Document

JScript migration guide

Table of contents


It is rather simple to migrate your script from foo_jscript_panel to foo_spider_monkey_panel: you only need to perform all the steps listed below.
Most of these can be automated by using Find & Replace command in your favourite text editor.

Note: at the time of writing foo_jscript_panel is still in active development, hence this guide might not cover some incompatibilities that could’ve been introduced in newer versions of the component.

Replace old headers:

Before
// ==PREPROCESSOR==
// @name "MyScript"
// @author "Me"
// @version "1.2.3"
// @import "%fb2k_path%\path\to\script1.js"
// @import "%fb2k_path%\path\to\script2.js"
// @feature "dragdrop"
// ==/PREPROCESSOR==
After
window.DefineScript('MyScript', {author: 'Me', version: '1.2.3', features: {drag_n_drop: true} });
include(`${fb.FoobarPath}/path/to/script1.js`);
include(`${fb.FoobarPath}/path/to/script2.js`);


Remove .toArray() and .Dispose() methods:

Before
var artists = tfo.EvalWithMetadbs(handle_list).toArray();
var artist = artists[0];
tfo.Dispose();
After
let artists = tfo.EvalWithMetadbs(handle_list);
let artist = artists[0];


Replace FbMetadbHandleList.Item(i) calls with FbMetadbHandleList[i]:

Before
var items = plman.GetPlaylistItems(plman.ActivePlaylist);
var item = items.Item(0);
After
let items = plman.GetPlaylistItems(plman.ActivePlaylist);
let item = items[0];


Replace plman.PlaylistRecyclerManager with plman.PlaylistRecycler; replace calls to it’s properties: Name>GetName, Content>GetContent:

Before
var playlist_name = plman.PlaylistRecyclerManager.Name(i);
var playlist_content = plman.PlaylistRecyclerManager.Content(i);
After
let playlist_name = plman.PlaylistRecycler.GetName(i);
let playlist_content = plman.PlaylistRecycler.GetContent(i);


Add additional argument to fb.DoDragDrop:

Before
fb.DoDragDrop(cur_playlist_selection, g_drop_effect.copy);
After
fb.DoDragDrop(0, cur_playlist_selection, g_drop_effect.copy);


If there are errors about unknown methods or properties, make sure that corresponding methods and properties have the valid case:

Before
Console.Log('Log message');
var items = plman.getPlaylistItems(plman.activePlaylist);
After
console.log('Log message');
let items = plman.GetPlaylistItems(plman.ActivePlaylist);


Some methods have more rigorous error checks, so you’ll have to pass the valid arguments:

Before
menu.CheckMenuRadioItem(StartIndex, StartIndex, StartIndex + (checked ? 0 : 1)); ///< out of bounds error
After
if (checked) {
    menu.CheckMenuRadioItem(StartIndex, StartIndex, StartIndex);
}

Copyright © 2018-2021 Yuri Shutenko.
Distributed by an MIT license.