BF2042-Portal-Extensions

Plugins

Plugins are scripts that are loaded by the extension, right after Blockly initializes.

Creating a plugin

To create a plugin you need 3 things:

Manifest

The format of a manifest.json file is as follows:

{
    "id": "",
    "name": "",
    "version": "",
    "description": "",
    "author": "",
    "homepage": "",
    "loadAsModule": false,
    "main": ""
}

Let me go over each key:

The manifest.json should always be placed in the root-folder of the plugin!

Main JavaScript-file

The main JavaScript-file is referenced by the manifest.json and can contain any JavaScript you wish. It is not limited in any shape or form, so please be respectful of users their trust.

In theory, it is possible to load more JavaScript files from this file. It is however recommend to bundle all JavaScript into a single file for performance reasons.

Hosting the files

During development, you can make use of something like live-server to serve your files to the extension.

To deploy your files for other users, it is recommended to make a public GitHub repository and then push all required files into a dist-folder, alongside the source code (considering you want to open-source your plugin). You can then use the raw-URL to the manifest.json in the dist-folder to load your plugin.

Keep in mind that the domain hosting the raw files has X-Frame-Options set to deny, this means you can load the files directly into the BF2042 Portal just fine, but if you are using an iframe, you are going to have a bad time. If you really need to use iframes, use GitHub Pages instead.

Security concerns

Security is of utmost importance when injecting scripts into the browsers of users. Even though the extension can only modify the BF2042 Portal website and nothing else, we have to play by the rules of the many browser to allow this to be an approved extension.

As such:

But most importantly, again, be respectful of the trust users put in your plugin.

Developer Mode

NOTE! As of v2.0.0 this is no longer applicable, because the Plugin Manager is no longer part of the core Browser Extension.

While above security measures are in place, as a plugin developer you can choose to relax these restrictions a little. Turning on Developer Mode in the extension options will allow you to turn on “Live Reload” for your plugins. When Live Reload is enabled for a plugin, it will always load the main JavaScript-file directly, instead of the locally stored copy.

You will still have to update your plugin to update the manifest!

Runtime SDK

When your plugin loads, it’s possible to request a Runtime SDK from the extension.

Currently, the feature-set is very limited, but you can do the following:

A few convenience functions are also available:

NOTE! Only context menu items you want to show immediately into the context menu will have to be registered with Blockly too. For more examples, see the test-plugin.

There is no functionality yet to stream-line saving/loading data for your plugin. In order to be as prepared as possible for future chances:

This will allow the extension to easily cleanup data when your plugin gets removed or if the user wishes to reset to default values.

Licensing

Even though the BF2042 Portal Extensions is license under GPL 3.0, any plugins created are exempted from the requirement to open-source the plugin.