-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstepHelper.js
More file actions
103 lines (92 loc) · 1.9 KB
/
stepHelper.js
File metadata and controls
103 lines (92 loc) · 1.9 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const stepHelperClass = class{
/**
* @private
* @type {number}
**/
#start = 0;
/**
* @private
* @type {number}
**/
#name = 'id';
/**
* @private
* @type {string}
**/
#url = 'none';
/**
* @private
* @type {StorageHelperClass}
**/
#sT = '';
/**
* @private
* @type {MinerToolClass}
**/
#mT = '';
/**
* @private
**/
async #step(new_id_){
const _url = this.#url;
const _new_id = new_id_;
await this.#sT.set(
this.#name,
_new_id
);
this.#mT.setRandOut(function(){
window.location = (
_url.replace('{id}', _new_id)
);
});
};
/**
*
* @param {string} //
* @param {?string} //
* @param {?number} // {?int}
* @constructs
**/
constructor(url_, name_, start_) {
this.#sT = new StorageHelperClass();
this.#mT = new MinerToolClass('miner', 4000, 1000);
if (typeof name_ !== 'undefined')
this.#name = name_.toString();
if (typeof start_ !== 'undefined')
this.#start = start_;
this.#url = url_;
};
/**
*
* @public
* @async
* @return {number} // {int}
**/
async get(){
const org = parseInt(await this.#sT.get(this.#name));
if(isNaN(org))
return this.#start;
return org;
};
/**
*
* @public
* @async
**/
async step(){
const _org_id = await this.get();
this.#step((_org_id - 1).toString());
};
/**
*
* @param {sting|number}
* @public
* @async
**/
async safeStep(current_id_){
const _org_id = await this.get();
if(current_id_ == _org_id)
return this.#step((_org_id - 1).toString());
this.#step(_org_id.toString());
};
};