This snippet can be added to your BetterDiscord plugins to provide a simple, unintrusive self-installer.
A user downloads your plugin for BetterDiscord. Having only skimmed the #faq, he immediately double-clicks it (as he is wont to do with executable files from the internet). Then, a mysterious entity known as the Windows Script Host either spits out a non-sensical error message, or worse, provides no feedback at all. Soon afterwards, he suffers the harsh mocking of the more knowledgeable users of #support.
You can save him this embarassment.
You can save the valuable time of everyone in #support.
This takes advantage of JScript's conditional compilation to run an interactive self-installer (actually just a series of dialog prompts) when executed by the Windows Script Host, the default handler for .js
files on Windows. Your plugin code is contained safely within the @else ... @end
block, preventing the Windows Script Host from trying (and typically failing) to evaluate JavaScript syntax meant for a modern web browser. When executed under normal conditions, the self-installer's code is interpreted as a harmless comment.
Add the contents of SelfInstaller.HEADER.js
after the META line of your plugin, but before any actual code. Then, to the end of your file, add the contents of SelfInstaller.FOOTER.js
.
Alternatively, use the provided shell script to modify your plugin(s) in place:
$ ./patch.sh example.plugin.js
or
$ ./patch.sh *.plugin.js