-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.js
58 lines (51 loc) · 1.15 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
window.onload = function ()
{
var log = function (str){
if(window.console)
window.console.log(str);
};
var txt = document.getElementById("urls");
var saved = document.getElementById("saved");
var error = document.getElementById("error");
var showError = function (str){
error.innerHTML = str;
error.hidden = false;
};
var trim = function (s)
{
var l=0; var r=s.length -1;
while(l < s.length && s[l] == ' ')
{ l++; }
while(r > l && s[r] == ' ')
{ r-=1; }
return s.substring(l, r+1);
}
var restore_options = function (){
log("restore_options");
var urls = localStorage["inspiring_urls"];
if (!urls) {
// populate with defaults
txt.value = INSPIRING_URLS.join(",");
}else{
txt.value = urls;
}
};
var save_options = function (){
log("save");
saved.hidden = true;
error.hidden = true;
// trim
txt.value = trim(txt.value);
if (txt.value.length == 0) {
showError("Insert at least a url");
return;
}
localStorage["inspiring_urls"] = txt.value;
saved.hidden = false;
};
restore_options();
var btn = document.getElementById("btn");
btn.onclick = function (){
save_options();
}
}