2014-12-02 16:29:00 +01:00
|
|
|
var Miniflux={};Miniflux.App=function(){return{Run:function(){Miniflux.Event.ListenKeyboardEvents();Miniflux.Event.ListenMouseEvents()}}}();
|
2014-11-15 14:32:31 +01:00
|
|
|
Miniflux.Feed=function(){var b=[];return{Update:function(e,a){var d=e.querySelector("span.items-count");if(d){var b=e.getAttribute("data-feed-id"),l=e.querySelector("h2:first-of-type");l.className="loading-icon";var g=new XMLHttpRequest;g.onload=function(){l.className="";var b=e.querySelector(".feed-last-checked");b&&(b.innerHTML=b.getAttribute("data-after-update"));if(b=e.querySelector(".feed-parsing-error"))b.innerHTML="";var c=JSON.parse(this.responseText);c.result?d.innerHTML=c.items_count.items_unread+
|
|
|
|
"/"+c.items_count.items_total:b&&(b.innerHTML=b.getAttribute("data-after-error"));a&&a(c)};g.open("POST","?action=refresh-feed&feed_id="+b,!0);g.send()}},UpdateAll:function(){var e=Array.prototype.slice.call(document.querySelectorAll("article:not([data-feed-disabled])")),a=setInterval(function(){for(;0<e.length&&5>b.length;){var d=e.shift();b.push(parseInt(d.getAttribute("data-feed-id")));Miniflux.Feed.Update(d,function(d){d=b.indexOf(d.feed_id);0<=d&&b.splice(d,1);0===e.length&&0===b.length&&(clearInterval(a),
|
2014-12-31 13:43:05 +01:00
|
|
|
window.location.href="?action=unread")})}},100)}}}();
|
2014-11-15 14:32:31 +01:00
|
|
|
Miniflux.Item=function(){function b(c){return item_id=c.getAttribute("data-item-id")}function e(c){if(c&&c.hasAttribute("data-reverse-label")){var a=c.innerHTML;c.innerHTML=c.getAttribute("data-reverse-label");c.setAttribute("data-reverse-label",a)}}function a(c){"mouse"!==Miniflux.Event.lastEventType&&Miniflux.Nav.SelectNextItem();c.parentNode.removeChild(c);m--}function d(){0===m&&window.location.reload();var c=document.getElementById("page-counter");c.textContent=m||"";document.getElementById("nav-counter").textContent=
|
|
|
|
g||"";switch(document.querySelector("section.page").getAttribute("data-item-page")){case "unread":document.title="Miniflux ("+g+")";break;case "feed-items":document.title="("+m+") "+c.parentNode.firstChild.nodeValue;break;default:document.title=c.parentNode.firstChild.nodeValue+" ("+m+")"}}function h(c){var k=b(c),f=new XMLHttpRequest;f.onload=function(){if(Miniflux.Nav.IsListing()){if(c.getAttribute("data-hide"))a(c);else{c.setAttribute("data-item-status","read");var b=c.querySelector("a.mark");
|
|
|
|
e(b);(b=c.querySelector("a.mark"))&&b.setAttribute("data-action","mark-unread")}g--;d()}};f.open("POST","?action=mark-item-read&id="+k,!0);f.send()}function l(c){var k=b(c),f=new XMLHttpRequest;f.onload=function(){if(Miniflux.Nav.IsListing()){if(c.getAttribute("data-hide"))a(c);else{c.setAttribute("data-item-status","unread");var b=c.querySelector("a.mark");e(b);(b=c.querySelector("a.mark"))&&b.setAttribute("data-action","mark-read")}g++;d()}};f.open("POST","?action=mark-item-unread&id="+k,!0);f.send()}
|
|
|
|
var g=function(){var c=document.getElementById("nav-counter");if(c)return counter=parseInt(c.textContent,10)||0}(),m=function(){var c=document.getElementById("page-counter");if(c)return counter=parseInt(c.textContent,10)||0}();return{MarkAsRead:h,MarkAsUnread:l,MarkAsRemoved:function(c){var e=b(c),f=new XMLHttpRequest;f.onload=function(){Miniflux.Nav.IsListing()&&(a(c),"unread"===c.getAttribute("data-item-status")&&g--,d())};f.open("POST","?action=mark-item-removed&id="+e,!0);f.send()},SwitchBookmark:function(c){var k=
|
|
|
|
b(c),f="1"===c.getAttribute("data-item-bookmark")?"0":"1",n=new XMLHttpRequest;n.onload=function(){var b=document.querySelector("section.page");if(Miniflux.Nav.IsListing()&&"bookmarks"===b.getAttribute("data-item-page"))a(c),d();else if(c.setAttribute("data-item-bookmark",f),Miniflux.Nav.IsListing())b=c.querySelector("a.bookmark"),e(b);else if((b=c.querySelector("a.bookmark-icon"))&&b.hasAttribute("data-reverse-title")){var k=b.getAttribute("title");b.setAttribute("title",b.getAttribute("data-reverse-title"));
|
|
|
|
b.setAttribute("data-reverse-title",k)}};n.open("POST","?action=bookmark&id="+k+"&value="+f,!0);n.send()},SwitchStatus:function(c){var a=c.getAttribute("data-item-status");"read"===a?l(c):"unread"===a&&h(c)},Show:function(c){(c=c.querySelector("a.show"))&&c.click()},OpenOriginal:function(c){var a=c.querySelector("a.original");a&&("unread"===c.getAttribute("data-item-status")&&h(c),a.removeAttribute("data-action"),"mouse"!==Miniflux.Event.lastEventType&&a.click())},DownloadContent:function(c){var a=
|
|
|
|
document.getElementById("download-item");if(a){a.innerHTML=" "+a.getAttribute("data-before-message");a.className="loading-icon";var d=new XMLHttpRequest;d.onload=function(){var c=JSON.parse(d.responseText);a.className="";if(c.result){var b=document.getElementById("item-content");b&&(b.innerHTML=c.content);a.innerHTML=a.getAttribute("data-after-message")}else a.innerHTML=a.getAttribute("data-failure-message")};c=b(c);d.open("POST","?action=download-item&id="+c,!0);d.send()}},MarkListingAsRead:function(a){for(var d=
|
|
|
|
document.getElementsByTagName("article"),e=[],g=0,h=d.length;g<h;g++)e.push(b(d[g]));d=new XMLHttpRequest;d.onload=function(){window.location.href=a};d.open("POST","?action=mark-items-as-read",!0);d.send(JSON.stringify(e))},ToggleRTLMode:function(){for(var a=["#current-item h1","#item-content","#listing #current-item h2","#listing #current-item .preview"],b=0;b<a.length;b++){var d=document.querySelector(a[b]);d&&(d.dir=""==d.dir?"rtl":"")}}}}();
|
|
|
|
Miniflux.Event=function(){var b=[];return{lastEventType:"",ListenMouseEvents:function(){document.onclick=function(b){var a=b.target.getAttribute("data-action");a&&"original-link"!==a&&b.preventDefault()};document.onmouseup=function(b){if(2!==b.button)if("INPUT"===b.target.nodeName&&"auto-select"===b.target.className)b.target.select();else{var a=b.target.getAttribute("data-action");if(a){Miniflux.Event.lastEventType="mouse";var d;a:{for(element=b.target;element&&element.parentNode;)if(element=element.parentNode,
|
|
|
|
element.tagName&&"article"===element.tagName.toLowerCase()){d=element;break a}d=null}switch(a){case "refresh-all":Miniflux.Feed.UpdateAll();break;case "refresh-feed":Miniflux.Feed.Update(d);break;case "mark-read":Miniflux.Item.MarkAsRead(d);break;case "mark-unread":Miniflux.Item.MarkAsUnread(d);break;case "mark-removed":Miniflux.Item.MarkAsRemoved(d);break;case "bookmark":Miniflux.Item.SwitchBookmark(d);break;case "download-item":Miniflux.Item.DownloadContent(d);break;case "original-link":Miniflux.Item.OpenOriginal(d);
|
|
|
|
break;case "mark-all-read":Miniflux.Item.MarkListingAsRead("?action=unread");break;case "mark-feed-read":Miniflux.Item.MarkListingAsRead("?action=feed-items&feed_id="+b.target.getAttribute("data-feed-id"))}}}}},ListenKeyboardEvents:function(){document.onkeypress=function(e){if(63===e.keyCode||!(e.ctrlKey||e.shiftKey||e.altKey||e.metaKey)){var a=e.target||e.srcElement;if("INPUT"!==a.tagName&&"TEXTAREA"!==a.tagName)if(Miniflux.Event.lastEventType="keyboard",b.push(e.keyCode||e.which),103===b[0])switch(b[1]){case void 0:break;
|
|
|
|
case 117:window.location.href="?action=unread";b=[];break;case 98:window.location.href="?action=bookmarks";b=[];break;case 104:window.location.href="?action=history";b=[];break;case 115:window.location.href="?action=feeds";b=[];break;case 112:window.location.href="?action=config";b=[];break;default:b=[]}else switch(b=[],a=document.getElementById("current-item"),e.keyCode||e.which){case 100:Miniflux.Item.DownloadContent(a);break;case 112:case 107:Miniflux.Nav.SelectPreviousItem();break;case 110:case 106:Miniflux.Nav.SelectNextItem();
|
2015-01-03 00:49:29 +01:00
|
|
|
break;case 118:Miniflux.Item.OpenOriginal(a);break;case 111:Miniflux.Item.Show(a);break;case 109:Miniflux.Item.SwitchStatus(a);break;case 102:Miniflux.Item.SwitchBookmark(a);break;case 104:Miniflux.Nav.OpenPreviousPage();break;case 108:Miniflux.Nav.OpenNextPage();break;case 114:Miniflux.Feed.UpdateAll();break;case 63:Miniflux.Nav.ShowHelp();break;case 122:Miniflux.Item.ToggleRTLMode()}}}}}}();
|
2014-11-15 14:32:31 +01:00
|
|
|
Miniflux.Nav=function(){function b(a){var b=pageYOffset+document.documentElement.clientHeight;(0>b-(a.offsetTop+a.offsetHeight)||b-a.offsetTop>document.documentElement.clientHeight)&&window.scrollTo(0,a.offsetTop-10)}function e(){return document.getElementById("listing")?!0:!1}return{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 a=document.getElementById("next-item");
|
|
|
|
if(a)a.click();else if(e())if(a=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var d=0,h=a.length;d<h;d++){if("current-item"===a[d].id){d+1<h&&(a[d].id="item-"+a[d].getAttribute("data-item-id"),a[d+1].id="current-item",b(a[d+1]));break}}else a[0].id="current-item",b(a[0])},SelectPreviousItem:function(){var a=document.getElementById("previous-item");if(a)a.click();else if(e())if(a=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var d=
|
|
|
|
a.length-1;0<=d;d--){if("current-item"===a[d].id){0<=d-1&&(a[d].id="item-"+a[d].getAttribute("data-item-id"),a[d-1].id="current-item",b(a[d-1]));break}}else a[a.length-1].id="current-item",b(a[a.length-1])},ShowHelp:function(){open("?action=show-help","Help","width=320,height=450,location=no,scrollbars=no,status=no,toolbar=no")},IsListing:e}}();Miniflux.App.Run();
|