An open API service indexing awesome lists of open source software.

https://github.com/wechatjs/mp-darkmode

微信公众平台图文 Dark Mode 转换算法
https://github.com/wechatjs/mp-darkmode

darkmode wechat-official-account

Last synced: 6 months ago
JSON representation

微信公众平台图文 Dark Mode 转换算法

Awesome Lists containing this project

README

          

English | [简体中文](./README_CN.md)

mp-darkmode
==============================
[![NPM version][npm-image]][npm-url]

The Dark Mode conversion algorithm for WeChat Official Accounts Platform.

## Start

### 1. Download

Download the [latest release](https://github.com/wechatjs/mp-darkmode/releases).

Or, install via `npm`:

```shell
npm i mp-darkmode
```

### 2. Import

(1) Under non-AMD/CMD rule, insert mp-darkmode into ``.

```html

// run dark mode conversion algorithm
Darkmode.run(document.body.querySelectorAll('*')); // process all DOM nodes under body

```

(2) Under AMD/CMD rule, use `require()` to import mp-darkmode.

```javascript
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.

```javascript
Darkmode.run(document.body.querySelectorAll('*'), {
mode: 'dark', // force dark mode
... // other configuration items
});
```

More detailed usage can refer to [API](./doc/en/API.md).

## 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:

```javascript
Darkmode.extend([pluginA, pluginB, pluginC]);
```

If you want to write your own Dark Mode plugin, you can refer to [here](./doc/en/plugins.md)。

## 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](./doc/en/develop.md).

[npm-url]: https://www.npmjs.com/package/mp-darkmode
[npm-image]: https://img.shields.io/npm/v/mp-darkmode.svg