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
;
119 markHeadline(active_post_id
);
123 function refetch_callback() {
125 if (xmlhttp_rpc
.readyState
== 4) {
126 notify("All feeds updated");
127 var container
= document
.getElementById('feeds');
128 container
.innerHTML
= xmlhttp_rpc
.responseText
;
129 document
.title
= "Tiny Tiny RSS";
133 function scheduleFeedUpdate(force
) {
135 notify("Updating feeds in background...");
137 document
.title
= "Tiny Tiny RSS - Updating...";
139 var query_str
= "backend.php?op=rpc&subop=";
142 query_str
= query_str
+ "forceUpdateAllFeeds";
144 query_str
= query_str
+ "updateAllFeeds";
147 if (xmlhttp_ready(xmlhttp_rpc
)) {
148 xmlhttp_rpc
.open("GET", query_str
, true);
149 xmlhttp_rpc
.onreadystatechange
=refetch_callback
;
150 xmlhttp_rpc
.send(null);
156 function updateFeedList(silent
, fetch
) {
158 if (silent
!= true) {
159 notify("Loading feed list...");
162 var query_str
= "backend.php?op=feeds";
164 if (fetch
) query_str
= query_str
+ "&fetch=yes";
166 if (xmlhttp_ready(xmlhttp
)) {
167 xmlhttp
.open("GET", query_str
, true);
168 xmlhttp
.onreadystatechange
=feedlist_callback
;
175 function catchupPage(feed
) {
177 if (!xmlhttp_ready(xmlhttp
)) {
182 var content
= document
.getElementById("headlinesList");
184 var rows
= new Array();
186 for (i
= 0; i
< content
.rows
.length
; i
++) {
187 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
188 if (row_id
.length
> 0) {
189 if (content
.rows
[i
].className
.match("Unread")) {
191 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Unread", "");
196 if (rows
.length
> 0) {
198 var feedr
= document
.getElementById("FEEDR-" + feed
);
199 var feedu
= document
.getElementById("FEEDU-" + feed
);
201 feedu
.innerHTML
= feedu
.innerHTML
- rows
.length
;
203 if (feedu
.innerHTML
> 0 && !feedr
.className
.match("Unread")) {
204 feedr
.className
= feedr
.className
+ "Unread";
205 } else if (feedu
.innerHTML
<= 0) {
206 feedr
.className
= feedr
.className
.replace("Unread", "");
209 var query_str
= "backend.php?op=rpc&subop=catchupPage&ids=" +
210 param_escape(rows
.toString());
212 notify("Marking this page as read...");
214 var button
= document
.getElementById("btnCatchupPage");
216 button
.className
= "disabledButton";
219 xmlhttp
.open("GET", query_str
, true);
220 xmlhttp
.onreadystatechange
=notify_callback
;
224 notify("No unread items on this page.");
229 function catchupAllFeeds() {
231 if (!xmlhttp_ready(xmlhttp
)) {
235 var query_str
= "backend.php?op=feeds&subop=catchupAll";
237 notify("Marking all feeds as read...");
239 xmlhttp
.open("GET", query_str
, true);
240 xmlhttp
.onreadystatechange
=feedlist_callback
;
245 function viewfeed(feed
, skip
, subop
) {
249 var searchbox
= document
.getElementById("searchbox");
252 search_query
= searchbox
.value
;
257 /* if (active_feed_id == feed && subop != "ForceUpdate") {
258 notify("This feed is currently selected.");
262 if (skip
< 0 || skip
> total_feed_entries
) {
266 if (!xmlhttp_ready(xmlhttp
)) {
271 if (active_feed_id
!= feed
|| skip
!= active_offset
) {
272 active_post_id
= false;
275 active_feed_id
= feed
;
276 active_offset
= skip
;
278 var query
= "backend.php?op=viewfeed&feed=" + param_escape(feed
) +
279 "&skip=" + param_escape(skip
) + "&subop=" + param_escape(subop
);
281 if (search_query
!= "") {
282 query
= query
+ "&search=" + param_escape(search_query
);
285 xmlhttp
.open("GET", query
, true);
286 xmlhttp
.onreadystatechange
=viewfeed_callback
;
289 notify("Loading headlines...");
293 function markHeadline(id
) {
294 var row
= document
.getElementById("RROW-" + id
);
296 row
.className
= row
.className
+ "Selected";
300 function cleanSelected(element
) {
301 var content
= document
.getElementById(element
);
303 var rows
= new Array();
305 for (i
= 0; i
< content
.rows
.length
; i
++) {
306 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
311 function view(id
,feed_id
) {
315 if (!xmlhttp_ready(xmlhttp_view
)) {
320 var crow
= document
.getElementById("RROW-" + id
);
322 if (crow
.className
.match("Unread")) {
323 var umark
= document
.getElementById("FEEDU-" + feed_id
);
324 umark
.innerHTML
= umark
.innerHTML
- 1;
325 crow
.className
= crow
.className
.replace("Unread", "");
327 if (umark
.innerHTML
== "0") {
328 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
329 feedr
.className
= feedr
.className
.replace("Unread", "");
335 cleanSelected("headlinesList");
336 // crow.className = crow.className + "Selected";
338 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
341 upd_img_pic
.innerHTML
= "";
344 // document.getElementById('content').innerHTML='Loading, please wait...';
348 xmlhttp_view
.open("GET", "backend.php?op=view&id=" + param_escape(id
), true);
349 xmlhttp_view
.onreadystatechange
=view_callback
;
350 xmlhttp_view
.send(null);
356 scheduleFeedUpdate(true);
357 setTimeout("timeout()", 1800*1000);
360 function resetSearch() {
361 document
.getElementById("searchbox").value
= "";
362 viewfeed(active_feed_id
, 0, "");
365 function search(feed
) {
366 viewfeed(feed
, 0, "");
369 function localPiggieFunction(enable
) {
371 var query_str
= "backend.php?op=feeds&subop=piggie";
373 if (xmlhttp_ready(xmlhttp
)) {
375 xmlhttp
.open("GET", query_str
, true);
376 xmlhttp
.onreadystatechange
=feedlist_callback
;
382 function relativeid_callback() {
384 if (xmlhttp_rpc
.readyState
== 4) {
385 notify(xmlhttp_rpc
.responseText
);
390 function getVisibleHeadlineIds() {
392 var content
= document
.getElementById("headlinesList");
394 var rows
= new Array();
396 for (i
= 0; i
< content
.rows
.length
; i
++) {
397 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
398 if (row_id
.length
> 0) {
405 function getFirstVisibleHeadlineId() {
406 var rows
= getVisibleHeadlineIds();
410 function getLastVisibleHeadlineId() {
411 var rows
= getVisibleHeadlineIds();
412 return rows
[rows
.length
-1];
415 function moveToPost(mode
) {
417 var rows
= getVisibleHeadlineIds();
422 if (active_post_id
== false) {
423 next_id
= getFirstVisibleHeadlineId();
424 prev_id
= getLastVisibleHeadlineId();
426 for (var i
= 0; i
< rows
.length
; i
++) {
427 if (rows
[i
] == active_post_id
) {
434 if (mode
== "next") {
435 if (next_id
!= undefined) {
436 view(next_id
, active_feed_id
);
438 _viewfeed_autoselect_first
= true;
439 viewfeed(active_feed_id
, active_offset
+15);
443 if (mode
== "prev") {
444 if ( prev_id
!= undefined) {
445 view(prev_id
, active_feed_id
);
447 _viewfeed_autoselect_last
= true;
448 viewfeed(active_feed_id
, active_offset
-15);
454 function localHotkeyHandler(keycode
) {
457 return moveToPost('next');
461 return moveToPost('prev');
465 return scheduleFeedUpdate(true);
469 return viewfeed(active_feed_id
, active_offset
, "ForceUpdate");
472 // notify("KC: " + keycode);
481 if (xmlhttp
&& !xmlhttp_rpc
) {
482 xmlhttp_rpc
= xmlhttp
;
483 xmlhttp_view
= xmlhttp
;
486 if (!xmlhttp
|| !xmlhttp_rpc
|| !xmlhttp_view
) {
487 document
.getElementById("headlines").innerHTML
=
488 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
489 "to function properly. Your browser doesn't seem to support it.";
493 updateFeedList(false, false);
494 document
.onkeydown
= hotkey_handler
;
495 setTimeout("timeout()", 1800*1000);