-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
executable file
·77 lines (63 loc) · 2.3 KB
/
options.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
75
76
77
function init()
{
var prefs = JSON.parse(window.localStorage.getItem("prefs"));
if( prefs === null ) prefs = {expire:10080,privacy:1,api_token:'',latestPastesDisplaySize:5};
var expire = prefs.expire; // determine the expiration
var privacy = prefs.privacy; // determine paste privacy
var api_token = prefs.api_token; // determine if user account
var latestPastesDisplaySize = prefs.latestPastesDisplaySize;
saveOptions(expire, privacy, api_token, latestPastesDisplaySize);
document.getElementById("expire").addEventListener("change", update);
document.getElementById("privacy").addEventListener("change", update);
document.getElementById("api_token").addEventListener("change", update);
document.getElementById("latestPastesDisplaySize").addEventListener("change", update);
// Set initial data options page
document.getElementById("expire").value = expire;
document.getElementById("range-value").innerHTML = getExpirationLabel(expire);
document.getElementById("privacy").value = privacy;
document.getElementById("api_token").value = api_token;
document.getElementById("latestPastesDisplaySize").value = latestPastesDisplaySize;
document.getElementById("range-value-display").innerHTML = getDisplayLabel(latestPastesDisplaySize);
}
function getExpirationLabel(expire)
{
if(expire == 1)
return expire + " minute";
else if(expire == 262800)
return "forever";
else if(expire > 20160)
return Math.floor(expire/60/24) + " days";
else if(expire > 5760)
return Math.floor(expire/60) + " hours";
else
return Math.floor(expire) + " minutes";
}
function getDisplayLabel(size)
{
return size + " rows";
}
function getExpiration()
{
return document.getElementById("expire").value;
}
function getPrivacy()
{
return document.getElementById("privacy").value;
}
function getAPI()
{
return document.getElementById("api_token").value;
}
function getLatestPastesDisplaySize()
{
return document.getElementById("latestPastesDisplaySize").value;
}
function update()
{
saveOptions(getExpiration(), getPrivacy(), getAPI(), getLatestPastesDisplaySize());
}
function saveOptions(expire, privacy, api_token, latestPastesDisplaySize)
{
window.localStorage.setItem("prefs", JSON.stringify({expire: expire, privacy: privacy, api_token: api_token, latestPastesDisplaySize: latestPastesDisplaySize}));
}
window.onload = init;