Getting a list of all categories on ACP plugin settings

How do I display in ACP plugin settings all categories so the user can select them manually, in order to then automatically post a topic in all of them (for example, using the hook filter:post.create)?

I already have the list with all categories, but now I want the function I have in the /static/lib/main.js file to run only on the categories I selected on the plugin settings page (those settings are stored in the /library.js file).

Can I do this or do I have to move that function to the /library.js file too?

static/lib/main.js:

"use strict";
$(window).on('action:ajaxify.end', function(ev) {
var CategoriesIds = [28,29];
// I want to change this to fetch the categories selected from the plugin's settings page
// instead of using the array above, to prevent the user having to modify the plugin files
// to change the ID of the categories
if( $.inArray( parseInt(ajaxify.data.cid, 10) , CategoriesIds) != -1){
runFunction();
}
});

I can tell u what runFunction() is, I just simplified it for a better understanding.
Because what I just to replace is this condition if( $.inArray( parseInt(ajaxify.data.cid, 10) , CategoriesIds) != -1) instead of going search if the current category is on the array CategoriesIds above (hardcoded), I need to check if the current category is on the selection made by the user on the plugin config page.

And I'm not realizing how I make that connection between the plugin settings and the function.

On the server, you can do
var groups = require.main.require('./src/groups');
groups.getUserGroups([1] /*array of uids*/, function(err, userGroups){
if (err) return;
// Returns an array of an array of group data.
console.log(userGroups[0]); // Prints an array of groups for uid 1
});
on the client, you can get a list of visible groups by doing:
$.getJSON('/api/user/USERSLUG/groups', function (data) {
// Returns an object with a 'groups' property, an array of visible group data.
console.log(data.groups);
});