-
Notifications
You must be signed in to change notification settings - Fork 3
/
storage.js
74 lines (66 loc) · 1.38 KB
/
storage.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict';
const defaults = {
sync: {
quickmode: false,
careful: false,
show_text: true,
show_tags: true,
default_tags: "Bookmark",
reqfav: true,
savingmode: 'download',
savebox: false,
address: "",
auth: false,
username: "",
password: "",
safety: true,
bookmark_fmt:
`let now = (d => {
const pad = (w, i) => ("0".repeat(w) + i).slice(-w);
return pad(4, d.getUTCFullYear())
+ pad(2, d.getUTCMonth() + 1)
+ pad(2, d.getUTCDate())
+ pad(2, d.getUTCHours())
+ pad(2, d.getUTCMinutes())
+ pad(2, d.getUTCSeconds())
+ pad(3, d.getUTCMilliseconds());
})(new Date());
let o = {
title: title,
tags: tags,
text: text,
fields: {
rawtitle: rawtitle,
link: url,
created: now,
modified: now
}
};
if (icon !== undefined) {
o.fields.icon = icon.title;
}
return o;`,
favicon_separate: true,
favicon_fmt:
`return {
title: \`\${hash}.\${ext}\`,
tags: "Favicon",
text: data,
type: mime
};`,
justinstalled: true
},
local: {
state: 'ready',
error: {},
tags: ""
}
};
const storage_all = a =>
browser.storage[a].get(defaults[a]);
const storage_obj = (a, k) =>
browser.storage[a].get({[k]: defaults[a][k]});
const local_of = async k => (await storage_obj('local', k))[k];
const pref_of = async k => (await storage_obj('sync', k))[k];
const fake_update = async (a, k) =>
browser.storage[a].set(await storage_obj(a, k));