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", "");
229 var upd_img_pic
= document
.getElementById("FUPDPIC-" + row_id
);
231 upd_img_pic
.innerHTML
= "";
236 if (rows
.length
> 0) {
238 var feedr
= document
.getElementById("FEEDR-" + feed
);
239 var feedu
= document
.getElementById("FEEDU-" + feed
);
241 feedu
.innerHTML
= feedu
.innerHTML
- rows
.length
;
243 if (feedu
.innerHTML
> 0 && !feedr
.className
.match("Unread")) {
244 feedr
.className
= feedr
.className
+ "Unread";
245 } else if (feedu
.innerHTML
<= 0) {
246 feedr
.className
= feedr
.className
.replace("Unread", "");
249 var query_str
= "backend.php?op=rpc&subop=catchupPage&ids=" +
250 param_escape(rows
.toString());
252 notify("Marking this page as read...");
254 var button
= document
.getElementById("btnCatchupPage");
257 button
.className
= "disabledButton";
261 xmlhttp
.open("GET", query_str
, true);
262 xmlhttp
.onreadystatechange
=notify_callback
;
266 notify("No unread items on this page.");
271 function catchupAllFeeds() {
273 if (!xmlhttp_ready(xmlhttp
)) {
277 var query_str
= "backend.php?op=feeds&subop=catchupAll";
279 notify("Marking all feeds as read...");
281 xmlhttp
.open("GET", query_str
, true);
282 xmlhttp
.onreadystatechange
=feedlist_callback
;
287 function viewfeed(feed
, skip
, subop
) {
291 var searchbox
= document
.getElementById("searchbox");
294 search_query
= searchbox
.value
;
299 var viewbox
= document
.getElementById("viewbox");
304 view_mode
= viewbox
.value
;
306 view_mode
= "All Posts";
309 /* if (active_feed_id == feed && subop != "ForceUpdate") {
310 notify("This feed is currently selected.");
314 if (skip
< 0 || skip
> total_feed_entries
) {
318 if (!xmlhttp_ready(xmlhttp
)) {
323 if (active_feed_id
!= feed
|| skip
!= active_offset
) {
324 active_post_id
= false;
327 active_feed_id
= feed
;
328 active_offset
= skip
;
330 var query
= "backend.php?op=viewfeed&feed=" + param_escape(feed
) +
331 "&skip=" + param_escape(skip
) + "&subop=" + param_escape(subop
) +
332 "&view=" + param_escape(view_mode
);
334 if (search_query
!= "") {
335 query
= query
+ "&search=" + param_escape(search_query
);
338 xmlhttp
.open("GET", query
, true);
339 xmlhttp
.onreadystatechange
=viewfeed_callback
;
342 notify("Loading headlines...");
346 function markHeadline(id
) {
347 var row
= document
.getElementById("RROW-" + id
);
349 row
.className
= row
.className
+ "Selected";
353 function getFeedIds() {
354 var content
= document
.getElementById("feedsList");
356 var rows
= new Array();
358 for (i
= 0; i
< content
.rows
.length
; i
++) {
359 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
368 function cleanSelected(element
) {
369 var content
= document
.getElementById(element
);
371 var rows
= new Array();
373 for (i
= 0; i
< content
.rows
.length
; i
++) {
374 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
379 function view(id
,feed_id
) {
383 if (!xmlhttp_ready(xmlhttp_view
)) {
388 var crow
= document
.getElementById("RROW-" + id
);
390 if (crow
.className
.match("Unread")) {
391 var umark
= document
.getElementById("FEEDU-" + feed_id
);
392 umark
.innerHTML
= umark
.innerHTML
- 1;
393 crow
.className
= crow
.className
.replace("Unread", "");
395 if (umark
.innerHTML
== "0") {
396 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
397 feedr
.className
= feedr
.className
.replace("Unread", "");
403 cleanSelected("headlinesList");
404 // crow.className = crow.className + "Selected";
406 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
409 upd_img_pic
.innerHTML
= "";
412 // document.getElementById('content').innerHTML='Loading, please wait...';
414 var unread_rows
= getVisibleUnreadHeadlines();
416 if (unread_rows
.length
== 0) {
417 var button
= document
.getElementById("btnCatchupPage");
419 button
.className
= "disabledButton";
426 xmlhttp_view
.open("GET", "backend.php?op=view&id=" + param_escape(id
), true);
427 xmlhttp_view
.onreadystatechange
=view_callback
;
428 xmlhttp_view
.send(null);
434 scheduleFeedUpdate(true);
435 setTimeout("timeout()", 1800*1000);
438 function resetSearch() {
439 document
.getElementById("searchbox").value
= "";
440 viewfeed(active_feed_id
, 0, "");
443 function search(feed
) {
444 viewfeed(feed
, 0, "");
447 function localPiggieFunction(enable
) {
449 var query_str
= "backend.php?op=feeds&subop=piggie";
451 if (xmlhttp_ready(xmlhttp
)) {
453 xmlhttp
.open("GET", query_str
, true);
454 xmlhttp
.onreadystatechange
=feedlist_callback
;
460 function relativeid_callback() {
462 if (xmlhttp_rpc
.readyState
== 4) {
463 notify(xmlhttp_rpc
.responseText
);
468 function getVisibleUnreadHeadlines() {
469 var content
= document
.getElementById("headlinesList");
471 var rows
= new Array();
473 for (i
= 0; i
< content
.rows
.length
; i
++) {
474 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
475 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
482 function getVisibleHeadlineIds() {
484 var content
= document
.getElementById("headlinesList");
486 var rows
= new Array();
488 for (i
= 0; i
< content
.rows
.length
; i
++) {
489 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
490 if (row_id
.length
> 0) {
497 function getFirstVisibleHeadlineId() {
498 var rows
= getVisibleHeadlineIds();
502 function getLastVisibleHeadlineId() {
503 var rows
= getVisibleHeadlineIds();
504 return rows
[rows
.length
-1];
507 function moveToPost(mode
) {
509 var rows
= getVisibleHeadlineIds();
514 if (active_post_id
== false) {
515 next_id
= getFirstVisibleHeadlineId();
516 prev_id
= getLastVisibleHeadlineId();
518 for (var i
= 0; i
< rows
.length
; i
++) {
519 if (rows
[i
] == active_post_id
) {
526 if (mode
== "next") {
527 if (next_id
!= undefined) {
528 view(next_id
, active_feed_id
);
530 _viewfeed_autoselect_first
= true;
531 viewfeed(active_feed_id
, active_offset
+15);
535 if (mode
== "prev") {
536 if ( prev_id
!= undefined) {
537 view(prev_id
, active_feed_id
);
539 _viewfeed_autoselect_last
= true;
540 viewfeed(active_feed_id
, active_offset
-15);
546 function localHotkeyHandler(keycode
) {
549 return moveToPost('next');
553 return moveToPost('prev');
557 return scheduleFeedUpdate(true);
561 return viewfeed(active_feed_id
, active_offset
, "ForceUpdate");
564 // notify("KC: " + keycode);
568 function toggleMark(id
, toggle
) {
570 // notify("Toggle mark: " + id + ", " + toggle);
572 if (!xmlhttp_ready(xmlhttp_rpc
)) {
577 var mark_img
= document
.getElementById("FMARKPIC-" + id
);
579 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
581 if (toggle
== true) {
582 mark_img
.src
= "images/mark_set.png";
583 mark_img
.alt
= "Reset mark";
584 mark_img
.setAttribute('onclick', 'javascript:toggleMark('+id
+', false)');
585 query
= query
+ "&mark=1";
587 mark_img
.src
= "images/mark_unset.png";
588 mark_img
.alt
= "Set mark";
589 mark_img
.setAttribute('onclick', 'javascript:toggleMark('+id
+', true)');
590 query
= query
+ "&mark=0";
593 xmlhttp_rpc
.open("GET", query
, true);
594 xmlhttp_rpc
.onreadystatechange
=rpc_notify_callback
;
595 xmlhttp_rpc
.send(null);
603 if (xmlhttp
&& !xmlhttp_rpc
) {
604 xmlhttp_rpc
= xmlhttp
;
605 xmlhttp_view
= xmlhttp
;
608 if (!xmlhttp
|| !xmlhttp_rpc
|| !xmlhttp_view
) {
609 document
.getElementById("headlines").innerHTML
=
610 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
611 "to function properly. Your browser doesn't seem to support it.";
615 updateFeedList(false, false);
616 document
.onkeydown
= hotkey_handler
;
617 setTimeout("timeout()", 1800*1000);