I have found this excellent snippet Make my userscript wait for other scripts to load that shows me how to wait for a function to be available before calling it.
Currently I have this local code in my script which I have put together which works for me
waitForFnc();
function waitForFnc() {
if (typeof Portal.Management_Init == "undefined") {
window.setTimeout(waitForFnc, 50);
}
else {
Portal.Management_Init();
}
}
However, I would like to write a generic version of 'waitForFnc' as I need to do the same thing in several places. Something like
waitForFnc(Portal.Management_Init);
function waitForFnc(fnc) {
if (typeof fnc == "undefined") {
window.setTimeout(waitForFnc(fnc), 50);
}
else {
fnc();
}
}
where I pass the name of the function in which is called when it becomes available. The above code does not work but I am unsure as to how to resolve it.
Regards Paul