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