Updated Plugin APIs (markdown)
parent
08cbdc2236
commit
f9439d8df0
|
@ -1,72 +1,3 @@
|
|||
**The current version of BetterDiscord is deprecated and will only receive bug fixes. You may want to develop plugins for [BetterDiscord v2](https://github.com/JsSucks/BetterDiscordApp) instead, however it is in active development and the plugin API has no documentation and is subject to change.**
|
||||
**The current version of BetterDiscord in this repository is deprecated, however there is a semi-official fork that maintains the current version while the next version of BetterDiscord is being developed, check out the documentations [here](https://github.com/rauenzi/BetterDiscordApp/wiki/Creating-Plugins)**
|
||||
|
||||
IMPORTANT: Name your plugins `*.plugin.js` or they won't load.
|
||||
|
||||
## Building a plugin
|
||||
|
||||
Take a look at this prototypal [Example Plugin](https://gist.github.com/Jiiks/71edd5af0beafcd08956) or this class based [Example](https://gist.github.com/rauenzi/e5f4d02fc3085a53872b0236cd6f8225) for a template.
|
||||
|
||||
Checkout some of the plugins from the official [BetterDiscord repository](https://github.com/Jiiks/BetterDiscordApp/blob/master/Plugins).
|
||||
|
||||
Currently available [BdApi](https://github.com/Jiiks/BetterDiscordApp/blob/master/dev/js/12api.js) functions:
|
||||
|
||||
```js
|
||||
// Inject CSS to `head` element with identifier, don't forget to remove it on stop
|
||||
BdApi.injectCSS(id, css);
|
||||
|
||||
// Clear your CSS
|
||||
BdApi.clearCSS(id);
|
||||
|
||||
// Interact with other plugins
|
||||
BdApi.getPlugin(pluginName);
|
||||
|
||||
// Get the BetterDiscord core module
|
||||
BdApi.getCore();
|
||||
|
||||
// Save some information to disk (as JSON)
|
||||
bdPluginStorage.set(pluginName, key, value);
|
||||
|
||||
// Get the stored information
|
||||
bdPluginStorage.get(pluginName, key);
|
||||
```
|
||||
|
||||
## Third-party libraries
|
||||
|
||||
Some plugin developers have written their own libraries for developing plugins (some functions, such as monkey patching and accessing Discord's webpack modules are built into BDv2):
|
||||
|
||||
Name | Source | Documentation | License
|
||||
------------------------|-----------------------|-----------------------|------------
|
||||
Lib Discord Internals | https://github.com/samogot/betterdiscord-plugins/tree/master/v2/1Lib%20Discord%20Internals | | [MIT](https://github.com/samogot/betterdiscord-plugins/blob/master/LICENSE)
|
||||
Zere's Plugin Library | https://github.com/rauenzi/BDPluginLibrary | https://rauenzi.github.io/BDPluginLibrary/docs/ | [MIT](https://github.com/rauenzi/BDPluginLibrary/blob/master/LICENSE)
|
||||
|
||||
## Details
|
||||
|
||||
### Plugins are limited to one file
|
||||
|
||||
There can be multiple files in the BetterDiscord plugins directory, but to prevent junk and prevent future collisions, it is best practice to include your entire plugin within one file. You can use [webpack](https://webpack.js.org) or any other JS module bundler to combine multiple source files and any dependencies into a single file.
|
||||
|
||||
### Plugins require a special header
|
||||
|
||||
BetterDiscord requires one line at the beginning of a plugin file to identify it:
|
||||
|
||||
```js
|
||||
//META{"name":"testPlugin"}*//
|
||||
```
|
||||
|
||||
Be sure that `testPlugin` matches the variable name defined in the file. Without this, your plugin will not be identified by BD properly and will not show up in the list.
|
||||
|
||||
### Discord isn't just a browser
|
||||
|
||||
Discord is Node.js and Chromium as one. BetterDiscord plugins can use all built-in [Node.js](https://nodejs.org/docs/latest-v10.x/api/) and [Electron](https://github.com/electron/electron/tree/v4.0.8/docs) modules. It is possible to include pure JS modules within your plugin using [webpack](https://webpack.js.org) or any other JS module bundler. Native modules will work, but are not supported (at least until BDv2 is released) and you'll have to compile and distribute binaries for the following platforms:
|
||||
|
||||
- Windows 32-bit with Electron 4.0.8 (Node.js API version 69)
|
||||
- Darwin (macOS) 64-bit with Electron 4.0.8 (Node.js API version 69)
|
||||
- Linux 64-bit with Electron 4.0.8 (Node.js API version 69)
|
||||
|
||||
### Plugins are susceptible to throttling
|
||||
|
||||
By default, Discord will throttle plugins when it is minimised or otherwise not visible onscreen. Currently there are no in-plugin workarounds for this. Throttling is the same as Chromium, functions like `setInterval` and `setTimeout` will be throttled to at least 1000ms.
|
||||
|
||||
### Add namespaces to your events
|
||||
|
||||
When using jQuery and listening on events like `$(document).on('dblclick', ...)`, use a namespace such as `$(document).on('dblclick.myplugin', ...)` in order to easily unload all events with `$(document).off('dblclick.myplugin')` or `$(document).off('*.myplugin')` without affecting Discord and other plugins.
|
||||
Interested in helping out with BetterDiscord v2's development? [Click here!](https://github.com/JsSucks/BetterDiscordApp)
|
||||
|
|
Loading…
Reference in New Issue