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", "");
100 cleanSelected("feedsList");
102 feedr
.className
= feedr
.className
+ "Selected";
105 var searchbox
= document
.getElementById("searchbox");
106 searchbox
.value
= search_query
;
108 markHeadline(active_post_id
);
115 function view_callback() {
116 var container
= document
.getElementById('content');
117 if (xmlhttp_view
.readyState
== 4) {
118 container
.innerHTML
=xmlhttp_view
.responseText
;
122 function refetch_callback() {
124 if (xmlhttp_rpc
.readyState
== 4) {
125 notify("All feeds updated");
126 var container
= document
.getElementById('feeds');
127 container
.innerHTML
= xmlhttp_rpc
.responseText
;
128 document
.title
= "Tiny Tiny RSS";
132 function scheduleFeedUpdate(force
) {
134 notify("Updating feeds in background...");
136 document
.title
= "Tiny Tiny RSS - Updating...";
138 var query_str
= "backend.php?op=rpc&subop=";
141 query_str
= query_str
+ "forceUpdateAllFeeds";
143 query_str
= query_str
+ "updateAllFeeds";
146 if (xmlhttp_ready(xmlhttp_rpc
)) {
147 xmlhttp_rpc
.open("GET", query_str
, true);
148 xmlhttp_rpc
.onreadystatechange
=refetch_callback
;
149 xmlhttp_rpc
.send(null);
155 function updateFeedList(silent
, fetch
) {
157 if (silent
!= true) {
158 notify("Loading feed list...");
161 var query_str
= "backend.php?op=feeds";
163 if (fetch
) query_str
= query_str
+ "&fetch=yes";
165 if (xmlhttp_ready(xmlhttp
)) {
166 xmlhttp
.open("GET", query_str
, true);
167 xmlhttp
.onreadystatechange
=feedlist_callback
;
174 function catchupPage(feed
) {
176 if (!xmlhttp_ready(xmlhttp
)) {
181 var content
= document
.getElementById("headlinesList");
183 var rows
= new Array();
185 for (i
= 0; i
< content
.rows
.length
; i
++) {
186 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
187 if (row_id
.length
> 0) {
188 if (content
.rows
[i
].className
.match("Unread")) {
190 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Unread", "");
195 if (rows
.length
> 0) {
197 var feedr
= document
.getElementById("FEEDR-" + feed
);
198 var feedu
= document
.getElementById("FEEDU-" + feed
);
200 feedu
.innerHTML
= feedu
.innerHTML
- rows
.length
;
202 if (feedu
.innerHTML
> 0 && !feedr
.className
.match("Unread")) {
203 feedr
.className
= feedr
.className
+ "Unread";
204 } else if (feedu
.innerHTML
<= 0) {
205 feedr
.className
= feedr
.className
.replace("Unread", "");
208 var query_str
= "backend.php?op=rpc&subop=catchupPage&ids=" +
209 param_escape(rows
.toString());
211 notify("Marking this page as read...");
213 xmlhttp
.open("GET", query_str
, true);
214 xmlhttp
.onreadystatechange
=notify_callback
;
218 notify("No unread items on this page.");
223 function catchupAllFeeds() {
225 if (!xmlhttp_ready(xmlhttp
)) {
229 var query_str
= "backend.php?op=feeds&subop=catchupAll";
231 notify("Marking all feeds as read...");
233 xmlhttp
.open("GET", query_str
, true);
234 xmlhttp
.onreadystatechange
=feedlist_callback
;
239 function viewfeed(feed
, skip
, subop
) {
243 var searchbox
= document
.getElementById("searchbox");
246 search_query
= searchbox
.value
;
251 /* if (active_feed_id == feed && subop != "ForceUpdate") {
252 notify("This feed is currently selected.");
256 if (skip
< 0 || skip
> total_feed_entries
) {
260 if (!xmlhttp_ready(xmlhttp
)) {
265 if (active_feed_id
!= feed
|| skip
!= active_offset
) {
266 active_post_id
= false;
269 active_feed_id
= feed
;
270 active_offset
= skip
;
272 var query
= "backend.php?op=viewfeed&feed=" + param_escape(feed
) +
273 "&skip=" + param_escape(skip
) + "&subop=" + param_escape(subop
);
275 if (search_query
!= "") {
276 query
= query
+ "&search=" + param_escape(search_query
);
279 xmlhttp
.open("GET", query
, true);
280 xmlhttp
.onreadystatechange
=viewfeed_callback
;
283 notify("Loading headlines...");
287 function markHeadline(id
) {
288 var row
= document
.getElementById("RROW-" + id
);
290 row
.className
= row
.className
+ "Selected";
294 function cleanSelected(element
) {
295 var content
= document
.getElementById(element
);
297 var rows
= new Array();
299 for (i
= 0; i
< content
.rows
.length
; i
++) {
300 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
305 function view(id
,feed_id
) {
309 if (!xmlhttp_ready(xmlhttp_view
)) {
314 var crow
= document
.getElementById("RROW-" + id
);
316 if (crow
.className
.match("Unread")) {
317 var umark
= document
.getElementById("FEEDU-" + feed_id
);
318 umark
.innerHTML
= umark
.innerHTML
- 1;
319 crow
.className
= crow
.className
.replace("Unread", "");
321 if (umark
.innerHTML
== "0") {
322 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
323 feedr
.className
= feedr
.className
.replace("Unread", "");
329 cleanSelected("headlinesList");
331 crow
.className
= crow
.className
+ "Selected";
333 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
336 upd_img_pic
.innerHTML
= "";
339 // document.getElementById('content').innerHTML='Loading, please wait...';
343 xmlhttp_view
.open("GET", "backend.php?op=view&id=" + param_escape(id
), true);
344 xmlhttp_view
.onreadystatechange
=view_callback
;
345 xmlhttp_view
.send(null);
351 scheduleFeedUpdate(true);
352 setTimeout("timeout()", 1800*1000);
355 function resetSearch() {
356 document
.getElementById("searchbox").value
= "";
357 viewfeed(active_feed_id
, 0, "");
360 function search(feed
) {
361 viewfeed(feed
, 0, "");
364 function localPiggieFunction(enable
) {
366 var query_str
= "backend.php?op=feeds&subop=piggie";
368 if (xmlhttp_ready(xmlhttp
)) {
370 xmlhttp
.open("GET", query_str
, true);
371 xmlhttp
.onreadystatechange
=feedlist_callback
;
377 function relativeid_callback() {
379 if (xmlhttp_rpc
.readyState
== 4) {
380 notify(xmlhttp_rpc
.responseText
);
385 function getVisibleHeadlineIds() {
387 var content
= document
.getElementById("headlinesList");
389 var rows
= new Array();
391 for (i
= 0; i
< content
.rows
.length
; i
++) {
392 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
393 if (row_id
.length
> 0) {
400 function getFirstVisibleHeadlineId() {
401 var rows
= getVisibleHeadlineIds();
405 function getLastVisibleHeadlineId() {
406 var rows
= getVisibleHeadlineIds();
407 return rows
[rows
.length
-1];
410 function moveToPost(mode
) {
412 var rows
= getVisibleHeadlineIds();
417 if (active_post_id
== false) {
418 next_id
= getFirstVisibleHeadlineId();
419 prev_id
= getLastVisibleHeadlineId();
421 for (var i
= 0; i
< rows
.length
; i
++) {
422 if (rows
[i
] == active_post_id
) {
429 var content
= document
.getElementById("headlinesList");
431 if (mode
== "next") {
432 if (next_id
!= undefined) {
433 view(next_id
, active_feed_id
);
435 _viewfeed_autoselect_first
= true;
436 viewfeed(active_feed_id
, active_offset
+15);
440 if (mode
== "prev") {
441 if ( prev_id
!= undefined) {
442 view(prev_id
, active_feed_id
);
444 _viewfeed_autoselect_last
= true;
445 viewfeed(active_feed_id
, active_offset
-15);
451 function localHotkeyHandler(keycode
) {
454 return moveToPost('next');
458 return moveToPost('prev');
462 return scheduleFeedUpdate(true);
466 return viewfeed(active_feed_id
, active_offset
, "ForceUpdate");
469 // notify("KC: " + keycode);
478 if (xmlhttp
&& !xmlhttp_rpc
) {
479 xmlhttp_rpc
= xmlhttp
;
480 xmlhttp_view
= xmlhttp
;
483 if (!xmlhttp
|| !xmlhttp_rpc
|| !xmlhttp_view
) {
484 document
.getElementById("headlines").innerHTML
=
485 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
486 "to function properly. Your browser doesn't seem to support it.";
490 updateFeedList(false, false);
491 document
.onkeydown
= hotkey_handler
;
492 setTimeout("timeout()", 1800*1000);