On MediaWiki wikis each user has a user JavaScript page they can put code in, much like GreaseMonkey but without extensions. Such as at User:YourUsername/vector.js
MediaWiki has also had an embedded Lua, called Scribunto, for a little while now.
I know Lua modules can be called from MediaWiki templates, and I suppose that's their main use. But Googling and hunting around the MediWiki docs I can't find whether there's a way to call a Lua module from your user JavaScript.
(I need to map names of languages to language codes in my JS and there's a Lua module to do just that without me duplicating the code (mainly data) in a second language.)
You can't do this directly, because JS runs on the client and Lua on the server. What you can do is to use the MediaWiki API from JS to invoke the module. Specifically using the
expandtemplates
API module.For example, if you wanted to call the function
h2d
from Module:Hex with the parameterFF
({{#invoke:hex|h2d|FF}}
in wikitext) andalert
the result, then the JS would look like this:And for the OP's specific case, running on the English Wiktionary:
(
prop: 'wikitext'
avoids a warning from the API and lets you access the result asdata.expandtemplates.wikitext
rather than the slightly mystifyingdata.expandtemplates['*']
. Otherwise there's no difference.)