-
Notifications
You must be signed in to change notification settings - Fork 4
/
util.js
53 lines (48 loc) · 1.33 KB
/
util.js
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
class Utility {
static get_data(key) {
return new Promise(resolve => {
chrome.storage.local.get(key, item => {
if (item && item[key]) {
resolve(item[key]);
}
else {
resolve();
}
})
})
}
static set_data(key, data) {
return new Promise(resolve => {
chrome.storage.local.get(key, item => {
if (item && item[key]) {
const merge_data = Object.assign(item[key], data);
chrome.storage.local.set({ [key]: merge_data }, () => { resolve() });
}
else {
chrome.storage.local.set({ [key]: data }, () => { resolve() });
}
})
})
}
static is_expired(date_string) {
const today = new Date();
const expire_day = new Date(date_string);
return (today > expire_day);
}
static get_expire_date(duration) {
const expire_time = new Date(new Date().getTime() + duration * 24 * 60 * 60 * 1000);
const mm = expire_time.getMonth() + 1;
const dd = expire_time.getDate();
const yy = expire_time.getFullYear();;
const expire_day = `${mm}/${dd}/${yy}`;
return expire_day;
}
static back_fetch(url){
return new Promise(resolve => {
const action = 'fetch_http';
chrome.runtime.sendMessage({ action, url }, response => {
resolve(response);
})
})
}
}