2014-02-08 20:13:14 +01:00
|
|
|
var Miniflux={};Miniflux.App=function(){return{Run:function(){Miniflux.Event.ListenKeyboardEvents();Miniflux.Event.ListenMouseEvents()},MozillaAuth:function(e){navigator.id.watch({onlogin:function(a){var b=new XMLHttpRequest;b.open("POST","?action="+e+"&token="+a,!0);b.setRequestHeader("Connection","close");b.onload=function(){window.location.href=this.responseText};b.send("token="+a)},onlogout:function(){}});navigator.id.request()}}}();
|
|
|
|
Miniflux.Feed=function(){function e(b){if(b=document.getElementById("loading-feed-"+b)){var a=document.createElement("img");a.src="assets/img/refresh.gif";b.appendChild(a)}}function a(){for(var a=document.getElementsByTagName("a"),d=0,e=a.length;d<e;d++){var c=a[d].getAttribute("data-feed-id");c&&b.push(parseInt(c))}}var b=[],d=[];return{Update:function(b,a){e(b);var d=new XMLHttpRequest;d.onload=function(){var c=document.getElementById("loading-feed-"+b);c&&(c.innerHTML="");if(c=document.getElementById("last-checked-feed-"+
|
|
|
|
b))c.innerHTML=c.getAttribute("data-after-update");try{a&&a(JSON.parse(this.responseText))}catch(h){}};d.open("POST","?action=refresh-feed&feed_id="+b,!0);d.send()},UpdateAll:function(){a();var e=setInterval(function(){for(;0<b.length&&5>d.length;){var a=b.shift();d.push(a);Miniflux.Feed.Update(a,function(a){a=d.indexOf(a.feed_id);0<=a&&d.splice(a,1);0==b.length&&0==d.length&&(clearInterval(e),window.location.href="?action=unread")})}},100)}}}();
|
|
|
|
Miniflux.Item=function(){function e(c){var b=document.getElementById("item-"+c);b||(b=document.getElementById("current-item"),b.getAttribute("data-item-id")!=c&&(b=!1));return b}function a(c){if((c=document.getElementById("bookmark-"+c))&&c.getAttribute("data-reverse-label")){var b=c.innerHTML;c.innerHTML=c.getAttribute("data-reverse-label");c.setAttribute("data-reverse-label",b)}}function b(c){if(c=document.getElementById("status-"+c)){var b=c.innerHTML;c.innerHTML=c.getAttribute("data-reverse-label");
|
2014-02-15 03:37:07 +01:00
|
|
|
c.setAttribute("data-reverse-label",b)}}function d(c){"mouse"!=Miniflux.Event.lastEventType&&Miniflux.Nav.SelectNextItem();c.parentNode.removeChild(c);if(c=document.getElementById("page-counter"))counter=parseInt(c.textContent.trim(),10)-1,0==counter?window.location="?action=unread":(c.textContent=counter+" ",document.title="miniflux ("+counter+")",document.getElementById("nav-counter").textContent="("+counter+")")}function f(c){var a=new XMLHttpRequest;a.onload=function(){if(Miniflux.Nav.IsListing()){var a=
|
|
|
|
e(c);if(a)if(a.getAttribute("data-hide"))d(a);else{a.setAttribute("data-item-status","read");b(c);if(a=document.getElementById("show-"+c)){a.className="read";var h=document.createElement("span");h.id="read-icon-"+c;h.appendChild(document.createTextNode("\u2611 "));a.parentNode.insertBefore(h,a)}(a=document.getElementById("status-"+c))&&a.setAttribute("data-action","mark-unread")}}};a.open("POST","?action=mark-item-read&id="+c,!0);a.send()}function k(c){var a=new XMLHttpRequest;a.onload=function(){if(Miniflux.Nav.IsListing()){var a=
|
|
|
|
e(c);if(a)if(a.getAttribute("data-hide"))d(a);else{a.setAttribute("data-item-status","unread");b(c);if(a=document.getElementById("show-"+c))a.className="";(a=document.getElementById("read-icon-"+c))&&a.parentNode.removeChild(a);(a=document.getElementById("status-"+c))&&a.setAttribute("data-action","mark-read")}}};a.open("POST","?action=mark-item-unread&id="+c,!0);a.send()}function l(c,b){var d=c.getAttribute("data-item-id"),e=new XMLHttpRequest;e.onload=function(){c.setAttribute("data-item-bookmark",
|
|
|
|
b);if(b)if(Miniflux.Nav.IsListing()){if(g=document.getElementById("show-"+d)){var e=document.createElement("span");e.id="bookmark-icon-"+d;e.appendChild(document.createTextNode("\u2605 "));g.parentNode.insertBefore(e,g)}a(d)}else{var g=document.getElementById("bookmark-"+d);g&&(g.innerHTML="\u2605")}else if(Miniflux.Nav.IsListing())(e=document.getElementById("bookmark-icon-"+d))&&e.parentNode.removeChild(e),a(d);else if(e=document.getElementById("bookmark-"+d))e.innerHTML="\u2606"};e.open("POST",
|
|
|
|
"?action=bookmark&id="+d+"&value="+b,!0);e.send()}return{Get:e,MarkAsRead:f,MarkAsUnread:k,SwitchBookmark:function(c){"1"==c.getAttribute("data-item-bookmark")?l(c,0):l(c,1)},SwitchStatus:function(c){var a=c.getAttribute("data-item-id");c=c.getAttribute("data-item-status");"read"==c?k(a):"unread"==c&&f(a)},ChangeStatus:function(c,a){switch(a){case "read":f(c);break;case "unread":k(c)}},Show:function(c){(c=document.getElementById("show-"+c))&&c.click()},OpenOriginal:function(c){var a=document.getElementById("original-"+
|
|
|
|
c);a&&("unread"==e(c).getAttribute("data-item-status")&&f(c),a.removeAttribute("data-action"),a.click())},DownloadContent:function(){var a=document.getElementById("download-item");if(a){var b=a.getAttribute("data-item-id"),d=a.getAttribute("data-before-message"),e=document.createElement("img");e.src="./assets/img/refresh.gif";a.innerHTML="";a.className="downloading";a.appendChild(e);a.appendChild(document.createTextNode(" "+d));var f=new XMLHttpRequest;f.onload=function(){var b=JSON.parse(f.responseText);
|
|
|
|
if(b.result){var d=document.getElementById("item-content");d&&(d.innerHTML=b.content);a&&(b=a.getAttribute("data-after-message"),a.innerHTML="",a.appendChild(document.createTextNode(" "+b)))}else a&&(b=a.getAttribute("data-failure-message"),a.innerHTML="",a.appendChild(document.createTextNode(" "+b)))};f.open("POST","?action=download-item&id="+b,!0);f.send()}},MarkListingAsRead:function(a){for(var b=document.getElementsByTagName("article"),d=[],e=0,f=b.length;e<f;e++)d.push(b[e].getAttribute("data-item-id"));
|
|
|
|
b=new XMLHttpRequest;b.onload=function(){window.location.href=a};b.open("POST","?action=mark-items-as-read",!0);b.send(JSON.stringify(d))}}}();
|
|
|
|
Miniflux.Event=function(){var e=[];return{lastEventType:"",ListenMouseEvents:function(){document.onclick=function(a){var b=a.target.getAttribute("data-action");if(b)switch(Miniflux.Event.lastEventType="mouse",b){case "refresh-all":a.preventDefault();Miniflux.Feed.UpdateAll();break;case "refresh-feed":a.preventDefault();Miniflux.Feed.Update(a.target.getAttribute("data-feed-id"));break;case "mark-read":a.preventDefault();Miniflux.Item.MarkAsRead(a.target.getAttribute("data-item-id"));break;case "mark-unread":a.preventDefault();
|
|
|
|
Miniflux.Item.MarkAsUnread(a.target.getAttribute("data-item-id"));break;case "bookmark":a.preventDefault();Miniflux.Item.SwitchBookmark(Miniflux.Item.Get(a.target.getAttribute("data-item-id")));break;case "download-item":a.preventDefault();Miniflux.Item.DownloadContent();break;case "original-link":Miniflux.Item.OpenOriginal(a.target.getAttribute("data-item-id"));break;case "mark-all-read":a.preventDefault();Miniflux.Item.MarkListingAsRead("?action=unread");break;case "mark-feed-read":a.preventDefault();
|
|
|
|
Miniflux.Item.MarkListingAsRead("?action=feed-items&feed_id="+a.target.getAttribute("data-feed-id"));break;case "mozilla-login":a.preventDefault();Miniflux.App.MozillaAuth("mozilla-auth");break;case "mozilla-link":a.preventDefault(),Miniflux.App.MozillaAuth("mozilla-link")}}},ListenKeyboardEvents:function(){document.onkeypress=function(a){Miniflux.Event.lastEventType="keyboard";e.push(a.keyCode||a.which);if(103==e[0])switch(e[1]){case void 0:break;case 117:window.location.href="?action=unread";e=
|
|
|
|
[];break;case 98:window.location.href="?action=bookmarks";e=[];break;case 104:window.location.href="?action=history";e=[];break;case 115:window.location.href="?action=feeds";e=[];break;case 112:window.location.href="?action=config";e=[];break;default:e=[]}else switch(e=[],a.keyCode||a.which){case 100:Miniflux.Item.DownloadContent(Miniflux.Nav.GetCurrentItemId());break;case 112:case 107:Miniflux.Nav.SelectPreviousItem();break;case 110:case 106:Miniflux.Nav.SelectNextItem();break;case 118:Miniflux.Item.OpenOriginal(Miniflux.Nav.GetCurrentItemId());
|
|
|
|
break;case 111:Miniflux.Item.Show(Miniflux.Nav.GetCurrentItemId());break;case 109:Miniflux.Item.SwitchStatus(Miniflux.Nav.GetCurrentItem());break;case 102:Miniflux.Item.SwitchBookmark(Miniflux.Nav.GetCurrentItem());break;case 104:Miniflux.Nav.OpenPreviousPage();break;case 108:Miniflux.Nav.OpenNextPage();break;case 114:Miniflux.Feed.UpdateAll();break;case 63:Miniflux.Nav.ShowHelp()}}}}}();
|
2014-02-08 20:13:14 +01:00
|
|
|
Miniflux.Nav=function(){function e(a){var d=pageYOffset+document.documentElement.clientHeight;(0>d-(a.offsetTop+a.offsetHeight)||d-a.offsetTop>document.documentElement.clientHeight)&&window.scrollTo(0,a.offsetTop-10)}function a(){return document.getElementById("listing")?!0:!1}return{GetCurrentItem:function(){return document.getElementById("current-item")},GetCurrentItemId:function(){var a=Miniflux.Nav.GetCurrentItem();return a?a.getAttribute("data-item-id"):null},OpenNextPage:function(){var a=document.getElementById("next-page");
|
|
|
|
a&&a.click()},OpenPreviousPage:function(){var a=document.getElementById("previous-page");a&&a.click()},SelectNextItem:function(){var b=document.getElementById("next-item");if(b)b.click();else if(a())if(b=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var d=0,f=b.length;d<f;d++){if("current-item"==b[d].id){b[d].id="item-"+b[d].getAttribute("data-item-id");d+1<f&&(b[d+1].id="current-item",e(b[d+1]));break}}else b[0].id="current-item",e(b[0])},SelectPreviousItem:function(){var b=
|
|
|
|
document.getElementById("previous-item");if(b)b.click();else if(a())if(b=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var d=b.length-1;0<=d;d--){if("current-item"==b[d].id){b[d].id="item-"+b[d].getAttribute("data-item-id");0<=d-1&&(b[d-1].id="current-item",e(b[d-1]));break}}else b[b.length-1].id="current-item",e(b[b.length-1])},ShowHelp:function(){open("?action=show-help","Help","width=320,height=450,location=no,scrollbars=no,status=no,toolbar=no")},IsListing:a}}();
|
|
|
|
Miniflux.App.Run();
|