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;
25 var search_query
= "";
28 /*@if (@_jscript_version >= 5)
29 // JScript gives us Conditional compilation, we can cope with old IE versions.
30 // and security blocked creation of the objects.
32 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
35 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
36 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
37 xmlhttp_view = new ActiveXObject("Microsoft.XMLHTTP");
46 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
47 xmlhttp
= new XMLHttpRequest();
48 xmlhttp_rpc
= new XMLHttpRequest();
49 xmlhttp_view
= new XMLHttpRequest();
52 function feedlist_callback() {
53 var container
= document
.getElementById('feeds');
54 if (xmlhttp
.readyState
== 4) {
55 container
.innerHTML
=xmlhttp
.responseText
;
58 scheduleFeedUpdate(false);
66 function feed_update_callback() {
67 if (xmlhttp_rpc
.readyState
== 4) {
68 var result
= xmlhttp_rpc
.responseText
;
70 updateFeed(_update_ids
.shift());
74 function viewfeed_callback() {
75 var container
= document
.getElementById('headlines');
76 if (xmlhttp
.readyState
== 4) {
77 container
.innerHTML
= xmlhttp
.responseText
;
79 var factive
= document
.getElementById("FACTIVE");
80 var funread
= document
.getElementById("FUNREAD");
81 var ftotal
= document
.getElementById("FTOTAL");
83 if (_viewfeed_autoselect_first
== true) {
84 _viewfeed_autoselect_first
= false;
85 view(getFirstVisibleHeadlineId(), active_feed_id
);
88 if (_viewfeed_autoselect_last
== true) {
89 _viewfeed_autoselect_last
= false;
90 view(getLastVisibleHeadlineId(), active_feed_id
);
93 if (ftotal
&& factive
&& funread
) {
94 var feed_id
= factive
.innerHTML
;
96 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
97 var feedt
= document
.getElementById("FEEDT-" + feed_id
);
98 var feedu
= document
.getElementById("FEEDU-" + feed_id
);
100 feedt
.innerHTML
= ftotal
.innerHTML
;
101 feedu
.innerHTML
= funread
.innerHTML
;
103 total_feed_entries
= ftotal
.innerHTML
;
105 if (feedu
.innerHTML
> 0 && !feedr
.className
.match("Unread")) {
106 feedr
.className
= feedr
.className
+ "Unread";
107 } else if (feedu
.innerHTML
<= 0) {
108 feedr
.className
= feedr
.className
.replace("Unread", "");
111 cleanSelected("feedsList");
113 feedr
.className
= feedr
.className
+ "Selected";
116 var searchbox
= document
.getElementById("searchbox");
117 searchbox
.value
= search_query
;
119 markHeadline(active_post_id
);
126 function view_callback() {
127 var container
= document
.getElementById('content');
128 if (xmlhttp_view
.readyState
== 4) {
129 container
.innerHTML
=xmlhttp_view
.responseText
;
130 markHeadline(active_post_id
);
134 function refetch_callback() {
136 if (xmlhttp_rpc
.readyState
== 4) {
137 notify("All feeds updated");
138 var container
= document
.getElementById('feeds');
139 container
.innerHTML
= xmlhttp_rpc
.responseText
;
140 document
.title
= "Tiny Tiny RSS";
144 function updateFeed(feed_id
) {
146 var query_str
= "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id
;
148 if (xmlhttp_ready(xmlhttp_rpc
)) {
149 xmlhttp_rpc
.open("GET", query_str
, true);
150 xmlhttp_rpc
.onreadystatechange
=feed_update_callback
;
151 xmlhttp_rpc
.send(null);
158 function scheduleSepFeedUpdate(force
) {
159 notify("Updating feeds in background (M2)...");
161 _update_ids
= getFeedIds();
162 _update_num_ids
= _update_ids
.length
;
164 updateFeed(_update_ids
.pop());
168 function scheduleFeedUpdate(force
) {
170 notify("Updating feeds in background...");
172 document
.title
= "Tiny Tiny RSS - Updating...";
174 var query_str
= "backend.php?op=rpc&subop=";
177 query_str
= query_str
+ "forceUpdateAllFeeds";
179 query_str
= query_str
+ "updateAllFeeds";
182 if (xmlhttp_ready(xmlhttp_rpc
)) {
183 xmlhttp_rpc
.open("GET", query_str
, true);
184 xmlhttp_rpc
.onreadystatechange
=refetch_callback
;
185 xmlhttp_rpc
.send(null);
191 function updateFeedList(silent
, fetch
) {
193 if (silent
!= true) {
194 notify("Loading feed list...");
197 var query_str
= "backend.php?op=feeds";
199 if (fetch
) query_str
= query_str
+ "&fetch=yes";
201 if (xmlhttp_ready(xmlhttp
)) {
202 xmlhttp
.open("GET", query_str
, true);
203 xmlhttp
.onreadystatechange
=feedlist_callback
;
210 function catchupPage(feed
) {
212 if (!xmlhttp_ready(xmlhttp
)) {
217 var content
= document
.getElementById("headlinesList");
219 var rows
= new Array();
221 for (i
= 0; i
< content
.rows
.length
; i
++) {
222 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
223 if (row_id
.length
> 0) {
224 if (content
.rows
[i
].className
.match("Unread")) {
226 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Unread", "");
231 if (rows
.length
> 0) {
233 var feedr
= document
.getElementById("FEEDR-" + feed
);
234 var feedu
= document
.getElementById("FEEDU-" + feed
);
236 feedu
.innerHTML
= feedu
.innerHTML
- rows
.length
;
238 if (feedu
.innerHTML
> 0 && !feedr
.className
.match("Unread")) {
239 feedr
.className
= feedr
.className
+ "Unread";
240 } else if (feedu
.innerHTML
<= 0) {
241 feedr
.className
= feedr
.className
.replace("Unread", "");
244 var query_str
= "backend.php?op=rpc&subop=catchupPage&ids=" +
245 param_escape(rows
.toString());
247 notify("Marking this page as read...");
249 var button
= document
.getElementById("btnCatchupPage");
251 button
.className
= "disabledButton";
254 xmlhttp
.open("GET", query_str
, true);
255 xmlhttp
.onreadystatechange
=notify_callback
;
259 notify("No unread items on this page.");
264 function catchupAllFeeds() {
266 if (!xmlhttp_ready(xmlhttp
)) {
270 var query_str
= "backend.php?op=feeds&subop=catchupAll";
272 notify("Marking all feeds as read...");
274 xmlhttp
.open("GET", query_str
, true);
275 xmlhttp
.onreadystatechange
=feedlist_callback
;
280 function viewfeed(feed
, skip
, subop
) {
284 var searchbox
= document
.getElementById("searchbox");
287 search_query
= searchbox
.value
;
292 /* if (active_feed_id == feed && subop != "ForceUpdate") {
293 notify("This feed is currently selected.");
297 if (skip
< 0 || skip
> total_feed_entries
) {
301 if (!xmlhttp_ready(xmlhttp
)) {
306 if (active_feed_id
!= feed
|| skip
!= active_offset
) {
307 active_post_id
= false;
310 active_feed_id
= feed
;
311 active_offset
= skip
;
313 var query
= "backend.php?op=viewfeed&feed=" + param_escape(feed
) +
314 "&skip=" + param_escape(skip
) + "&subop=" + param_escape(subop
);
316 if (search_query
!= "") {
317 query
= query
+ "&search=" + param_escape(search_query
);
320 xmlhttp
.open("GET", query
, true);
321 xmlhttp
.onreadystatechange
=viewfeed_callback
;
324 notify("Loading headlines...");
328 function markHeadline(id
) {
329 var row
= document
.getElementById("RROW-" + id
);
331 row
.className
= row
.className
+ "Selected";
335 function getFeedIds() {
336 var content
= document
.getElementById("feedsList");
338 var rows
= new Array();
340 for (i
= 0; i
< content
.rows
.length
; i
++) {
341 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
350 function cleanSelected(element
) {
351 var content
= document
.getElementById(element
);
353 var rows
= new Array();
355 for (i
= 0; i
< content
.rows
.length
; i
++) {
356 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
361 function view(id
,feed_id
) {
365 if (!xmlhttp_ready(xmlhttp_view
)) {
370 var crow
= document
.getElementById("RROW-" + id
);
372 if (crow
.className
.match("Unread")) {
373 var umark
= document
.getElementById("FEEDU-" + feed_id
);
374 umark
.innerHTML
= umark
.innerHTML
- 1;
375 crow
.className
= crow
.className
.replace("Unread", "");
377 if (umark
.innerHTML
== "0") {
378 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
379 feedr
.className
= feedr
.className
.replace("Unread", "");
385 cleanSelected("headlinesList");
386 // crow.className = crow.className + "Selected";
388 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
391 upd_img_pic
.innerHTML
= "";
394 // document.getElementById('content').innerHTML='Loading, please wait...';
398 xmlhttp_view
.open("GET", "backend.php?op=view&id=" + param_escape(id
), true);
399 xmlhttp_view
.onreadystatechange
=view_callback
;
400 xmlhttp_view
.send(null);
406 scheduleFeedUpdate(true);
407 setTimeout("timeout()", 1800*1000);
410 function resetSearch() {
411 document
.getElementById("searchbox").value
= "";
412 viewfeed(active_feed_id
, 0, "");
415 function search(feed
) {
416 viewfeed(feed
, 0, "");
419 function localPiggieFunction(enable
) {
421 var query_str
= "backend.php?op=feeds&subop=piggie";
423 if (xmlhttp_ready(xmlhttp
)) {
425 xmlhttp
.open("GET", query_str
, true);
426 xmlhttp
.onreadystatechange
=feedlist_callback
;
432 function relativeid_callback() {
434 if (xmlhttp_rpc
.readyState
== 4) {
435 notify(xmlhttp_rpc
.responseText
);
440 function getVisibleHeadlineIds() {
442 var content
= document
.getElementById("headlinesList");
444 var rows
= new Array();
446 for (i
= 0; i
< content
.rows
.length
; i
++) {
447 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
448 if (row_id
.length
> 0) {
455 function getFirstVisibleHeadlineId() {
456 var rows
= getVisibleHeadlineIds();
460 function getLastVisibleHeadlineId() {
461 var rows
= getVisibleHeadlineIds();
462 return rows
[rows
.length
-1];
465 function moveToPost(mode
) {
467 var rows
= getVisibleHeadlineIds();
472 if (active_post_id
== false) {
473 next_id
= getFirstVisibleHeadlineId();
474 prev_id
= getLastVisibleHeadlineId();
476 for (var i
= 0; i
< rows
.length
; i
++) {
477 if (rows
[i
] == active_post_id
) {
484 if (mode
== "next") {
485 if (next_id
!= undefined) {
486 view(next_id
, active_feed_id
);
488 _viewfeed_autoselect_first
= true;
489 viewfeed(active_feed_id
, active_offset
+15);
493 if (mode
== "prev") {
494 if ( prev_id
!= undefined) {
495 view(prev_id
, active_feed_id
);
497 _viewfeed_autoselect_last
= true;
498 viewfeed(active_feed_id
, active_offset
-15);
504 function localHotkeyHandler(keycode
) {
507 return moveToPost('next');
511 return moveToPost('prev');
515 return scheduleFeedUpdate(true);
519 return viewfeed(active_feed_id
, active_offset
, "ForceUpdate");
522 // notify("KC: " + keycode);
531 if (xmlhttp
&& !xmlhttp_rpc
) {
532 xmlhttp_rpc
= xmlhttp
;
533 xmlhttp_view
= xmlhttp
;
536 if (!xmlhttp
|| !xmlhttp_rpc
|| !xmlhttp_view
) {
537 document
.getElementById("headlines").innerHTML
=
538 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
539 "to function properly. Your browser doesn't seem to support it.";
543 updateFeedList(false, false);
544 document
.onkeydown
= hotkey_handler
;
545 setTimeout("timeout()", 1800*1000);