vilike
v0.2.2
Published
A lightweight counts of visit and like plugin.
Downloads
108
Maintainers
Readme
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 useisHit
to judge whether the current browser has been visited.0
: Don't open LocalStorage, and return the value ofvalue
directly after the request is successful.1
: Turn on LocalStorage, and the value ofisHit
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 asvilike.vercel.app
etc.skey
: Subkeys, filled with unique strings, such as Hash, MD5, etc.value
: The initial value of the data, the default value is0
.ctrl
: Used to configure whether the data can be changed or not, the default value is0
.0
: The data is locked and cannot be changed using theVilike.update
method.1
: The data is unlocked and can be changed using theVilike.update
method.
upperbound
: The maximum limit can be added to the data, and the default value is1
.
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
is0
:value
The default value is0
. - When
type
is1
:value
The default value is1
.
- When
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.
Contributors
This project exists thanks to all the people who contribute.
License
RVerify © 2020-present, Feng L.H. Released under the MIT License.