Since the recent MediaWiki update, the user script [[User:MarkS/extraeditbuttons.js]] (and its translation [[pt:MediaWiki:Gadget-Extra-Editbuttons.js]]) is not working anymore.
I was trying to fix the Portuguese version and make it into a ResourceLoader-compatible gadget, but I wasn't capable of restoring its previous behaviour because it is currently impossible (AFAIK) to force its function "initButtons()" which depends on "mw.toolbar.addButton()" (from module "mediawiki.action.edit") to be executed BEFORE the execution of "mw.toolbar.init()" BUT AFTER the default buttons are added to the array "mw.toolbar.buttons" (a replacemente to the legacy "window.mwCustomEditButtons") by the inline <script> tag in the botton of the page.
This order is necessary because "initButtons()" needs to be capable to redefine the content of the array "mw.toolbar.buttons" (adding and/or removing buttons) before it is used by "mw.toolbar.init()" to insert the listed buttons in the edit toolbar.
In its current state, the extra buttons are being added before the ones from MediaWiki, and the user can't change the order of (neither remove) the default MW buttons. This seems to be because those "mw.toolbar.addButton" from MediaWiki is appending the default elements to the array AFTER it has already being filled with user defined buttons (how can the user remove something which is not there yet?).
If I change "initButtons()" to "$(document).ready(initButtons)", then MediaWiki default buttons are added to the begining of the array and the gadget could edit the array, but in this case the gadget is executed too late, after "mw.toolbar.init()" happened, and so any changes made to "mw.toolbar.buttons" will have no efect in the resulting toolbar.
Please provide some alternative to fix this kind of user scripts which worked fine previously.