forked from Kenshin/simpread
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal.js
More file actions
87 lines (76 loc) · 1.59 KB
/
local.js
File metadata and controls
87 lines (76 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
console.log( "=== simpread local load ===" )
const id = "simpread",
NAMES = {
VER : "version",
COUNT : "count",
FIRST : "firstload",
},
MAX_COUNT = 5;
let curcount;
/**
* Read and Write Local Storage
*
* @class
*/
class Local {
get curcount() {
return curcount;
}
/**
* @method
*
* @return {boolean} true: not MAX_COUNT; false: exceed MAX_COUNT, re-count
*/
Count() {
const [ cur = 0 ] = [ get(NAMES.COUNT) ];
curcount = cur;
set( NAMES.COUNT, ++curcount );
if ( curcount > MAX_COUNT ) {
set( NAMES.COUNT, 0 );
return false;
} else {
return true;
}
}
/**
* @method
*
* @return {boolean} true: first load; false: not first load
*/
Firstload() {
let [ firstload = "true" ] = [ get(NAMES.FIRST) ];
if ( firstload == "true" ) {
set( NAMES.FIRST, false );
return true;
} else {
return false;
}
}
/**
* Save manifest.json version to local storage
*
* @param {string} version
*/
Version( version ) {
set( NAMES.VER, version );
}
}
/**
* Get localStorage from key
*
* @param {string} NAMES.{value}
*/
function get( key ) {
return localStorage[ `${id}-${key}` ];
}
/**
* Set localStorage
*
* @param {string} NAMES.{value}
* @param {any} any value
*/
function set( key, value ) {
localStorage[ `${id}-${key}` ] = value;
}
const local = new Local();
export default local;