|
| 1 | +# Plugin |
| 2 | + |
| 3 | +KanbanBro plugins are a mechanism for extending the behavior of pages displayed by KanbanBro. |
| 4 | + |
| 5 | +## Plugin syntax |
| 6 | + |
| 7 | +A plugin consists of the following three parts: |
| 8 | + |
| 9 | +- Magic comment |
| 10 | +- Metadata section |
| 11 | +- Body |
| 12 | + |
| 13 | +### Magic comment |
| 14 | + |
| 15 | +Use the following magic comment to mark the script as a KanbanBro plugin. |
| 16 | + |
| 17 | +```javascript |
| 18 | +// @KanbanBroPlugin |
| 19 | +``` |
| 20 | + |
| 21 | +### Metadata section |
| 22 | + |
| 23 | +The metadata section contains the plugin's metadata. |
| 24 | + |
| 25 | +It is JSON code commented out with `// `. |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +Example: |
| 30 | + |
| 31 | +```javascript |
| 32 | +// { |
| 33 | +// "name": "com.example.example_plugin", |
| 34 | +// "title": "Example Plugin", |
| 35 | +// "version": "1.0.0", |
| 36 | +// "description": "This is <b>an example</b> plugin." |
| 37 | +// } |
| 38 | +``` |
| 39 | + |
| 40 | +### Body |
| 41 | + |
| 42 | +The body is JavaScript code that implements the plugin's behavior. |
| 43 | + |
| 44 | +To avoid conflicts with the metadata section, the first line of the body must not be a line comment. |
| 45 | + |
| 46 | +The body is generally free-form, but in many cases it includes a check so it runs only on specific pages. |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +Example: |
| 51 | + |
| 52 | +```javascript |
| 53 | +if (location.href === 'https://example.com/') { |
| 54 | + console.log('This is example.com'); |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +### Example |
| 59 | + |
| 60 | +Below is a complete plugin example. |
| 61 | + |
| 62 | +```javascript |
| 63 | +// @KanbanBroPlugin |
| 64 | +// { |
| 65 | +// "name": "com.example.example_plugin", |
| 66 | +// "title": "Example Plugin", |
| 67 | +// "version": "1.0.0", |
| 68 | +// "description": "This is <b>an example</b> plugin." |
| 69 | +// } |
| 70 | + |
| 71 | +if (location.href === 'https://example.com/') { |
| 72 | + console.log('This is example.com'); |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +## File name |
| 77 | + |
| 78 | +The plugin file must have the `.kbb.js` extension. |
| 79 | + |
| 80 | +More precisely, the URL from which the plugin is downloaded is expected to end with `.kbb.js`. |
| 81 | + |
| 82 | +## Metadata |
| 83 | + |
| 84 | +### `name` : required string |
| 85 | + |
| 86 | +A name that uniquely identifies the plugin. |
| 87 | + |
| 88 | +The name is expected to follow an identifier-like format separated by dots, similar to a Java package name. |
| 89 | + |
| 90 | +Each identifier component is expected to consist of one or more lowercase ASCII letters, digits, or underscores (`/[a-z0-9_]+/`). |
| 91 | + |
| 92 | +Example: `com.example.example_plugin` |
| 93 | + |
| 94 | +### `title` : required string |
| 95 | + |
| 96 | +A human-readable title for the plugin. |
| 97 | + |
| 98 | +The title does not have to be in English. |
| 99 | + |
| 100 | +We recommend up to 10 full-width characters or 20 half-width characters. |
| 101 | + |
| 102 | +Example: `Example Plugin` |
| 103 | + |
| 104 | +### `version` : required string |
| 105 | + |
| 106 | +The plugin version. |
| 107 | + |
| 108 | +The version is expected to be the `version core` of [Semantic Versioning](https://semver.org/) (`/([1-9][0-9]*)\.([1-9][0-9]*)\.([1-9][0-9]*)/`). |
| 109 | + |
| 110 | +Example: `1.0.0` |
| 111 | + |
| 112 | +### `description` : required string |
| 113 | + |
| 114 | +A description of the plugin. |
| 115 | + |
| 116 | +It does not have to be in English. |
| 117 | + |
| 118 | +The description supports a subset of HTML, which is rendered on Android by the following code: |
| 119 | + |
| 120 | +<code>textView.<a href="https://developer.android.com/reference/android/widget/TextView#setText(int)">setText</a>(Html.<a href="https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int)">fromHtml</a>(description, Html.FROM_HTML_MODE_COMPACT))</code> |
| 121 | + |
| 122 | +Example: `This is <b>an example</b> plugin.` |
| 123 | + |
| 124 | +## Plugin behavior |
| 125 | + |
| 126 | +Plugins are executed as JavaScript after the page has fully loaded. |
| 127 | + |
| 128 | +Therefore, you do not need to wait for the onload event. |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +You cannot use `await` directly in the plugin body. |
| 133 | + |
| 134 | +If you want to use `await`, wrap the code in a `Promise` as follows: |
| 135 | + |
| 136 | +```javascript |
| 137 | +new Promise(async () => { |
| 138 | + // Code that uses await |
| 139 | +}); |
| 140 | +``` |
0 commit comments