This repository has been archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
options.js
185 lines (156 loc) · 8.2 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// wire stuff to prevent XSS :(
$(document).ready(function()
{
$('#save').click(function(){Save();});
$('#cancel').click(function(){window.close();});
$('#feedSource').change(function(){FeedSourceChanged();});
$('#importFeeds').click(function(){window.open('import.html', 'height=250,width=550');});
$('#exportFeeds').click(function(){window.open('export.html', 'height=250,width=550');});
$('#dateDone').click(function(){ShowDateSample(true);});
$('#dateFormat').focus(function(){EditDateFormat();});
});
var bgPage = chrome.extension.getBackgroundPage();
window.onload = SetupScreen;
function SetupScreen()
{
document.getElementById("feedSource").selectedIndex = parseInt(bgPage.options.feedsource);
FeedSourceChanged(); // changing index doesn't fire onchange :(
document.getElementById("maxItems").value = bgPage.options.maxitems;
document.getElementById("showDescriptions").selectedIndex = bgPage.options.showdescriptions;
document.getElementById("showFeedImages").selectedIndex = bgPage.options.showfeedimages;
document.getElementById("showFeedObjects").selectedIndex = bgPage.options.showfeedobjects;
document.getElementById("showFeedIframes").selectedIndex = bgPage.options.showfeediframes;
document.getElementById("showFeedContent").selectedIndex = bgPage.options.showfeedcontent;
document.getElementById("checkInterval").value = bgPage.options.checkinterval;
document.getElementById("markReadAfter").value = bgPage.options.markreadafter;
document.getElementById("markReadOnClick").selectedIndex = bgPage.options.markreadonclick;
document.getElementById("readItemDisplay").selectedIndex = bgPage.options.readitemdisplay;
document.getElementById("unreadTotalDisplay").selectedIndex = bgPage.options.unreadtotaldisplay;
document.getElementById("unreadItemTotalDisplay").selectedIndex = bgPage.options.unreaditemtotaldisplay;
document.getElementById("columns").selectedIndex = bgPage.options.columns - 1;
document.getElementById("readLaterEnabled").selectedIndex = bgPage.options.readlaterenabled;
document.getElementById("readLaterRemoveWhenViewed").selectedIndex = bgPage.options.readlaterremovewhenviewed;
document.getElementById("readLaterIncludeTotal").selectedIndex = bgPage.options.readlaterincludetotal;
document.getElementById("loadLinksInBackground").selectedIndex = bgPage.options.loadlinksinbackground;
chrome.bookmarks.getTree(FillFolderList);
ShowDateSample(false);
document.getElementById("homePageURL").innerText = chrome.extension.getURL("viewer.html");
if(bgPage.snifferID != null)
{
document.getElementById("snifferInfo").innerText = bgPage.snifferName + " (v" + bgPage.snifferVersion + ")";
document.getElementById("snifferInfo").style.color = "black";
}
else
{
document.getElementById("snifferInfo").innerHTML = "None, <a href=\"https://chrome.google.com/extensions/detail/mpajmofiejfjgeaakelmjklenjaekppa\" onclick=\"window.close();\"target=\"_blank\" style=\"color: red;\">install Slick RSS Feed Finder</a>";
document.getElementById("snifferInfo").style.color = "red";
}
}
function Save()
{
var maxItems = document.getElementById("maxItems").value;
if(!/^\d+$/.test(maxItems) || maxItems == "0")
{
alert("'Max Items' seems invalid. It's the max number of items in a feed preview and should be > 0");
return;
}
if(!/^\d+$/.test(document.getElementById("checkInterval").value))
{
alert("'Update Interval' seems invalid. It's the number of minutes between fetching unread counts.");
return;
}
if(document.getElementById("checkInterval").value == 0)
{
alert("'Update Interval' must be > 0.");
return;
}
if(!/^\d+$/.test(document.getElementById("markReadAfter").value))
{
alert("'Mark feed read after' seems invalid. It's the number of seconds after you've viewed a feed before it's marked read.");
return;
}
bgPage.options.feedsource = document.getElementById("feedSource")[document.getElementById("feedSource").selectedIndex].value;
bgPage.options.feedfolderid = document.getElementById("feedFolderID")[document.getElementById("feedFolderID").selectedIndex].value;
bgPage.options.maxitems = parseInt(maxItems);
bgPage.options.showdescriptions = (document.getElementById("showDescriptions").selectedIndex == 1);
bgPage.options.showfeedimages = (document.getElementById("showFeedImages").selectedIndex == 1);
bgPage.options.showfeedobjects = (document.getElementById("showFeedObjects").selectedIndex == 1);
bgPage.options.showfeediframes = (document.getElementById("showFeedIframes").selectedIndex == 1);
bgPage.options.showfeedcontent = (document.getElementById("showFeedContent").selectedIndex == 1);
bgPage.options.checkinterval = document.getElementById("checkInterval").value;
bgPage.options.markreadonclick = (document.getElementById("markReadOnClick").selectedIndex == 1);
bgPage.options.markreadafter = document.getElementById("markReadAfter").value;
bgPage.options.readitemdisplay = document.getElementById("readItemDisplay")[document.getElementById("readItemDisplay").selectedIndex].value;
bgPage.options.unreadtotaldisplay = document.getElementById("unreadTotalDisplay")[document.getElementById("unreadTotalDisplay").selectedIndex].value;
bgPage.options.unreaditemtotaldisplay = (document.getElementById("unreadItemTotalDisplay").selectedIndex == 1);
bgPage.options.columns = document.getElementById("columns")[document.getElementById("columns").selectedIndex].value;
bgPage.options.readlaterenabled = (document.getElementById("readLaterEnabled").selectedIndex == 1);
bgPage.options.readlaterremovewhenviewed = (document.getElementById("readLaterRemoveWhenViewed").selectedIndex == 1);
bgPage.options.readlaterincludetotal = (document.getElementById("readLaterIncludeTotal").selectedIndex == 1);
bgPage.options.loadlinksinbackground = (document.getElementById("loadLinksInBackground").selectedIndex == 1)
localStorage["options"] = JSON.stringify(bgPage.options);
if(!bgPage.options.readlaterenabled)
{
delete localStorage["readlater"];
}
bgPage.GetFeeds(function()
{
bgPage.ReloadViewer();
bgPage.CheckForUnreadStart();
});
window.close();
}
// fills the folder dropdown
function FillFolderList(nodes)
{
var folderList = document.getElementById("feedFolderID");
var arr = [];
var option = null;
GetBookmarkNodes(nodes[0], arr, "");
for(var i = 0;i < arr.length; i++)
{
option = document.createElement("option");
option.setAttribute("value", arr[i][0]);
option.innerHTML = arr[i][1];
if(arr[i][0] == bgPage.options.feedfolderid)
{
option.setAttribute("selected", "selected");
}
folderList.appendChild(option);
}
}
// recursively fills array with ids and titles of folders in the bookmark tree
function GetBookmarkNodes(node, arr, depth)
{
for(var i = 0; i < node.children.length; i++)
{
if(node.children[i].url == null)
{
var detail = new Array(2);
detail[0] = node.children[i].id;
detail[1] = depth + node.children[i].title;
arr.push(detail);
GetBookmarkNodes(node.children[i], arr, depth + " ");
}
}
}
function FeedSourceChanged()
{
document.getElementById("feedFolder").style.display = (document.getElementById("feedSource").selectedIndex == 0) ? "none" : "";
}
function EditDateFormat()
{
document.getElementById("dateFormat").value = bgPage.options.dateformat;
document.getElementById("dateHelp").style.display = "";
document.getElementById("dateDone").style.display = "";
}
function ShowDateSample(saveDate)
{
if(saveDate)
{
bgPage.options.dateformat = document.getElementById("dateFormat").value;
}
document.getElementById("dateFormat").value = bgPage.GetFormattedDate(new Date());
document.getElementById("dateHelp").style.display = "none";
document.getElementById("dateDone").style.display = "none";
}