GithubHelp home page GithubHelp logo

wechatjs / mp-darkmode Goto Github PK

View Code? Open in Web Editor NEW
64.0 6.0 4.0 1.41 MB

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

License: MIT License

JavaScript 1.07% CSS 3.27% HTML 71.71% Smarty 23.94%
darkmode wechat-official-account

mp-darkmode's Introduction

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
});

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.