2 This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>
3 Licensed under GPL v.2 or (at your preference) any later version.
7 var xmlhttp_rpc
= false;
8 var xmlhttp_view
= false;
13 var active_post_id
= false;
14 var active_feed_id
= false;
15 var active_offset
= false;
17 var total_feed_entries
= false;
19 var _viewfeed_autoselect_first
= false;
20 var _viewfeed_autoselect_last
= false;
22 var search_query
= "";
25 /*@if (@_jscript_version >= 5)
26 // JScript gives us Conditional compilation, we can cope with old IE versions.
27 // and security blocked creation of the objects.
29 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
32 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
33 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
34 xmlhttp_view = new ActiveXObject("Microsoft.XMLHTTP");
43 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
44 xmlhttp
= new XMLHttpRequest();
45 xmlhttp_rpc
= new XMLHttpRequest();
46 xmlhttp_view
= new XMLHttpRequest();
49 function feedlist_callback() {
50 var container
= document
.getElementById('feeds');
51 if (xmlhttp
.readyState
== 4) {
52 container
.innerHTML
=xmlhttp
.responseText
;
55 scheduleFeedUpdate(false);
63 function viewfeed_callback() {
64 var container
= document
.getElementById('headlines');
65 if (xmlhttp
.readyState
== 4) {
66 container
.innerHTML
= xmlhttp
.responseText
;
68 var factive
= document
.getElementById("FACTIVE");
69 var funread
= document
.getElementById("FUNREAD");
70 var ftotal
= document
.getElementById("FTOTAL");
72 if (_viewfeed_autoselect_first
== true) {
73 _viewfeed_autoselect_first
= false;
74 view(getFirstVisibleHeadlineId(), active_feed_id
);
77 if (_viewfeed_autoselect_last
== true) {
78 _viewfeed_autoselect_last
= false;
79 view(getLastVisibleHeadlineId(), active_feed_id
);
82 if (ftotal
&& factive
&& funread
) {
83 var feed_id
= factive
.innerHTML
;
85 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
86 var feedt
= document
.getElementById("FEEDT-" + feed_id
);
87 var feedu
= document
.getElementById("FEEDU-" + feed_id
);
89 feedt
.innerHTML
= ftotal
.innerHTML
;
90 feedu
.innerHTML
= funread
.innerHTML
;
92 total_feed_entries
= ftotal
.innerHTML
;
94 if (feedu
.innerHTML
> 0 && !feedr
.className
.match("Unread")) {
95 feedr
.className
= feedr
.className
+ "Unread";
96 } else if (feedu
.innerHTML
<= 0) {
97 feedr
.className
= feedr
.className
.replace("Unread", "");
102 var searchbox
= document
.getElementById("searchbox");
104 searchbox
.value
= search_query
;
111 function view_callback() {
112 var container
= document
.getElementById('content');
113 if (xmlhttp_view
.readyState
== 4) {
114 container
.innerHTML
=xmlhttp_view
.responseText
;
118 function refetch_callback() {
120 if (xmlhttp_rpc
.readyState
== 4) {
121 notify("All feeds updated");
122 var container
= document
.getElementById('feeds');
123 container
.innerHTML
= xmlhttp_rpc
.responseText
;
124 document
.title
= "Tiny Tiny RSS";
128 function scheduleFeedUpdate(force
) {
130 notify("Updating feeds in background...");
132 document
.title
= "Tiny Tiny RSS - Updating...";
134 var query_str
= "backend.php?op=rpc&subop=";
137 query_str
= query_str
+ "forceUpdateAllFeeds";
139 query_str
= query_str
+ "updateAllFeeds";
142 if (xmlhttp_ready(xmlhttp_rpc
)) {
143 xmlhttp_rpc
.open("GET", query_str
, true);
144 xmlhttp_rpc
.onreadystatechange
=refetch_callback
;
145 xmlhttp_rpc
.send(null);
151 function updateFeedList(silent
, fetch
) {
153 if (silent
!= true) {
154 notify("Loading feed list...");
157 var query_str
= "backend.php?op=feeds";
159 if (fetch
) query_str
= query_str
+ "&fetch=yes";
161 if (xmlhttp_ready(xmlhttp
)) {
162 xmlhttp
.open("GET", query_str
, true);
163 xmlhttp
.onreadystatechange
=feedlist_callback
;
170 function catchupPage(feed
) {
172 if (!xmlhttp_ready(xmlhttp
)) {
177 var content
= document
.getElementById("headlinesList");
179 var rows
= new Array();
181 for (i
= 0; i
< content
.rows
.length
; i
++) {
182 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
183 if (row_id
.length
> 0) {
184 if (content
.rows
[i
].className
.match("Unread")) {
186 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Unread", "");
191 if (rows
.length
> 0) {
193 var feedr
= document
.getElementById("FEEDR-" + feed
);
194 var feedu
= document
.getElementById("FEEDU-" + feed
);
196 feedu
.innerHTML
= feedu
.innerHTML
- rows
.length
;
198 if (feedu
.innerHTML
> 0 && !feedr
.className
.match("Unread")) {
199 feedr
.className
= feedr
.className
+ "Unread";
200 } else if (feedu
.innerHTML
<= 0) {
201 feedr
.className
= feedr
.className
.replace("Unread", "");
204 var query_str
= "backend.php?op=rpc&subop=catchupPage&ids=" +
205 param_escape(rows
.toString());
207 notify("Marking this page as read...");
209 xmlhttp
.open("GET", query_str
, true);
210 xmlhttp
.onreadystatechange
=notify_callback
;
214 notify("No unread items on this page.");
219 function catchupAllFeeds() {
221 if (!xmlhttp_ready(xmlhttp
)) {
225 var query_str
= "backend.php?op=feeds&subop=catchupAll";
227 notify("Marking all feeds as read...");
229 xmlhttp
.open("GET", query_str
, true);
230 xmlhttp
.onreadystatechange
=feedlist_callback
;
235 function viewfeed(feed
, skip
, subop
) {
239 var searchbox
= document
.getElementById("searchbox");
242 search_query
= searchbox
.value
;
247 /* if (active_feed_id == feed && subop != "ForceUpdate") {
248 notify("This feed is currently selected.");
252 if (skip
< 0 || skip
> total_feed_entries
) {
256 if (!xmlhttp_ready(xmlhttp
)) {
261 active_feed_id
= feed
;
262 active_post_id
= false;
263 active_offset
= skip
;
265 var query
= "backend.php?op=viewfeed&feed=" + param_escape(feed
) +
266 "&skip=" + param_escape(skip
) + "&subop=" + param_escape(subop
);
268 if (search_query
!= "") {
269 query
= query
+ "&search=" + param_escape(search_query
);
272 xmlhttp
.open("GET", query
, true);
273 xmlhttp
.onreadystatechange
=viewfeed_callback
;
276 notify("Loading headlines...");
280 function cleanSelectedHeadlines() {
281 var content
= document
.getElementById("headlinesList");
283 var rows
= new Array();
285 for (i
= 0; i
< content
.rows
.length
; i
++) {
286 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
291 function view(id
,feed_id
) {
295 if (!xmlhttp_ready(xmlhttp_view
)) {
300 var crow
= document
.getElementById("RROW-" + id
);
302 if (crow
.className
.match("Unread")) {
303 var umark
= document
.getElementById("FEEDU-" + feed_id
);
304 umark
.innerHTML
= umark
.innerHTML
- 1;
305 crow
.className
= crow
.className
.replace("Unread", "");
307 if (umark
.innerHTML
== "0") {
308 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
309 feedr
.className
= feedr
.className
.replace("Unread", "");
315 cleanSelectedHeadlines();
317 crow
.className
= crow
.className
+ "Selected";
319 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
322 upd_img_pic
.innerHTML
= "";
325 document
.getElementById('content').innerHTML
='Loading, please wait...';
329 xmlhttp_view
.open("GET", "backend.php?op=view&id=" + param_escape(id
), true);
330 xmlhttp_view
.onreadystatechange
=view_callback
;
331 xmlhttp_view
.send(null);
337 scheduleFeedUpdate(true);
338 setTimeout("timeout()", 1800*1000);
341 function resetSearch() {
342 document
.getElementById("searchbox").value
= "";
343 viewfeed(active_feed_id
, 0, "");
346 function search(feed
) {
347 viewfeed(feed
, 0, "");
350 function localPiggieFunction(enable
) {
352 var query_str
= "backend.php?op=feeds&subop=piggie";
354 if (xmlhttp_ready(xmlhttp
)) {
356 xmlhttp
.open("GET", query_str
, true);
357 xmlhttp
.onreadystatechange
=feedlist_callback
;
363 function relativeid_callback() {
365 if (xmlhttp_rpc
.readyState
== 4) {
366 notify(xmlhttp_rpc
.responseText
);
371 function getVisibleHeadlineIds() {
373 var content
= document
.getElementById("headlinesList");
375 var rows
= new Array();
377 for (i
= 0; i
< content
.rows
.length
; i
++) {
378 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
379 if (row_id
.length
> 0) {
386 function getFirstVisibleHeadlineId() {
387 var rows
= getVisibleHeadlineIds();
391 function getLastVisibleHeadlineId() {
392 var rows
= getVisibleHeadlineIds();
393 return rows
[rows
.length
-1];
396 function moveToPost(mode
) {
398 var rows
= getVisibleHeadlineIds();
403 if (active_post_id
== false) {
404 next_id
= getFirstVisibleHeadlineId();
405 prev_id
= getLastVisibleHeadlineId();
407 for (var i
= 0; i
< rows
.length
; i
++) {
408 if (rows
[i
] == active_post_id
) {
415 var content
= document
.getElementById("headlinesList");
417 if (mode
== "next") {
418 if (next_id
!= undefined) {
419 view(next_id
, active_feed_id
);
421 _viewfeed_autoselect_first
= true;
422 viewfeed(active_feed_id
, active_offset
+15);
426 if (mode
== "prev") {
427 if ( prev_id
!= undefined) {
428 view(prev_id
, active_feed_id
);
430 _viewfeed_autoselect_last
= true;
431 viewfeed(active_feed_id
, active_offset
-15);
437 function localHotkeyHandler(keycode
) {
440 return moveToPost('next');
444 return moveToPost('prev');
448 return scheduleFeedUpdate(true);
452 return viewfeed(active_feed_id
, active_offset
, "ForceUpdate");
455 // notify("KC: " + keycode);
464 if (xmlhttp
&& !xmlhttp_rpc
) {
465 xmlhttp_rpc
= xmlhttp
;
466 xmlhttp_view
= xmlhttp
;
469 if (!xmlhttp
|| !xmlhttp_rpc
|| !xmlhttp_view
) {
470 document
.getElementById("headlines").innerHTML
=
471 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
472 "to function properly. Your browser doesn't seem to support it.";
476 updateFeedList(false, false);
477 document
.onkeydown
= hotkey_handler
;
478 setTimeout("timeout()", 1800*1000);