Giter Site home page Giter Site logo

zpfz / vilike.js Goto Github PK

View Code? Open in Web Editor NEW
12.0 1.0 2.0 55 KB

๐Ÿ‘€๐Ÿ‘ A lightweight counts of visit and like plugin.

Home Page: https://vilikejs.pages.dev/

License: MIT License

JavaScript 94.44% HTML 5.56%
visit count vilike like view

vilike.js's Introduction

Vilike.js

A lightweight counts of visit and like plugin.

Build Status Downloads Version License

Installation

Add Vilike.js to your project.

<script src="https://unpkg.com/vilike/dist/Vilike.min.js"></script>

You can get the corresponding CDN link from unpkg or jsdelivr.

Vilike.js is available via npm, and you can also use NPM:

npm install --save vilike
# or yarn add vilike

Basic usage

Vilike.exec(pkey, skey, mode)

Get the returned data through pkey and skey, the initial value is 1. Each time this method is executed, the data on the CountAPI server will automatically increase by one.
NOTE: If the corresponding pkey and skey exist in the CountAPI service, the corresponding data will be returned directly, otherwise the default data will be created automatically.

Parameter Description

  • pkey : Fill in the primary key that needs to be queried. If it does not exist, it will be created automatically and keep the default configuration.
  • skey : Fill in the subkey that needs to be queried. If it does not exist, it will be created automatically and keep the default configuration.
  • mode : LocalStorage mode, after opening, you can use isHit to judge whether the current browser has been visited.
    • 0 : Don't open LocalStorage, and return the value of value directly after the request is successful.
    • 1 : Turn on LocalStorage, and the value of isHit can be returned after the request is successful.

E.g.

Vilike.exec('github','vilike',1).then((result) => {
  console.log(result);
});

Result

{
  isHit: true,
  value: 1
}

Advanced Usage

Vilike.create(pkey, skey, value, ctrl, upperbound)

Used to create custom data, including key value, data controllability, and data additivity.

Parameter Description

  • pkey : Primary key, usually fill in the primary domain name, such as vilike.vercel.app etc.
  • skey : Subkeys, filled with unique strings, such as Hash, MD5, etc.
  • value : The initial value of the data, the default value is 0.
  • ctrl : Used to configure whether the data can be changed or not, the default value is 0.
    • 0 : The data is locked and cannot be changed using the Vilike.update method.
    • 1 : The data is unlocked and can be changed using the Vilike.update method.
  • upperbound : The maximum limit can be added to the data, and the default value is 1.

E.g.

Vilike.create('github.zpfz','vilike', 82382, 1, 999).then((result) => {
  console.log(result);
});

Result

{
  key: "vilike"
  namespace: "github.zpfz"
  value: 82382
}

Vilike.update(pkey, skey, value, type)

Used to update the corresponding values of pkey and skey, provided that the data needs to be created with the Vilike.create method and the value of ctrl is guaranteed to be 1.

Parameter Description

  • pkey : Fill in the primary key to be queried.
  • skey : Fill in the subkey that needs to be queried.
  • value : Fill in the value that needs to be updated, the default value is divided into two cases:
    • When type is 0: value The default value is 0.
    • When type is 1: value The default value is 1.
  • type : Set the data change type.
    • 0 : Replace the original data, you can replace the original data.
    • 1 : Additive counters that can be superimposed on the original data upwards.

E.g. 1

Vilike.update('github.zpfz','vilike', 565, 0).then((result) => {
  console.log(result);
});

Result

{
  old_value: 82382,
  value: 565
}

E.g. 2

Vilike.update('github.zpfz','vilike', 565, 1).then((result) => {
  console.log(result);
});

Result

{
  value: 1130
}

Vilike.info(pkey, skey)

Used to query all the information of the current data.

Parameter Description

  • pkey : Fill in the primary key to be queried.
  • skey : Fill in the subkey that needs to be queried.

E.g.

Vilike.info('github.zpfz','vilike').then((result) => {
  console.log(result);
});

Result

{
  created: 1622122993446
  enable_reset: true
  key: "vilike"
  namespace: "github.zpfz"
  ttl: 15769999666
  update_lowerbound: 0
  update_upperbound: 999
  value: 1130
}

NOTE: The fields above are in order: creation time, whether the data can be changed, subkey, primary key, TTL, maximum limit for data reduction, maximum limit for data addition, current value.

Try Online

Contributors

This project exists thanks to all the people who contribute.

Feng L.H.

License

RVerify ยฉ 2020-present, Feng L.H. Released under the MIT License.

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.