7ea37a1790
They do exactly the same as the non javascript version.
19 lines
9.4 KiB
JavaScript
19 lines
9.4 KiB
JavaScript
var k=function(){var d=[];return{h:function(c,a){var b=c.querySelector("span.items-count");if(b){var e=c.getAttribute("data-feed-id"),d=c.querySelector("h2:first-of-type");d.className="loading-icon";var p=new XMLHttpRequest;p.onload=function(){d.className="";c.removeAttribute("data-feed-error");var e=c.querySelector(".feed-last-checked");e&&(e.innerHTML=e.getAttribute("data-after-update"));e=JSON.parse(this.responseText);e.result?b.innerHTML=e.items_count.items_unread+"/"+e.items_count.items_total:
|
|
c.setAttribute("data-feed-error","1");a?a(e):g.a()};p.open("POST","?action=refresh-feed&feed_id="+e,!0);p.send()}},i: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"),10));k.h(b,function(b){b=d.indexOf(b.feed_id);0<=b&&d.splice(b,1);0===c.length&&0===d.length&&(clearInterval(a),g.a())})}},100)}}}(),g=function(){function d(f){var a=
|
|
document.createEvent("MouseEvents");a.initEvent("mousedown",!0,!0);f.dispatchEvent(a);a=document.createEvent("MouseEvents");a.initEvent("mouseup",!0,!0);f.dispatchEvent(a);f.click()}function c(a){return item_id=a.getAttribute("data-item-id")}function a(a){if(a&&a.hasAttribute("data-reverse-label")){var b=a.innerHTML;a.innerHTML=a.getAttribute("data-reverse-label");a.setAttribute("data-reverse-label",b)}}function b(f){if("read"!==f.getAttribute("data-item-status")){if(f.getAttribute("data-hide"))e(f);
|
|
else{f.setAttribute("data-item-status","read");var b=f.querySelector("a.mark");a(b);(f=f.querySelector("a.mark"))&&f.setAttribute("data-action","mark-unread")}l--}}function e(a){"mouse"!==m.c&&t.d();a.parentNode.removeChild(a);q--}function n(){-1<window.location.href.indexOf("nothing_to_read=1")&&0<l?window.location.href="?action=unread":0===q&&window.location.reload();var a=document.getElementById("page-counter");a&&(a.textContent=q||"");document.getElementById("nav-counter").textContent=l||"";var b=
|
|
document.querySelector("div.page-header h2:first-of-type");if(b)pageHeading=b.firstChild.nodeValue;else if(b=document.querySelector("article.item h1:first-of-type")){document.title=b.textContent;return}switch(document.querySelector("section.page").getAttribute("data-item-page")){case "unread":document.title="Miniflux ("+l+")";break;case "feed-items":document.title="("+q+") "+pageHeading;break;default:document.title=a?pageHeading+" ("+q+")":pageHeading}}function p(a){var e=c(a),h=new XMLHttpRequest;
|
|
h.onload=function(){t.b()&&(b(a),n())};h.open("POST","?action=mark-item-read&id="+e,!0);h.send()}function v(f){var b=c(f),h=new XMLHttpRequest;h.onload=function(){if(t.b()){if("unread"!==f.getAttribute("data-item-status")){if(f.getAttribute("data-hide"))e(f);else{f.setAttribute("data-item-status","unread");var b=f.querySelector("a.mark");a(b);(b=f.querySelector("a.mark"))&&b.setAttribute("data-action","mark-read")}l++}n()}};h.open("POST","?action=mark-item-unread&id="+b,!0);h.send()}var u=[],r=!1,
|
|
l=function(){var a=document.getElementById("nav-counter");if(a)return counter=parseInt(a.textContent,10)||0}(),q=function(){var a=document.getElementById("page-counter");if(a)return counter=parseInt(a.textContent,10)||0}();return{n:p,p:v,o:function(a){var b=c(a),h=new XMLHttpRequest;h.onload=function(){t.b()&&(e(a),"unread"===a.getAttribute("data-item-status")&&l--,n())};h.open("POST","?action=mark-item-removed&id="+b,!0);h.send()},g:function(b){var w=c(b),h="1"===b.getAttribute("data-item-bookmark")?
|
|
"0":"1",d=new XMLHttpRequest;d.onload=function(){var c=document.querySelector("section.page");if(t.b()&&"bookmarks"===c.getAttribute("data-item-page"))e(b),n();else if(b.setAttribute("data-item-bookmark",h),t.b())c=b.querySelector("a.bookmark"),a(c);else if((c=b.querySelector("a.bookmark-icon"))&&c.hasAttribute("data-reverse-title")){var d=c.getAttribute("title");c.setAttribute("title",c.getAttribute("data-reverse-title"));c.setAttribute("data-reverse-title",d)}};d.open("POST","?action=bookmark&id="+
|
|
w+"&value="+h,!0);d.send()},A:function(a){var b=a.getAttribute("data-item-status");"read"===b?v(a):"unread"===b&&p(a)},v:function(a){(a=a.querySelector("a.show"))&&d(a)},s:function(a){(a=a.querySelector("a.original"))&&d(a)},e:function(a){var b=document.getElementById("download-item");if(b){b.innerHTML=" "+b.getAttribute("data-before-message");b.className="loading-icon";var e=new XMLHttpRequest;e.onload=function(){var a=JSON.parse(e.responseText);b.className="";if(a.result){var c=document.getElementById("item-content");
|
|
c&&(c.innerHTML=a.content);b.innerHTML=b.getAttribute("data-after-message")}else b.innerHTML=b.getAttribute("data-failure-message")};a=c(a);e.open("POST","?action=download-item&id="+a,!0);e.send()}},q:function(a){var c=new XMLHttpRequest;c.onload=function(){for(var a=document.getElementsByTagName("article"),c=0,e=a.length;c<e;c++)b(a[c]);l=this.responseText;n()};c.open("POST","?action=mark-feed-as-read&feed_id="+a,!0);c.send()},B: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":"")}},C:function(){return r},a:function(){if(!document.hidden||!r){var a=new XMLHttpRequest;a.onload=function(){var a=0===u.length,b=!1,c=JSON.parse(this.responseText),e;for(e in c.feeds){var d=c.feeds[e];if(!u.hasOwnProperty(e)||d.time>u[e])u[e]=d.time,"unread"===d.status&&(b=!0)}document.hidden||c.nbUnread===l&&!r?document.hidden&&!a&&b&&(r=!0,document.title="\u21bb "+document.title):
|
|
(r=!1,l=c.nbUnread,n())};a.open("POST","?action=latest-feeds-items",!0);a.send()}}}}(),m=function(){function d(a){if(63!==a.keyCode&&63!==a.which&&(a.ctrlKey||a.shiftKey||a.altKey||a.metaKey))return!0;a=a.target||a.srcElement;return"INPUT"===a.tagName||"TEXTAREA"===a.tagName?!0:!1}var c=[];return{c:"",l:function(){document.onclick=function(a){a.target.hasAttribute("data-action")&&"original"!==a.target.className&&a.preventDefault()};document.onmouseup=function(a){if(2!==a.button)if("INPUT"===a.target.nodeName&&
|
|
"auto-select"===a.target.className)a.target.select();else{var b=a.target.getAttribute("data-action");if(b){m.c="mouse";var c;a:{for(element=a.target;element&&element.parentNode;)if(element=element.parentNode,element.tagName&&"article"===element.tagName.toLowerCase()){c=element;break a}c=void 0}switch(b){case "refresh-all":k.i();break;case "refresh-feed":c&&k.h(c);break;case "mark-read":c&&g.n(c);break;case "mark-unread":c&&g.p(c);break;case "mark-removed":c&&g.o(c);break;case "bookmark":c&&g.g(c);
|
|
break;case "download-item":c&&g.e(c);break;case "mark-feed-read":g.q(a.target.getAttribute("data-feed-id"))}}}}},k:function(){document.onkeypress=function(a){if(!d(a))if(m.c="keyboard",c.push(a.key||a.which),"g"===c[0]||103===c[0])switch(c[1]){case void 0:break;case "u":case 117:window.location.href="?action=unread";c=[];break;case "b":case 98:window.location.href="?action=bookmarks";c=[];break;case "h":case 104:window.location.href="?action=history";c=[];break;case "s":case 115:window.location.href=
|
|
"?action=feeds";c=[];break;case "p":case 112:window.location.href="?action=config";c=[];break;default:c=[]}else{c=[];var b=document.getElementById("current-item");switch(a.key||a.which){case "d":case 100:b&&g.e(b);break;case "p":case 112:case "k":case 107:t.f();break;case "n":case 110:case "j":case 106:t.d();break;case "v":case 118:b&&g.s(b);break;case "o":case 111:b&&g.v(b);break;case "m":case 109:b&&g.A(b);break;case "f":case 102:b&&g.g(b);break;case "h":case 104:t.t();break;case "l":case 108:t.r();
|
|
break;case "r":case 114:k.i();break;case "?":case 63:t.w();break;case "z":case 122:g.B()}}};document.onkeydown=function(a){if(!d(a))switch(m.c="keyboard",a.key||a.which){case "ArrowLeft":case "Left":case 37:t.f();break;case "ArrowRight":case "Right":case 39:t.d()}}},m:function(){document.addEventListener("visibilitychange",function(){!document.hidden&&g.C()&&g.a()})}}}(),t=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{r:function(){var a=document.getElementById("next-page");a&&a.click()},t:function(){var a=document.getElementById("previous-page");a&&a.click()},d: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,e=a.length;b<e;b++){if("current-item"===
|
|
a[b].id){b+1<e&&(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])},f: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])},w:function(){open("?action=show-help","Help","width=320,height=450,location=no,scrollbars=no,status=no,toolbar=no")},b:c}}();({D:function(){},u:function(){m.k();m.l();m.m();this.j()},j:function(){var d=new XMLHttpRequest;d.onload=function(){var c=JSON.parse(this.responseText);0<c.frontend_updatecheck_interval&&(g.a(),setInterval(function(){g.a()},6E4*c.frontend_updatecheck_interval))};d.open("POST","?action=get-config",!0);d.send(JSON.stringify(["frontend_updatecheck_interval"]))}}).u(); |