English | 简体中文
The Dark Mode conversion algorithm for WeChat Official Accounts Platform.
Download the latest release.
Or, install via npm
:
npm i mp-darkmode
(1) Under non-AMD/CMD rule, insert mp-darkmode into <head>
.
<script src="path/to/darkmode.min.js"></script>
<script>
// run dark mode conversion algorithm
Darkmode.run(document.body.querySelectorAll('*')); // process all DOM nodes under body
</script>
(2) Under AMD/CMD rule, use require()
to import mp-darkmode.
var Darkmode = require('path/to/darkmode.min.js');
// run dark mode conversion algorithm
Darkmode.run(document.body.querySelectorAll('*')); // process all DOM nodes under body
nodes
<DOM Object Array> The DOM to be converted.options
<Object> Configuration.options.error
<Function> Callback triggered when an error occurs.err
<Error> Error object.
options.mode
<string> The specified color mode (dark | light), if specified, the system color will not be monitored.- ...
- ...
- ...
Run Dark Mode conversion algorithm.
Darkmode.run(document.body.querySelectorAll('*'), {
mode: 'dark', // force dark mode
... // other configuration items
});
More detailed usage can refer to API.
Plugins are supported since v1.1.0
. Custom actions can be performed during transformation, such as filtering DOM attributes. How to use the plugin is as follows:
Darkmode.extend([pluginA, pluginB, pluginC]);
If you want to write your own Dark Mode plugin, you can refer to here。
The algorithm is constantly updated and optimized. If you have a good idea, you can fork and submit your code. For specific development, please refer to Development Guide.