-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClipboardLib.js
45 lines (45 loc) · 1013 Bytes
/
ClipboardLib.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
const DB_DOMAIN = "zhihaofans.clipboardlib",
DB_KEY = {
data: "clip_data"
};
const $ = require("$"),
{ Storage } = require("Next"),
Keychain = new Storage.Keychain(DB_DOMAIN);
function logE(message) {
$console.error("ClipboardLib", message);
}
class ClipboardLib {
constructor() {}
getList() {
const dataStr = Keychain.getValue(DB_KEY.data) || "[]";
try {
return JSON.parse(dataStr);
} catch (error) {
$console.error(error);
return [];
}
}
setList(list) {
if ($.isArray(list)) {
try {
return Keychain.setValue(DB_KEY.data, JSON.parse(list));
} catch (error) {
$console.error(error);
logE(error.message);
return false;
}
} else {
logE("setList:is not array");
return false;
}
}
addItem(text) {
const oldList = this.getList();
oldList.push(text);
this.setList(oldList);
}
removeData() {
return Keychain.remove(DB_KEY.data);
}
}
module.exports = ClipboardLib;