Skip to content

wechatjs/mp-darkmode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English | 简体中文

mp-darkmode

NPM version

The Dark Mode conversion algorithm for WeChat Official Accounts Platform.

Start

1. Download

Download the latest release.

Or, install via npm:

npm i mp-darkmode

2. Import

(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

Usage

Darkmode.run(nodes[, options])

  • 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

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

Contribution

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.