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
;
113 function view_callback() {
114 var container
= document
.getElementById('content');
115 if (xmlhttp_view
.readyState
== 4) {
116 container
.innerHTML
=xmlhttp_view
.responseText
;
120 function refetch_callback() {
122 if (xmlhttp_rpc
.readyState
== 4) {
123 notify("All feeds updated");
124 var container
= document
.getElementById('feeds');
125 container
.innerHTML
= xmlhttp_rpc
.responseText
;
126 document
.title
= "Tiny Tiny RSS";
130 function scheduleFeedUpdate(force
) {
132 notify("Updating feeds in background...");
134 document
.title
= "Tiny Tiny RSS - Updating...";
136 var query_str
= "backend.php?op=rpc&subop=";
139 query_str
= query_str
+ "forceUpdateAllFeeds";
141 query_str
= query_str
+ "updateAllFeeds";
144 if (xmlhttp_ready(xmlhttp_rpc
)) {
145 xmlhttp_rpc
.open("GET", query_str
, true);
146 xmlhttp_rpc
.onreadystatechange
=refetch_callback
;
147 xmlhttp_rpc
.send(null);
153 function updateFeedList(silent
, fetch
) {
155 if (silent
!= true) {
156 notify("Loading feed list...");
159 var query_str
= "backend.php?op=feeds";
161 if (fetch
) query_str
= query_str
+ "&fetch=yes";
163 if (xmlhttp_ready(xmlhttp
)) {
164 xmlhttp
.open("GET", query_str
, true);
165 xmlhttp
.onreadystatechange
=feedlist_callback
;
172 function catchupPage(feed
) {
174 if (!xmlhttp_ready(xmlhttp
)) {
179 var content
= document
.getElementById("headlinesList");
181 var rows
= new Array();
183 for (i
= 0; i
< content
.rows
.length
; i
++) {
184 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
185 if (row_id
.length
> 0) {
186 if (content
.rows
[i
].className
.match("Unread")) {
188 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Unread", "");
193 if (rows
.length
> 0) {
195 var feedr
= document
.getElementById("FEEDR-" + feed
);
196 var feedu
= document
.getElementById("FEEDU-" + feed
);
198 feedu
.innerHTML
= feedu
.innerHTML
- rows
.length
;
200 if (feedu
.innerHTML
> 0 && !feedr
.className
.match("Unread")) {
201 feedr
.className
= feedr
.className
+ "Unread";
202 } else if (feedu
.innerHTML
<= 0) {
203 feedr
.className
= feedr
.className
.replace("Unread", "");
206 var query_str
= "backend.php?op=rpc&subop=catchupPage&ids=" +
207 param_escape(rows
.toString());
209 notify("Marking this page as read...");
211 xmlhttp
.open("GET", query_str
, true);
212 xmlhttp
.onreadystatechange
=notify_callback
;
216 notify("No unread items on this page.");
221 function catchupAllFeeds() {
223 if (!xmlhttp_ready(xmlhttp
)) {
227 var query_str
= "backend.php?op=feeds&subop=catchupAll";
229 notify("Marking all feeds as read...");
231 xmlhttp
.open("GET", query_str
, true);
232 xmlhttp
.onreadystatechange
=feedlist_callback
;
237 function viewfeed(feed
, skip
, subop
) {
241 var searchbox
= document
.getElementById("searchbox");
244 search_query
= searchbox
.value
;
249 /* if (active_feed_id == feed && subop != "ForceUpdate") {
250 notify("This feed is currently selected.");
254 if (skip
< 0 || skip
> total_feed_entries
) {
258 if (!xmlhttp_ready(xmlhttp
)) {
263 active_feed_id
= feed
;
264 active_post_id
= false;
265 active_offset
= skip
;
267 var query
= "backend.php?op=viewfeed&feed=" + param_escape(feed
) +
268 "&skip=" + param_escape(skip
) + "&subop=" + param_escape(subop
);
270 if (search_query
!= "") {
271 query
= query
+ "&search=" + param_escape(search_query
);
274 xmlhttp
.open("GET", query
, true);
275 xmlhttp
.onreadystatechange
=viewfeed_callback
;
278 notify("Loading headlines...");
282 function cleanSelected(element
) {
283 var content
= document
.getElementById(element
);
285 var rows
= new Array();
287 for (i
= 0; i
< content
.rows
.length
; i
++) {
288 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
293 function view(id
,feed_id
) {
297 if (!xmlhttp_ready(xmlhttp_view
)) {
302 var crow
= document
.getElementById("RROW-" + id
);
304 if (crow
.className
.match("Unread")) {
305 var umark
= document
.getElementById("FEEDU-" + feed_id
);
306 umark
.innerHTML
= umark
.innerHTML
- 1;
307 crow
.className
= crow
.className
.replace("Unread", "");
309 if (umark
.innerHTML
== "0") {
310 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
311 feedr
.className
= feedr
.className
.replace("Unread", "");
317 cleanSelected("headlinesList");
319 crow
.className
= crow
.className
+ "Selected";
321 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
324 upd_img_pic
.innerHTML
= "";
327 document
.getElementById('content').innerHTML
='Loading, please wait...';
331 xmlhttp_view
.open("GET", "backend.php?op=view&id=" + param_escape(id
), true);
332 xmlhttp_view
.onreadystatechange
=view_callback
;
333 xmlhttp_view
.send(null);
339 scheduleFeedUpdate(true);
340 setTimeout("timeout()", 1800*1000);
343 function resetSearch() {
344 document
.getElementById("searchbox").value
= "";
345 viewfeed(active_feed_id
, 0, "");
348 function search(feed
) {
349 viewfeed(feed
, 0, "");
352 function localPiggieFunction(enable
) {
354 var query_str
= "backend.php?op=feeds&subop=piggie";
356 if (xmlhttp_ready(xmlhttp
)) {
358 xmlhttp
.open("GET", query_str
, true);
359 xmlhttp
.onreadystatechange
=feedlist_callback
;
365 function relativeid_callback() {
367 if (xmlhttp_rpc
.readyState
== 4) {
368 notify(xmlhttp_rpc
.responseText
);
373 function getVisibleHeadlineIds() {
375 var content
= document
.getElementById("headlinesList");
377 var rows
= new Array();
379 for (i
= 0; i
< content
.rows
.length
; i
++) {
380 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
381 if (row_id
.length
> 0) {
388 function getFirstVisibleHeadlineId() {
389 var rows
= getVisibleHeadlineIds();
393 function getLastVisibleHeadlineId() {
394 var rows
= getVisibleHeadlineIds();
395 return rows
[rows
.length
-1];
398 function moveToPost(mode
) {
400 var rows
= getVisibleHeadlineIds();
405 if (active_post_id
== false) {
406 next_id
= getFirstVisibleHeadlineId();
407 prev_id
= getLastVisibleHeadlineId();
409 for (var i
= 0; i
< rows
.length
; i
++) {
410 if (rows
[i
] == active_post_id
) {
417 var content
= document
.getElementById("headlinesList");
419 if (mode
== "next") {
420 if (next_id
!= undefined) {
421 view(next_id
, active_feed_id
);
423 _viewfeed_autoselect_first
= true;
424 viewfeed(active_feed_id
, active_offset
+15);
428 if (mode
== "prev") {
429 if ( prev_id
!= undefined) {
430 view(prev_id
, active_feed_id
);
432 _viewfeed_autoselect_last
= true;
433 viewfeed(active_feed_id
, active_offset
-15);
439 function localHotkeyHandler(keycode
) {
442 return moveToPost('next');
446 return moveToPost('prev');
450 return scheduleFeedUpdate(true);
454 return viewfeed(active_feed_id
, active_offset
, "ForceUpdate");
457 // notify("KC: " + keycode);
466 if (xmlhttp
&& !xmlhttp_rpc
) {
467 xmlhttp_rpc
= xmlhttp
;
468 xmlhttp_view
= xmlhttp
;
471 if (!xmlhttp
|| !xmlhttp_rpc
|| !xmlhttp_view
) {
472 document
.getElementById("headlines").innerHTML
=
473 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
474 "to function properly. Your browser doesn't seem to support it.";
478 updateFeedList(false, false);
479 document
.onkeydown
= hotkey_handler
;
480 setTimeout("timeout()", 1800*1000);