miniflux-legacy/assets/js/app.min.js

3 lines
19 KiB
JavaScript
Raw Normal View History

var Miniflux={};var DEBUG=false;Miniflux.App=function(){return{Log:function(message){if(DEBUG){console.log(message)}},Run:function(){Miniflux.Event.ListenKeyboardEvents();Miniflux.Event.ListenMouseEvents();Miniflux.Event.ListenVisibilityEvents();Miniflux.Event.ListenTouchEvents();this.FrontendUpdateCheck()},FrontendUpdateCheck:function(){var request=new XMLHttpRequest;request.onload=function(){var response=JSON.parse(this.responseText);if(response.frontend_updatecheck_interval>0){Miniflux.App.Log("Frontend updatecheck interval in minutes: "+response.frontend_updatecheck_interval);Miniflux.Item.CheckForUpdates();setInterval(function(){Miniflux.Item.CheckForUpdates()},response.frontend_updatecheck_interval*60*1e3)}else{Miniflux.App.Log("Frontend updatecheck disabled")}};request.open("POST","?action=get-config",true);request.send(JSON.stringify(["frontend_updatecheck_interval"]))}}}();Miniflux.Feed=function(){var queue=[];var queue_length=5;var updateInterval=null;var feeds=[];return{Update:function(feed,callback){var itemsCounter=feed.querySelector("span.items-count");if(!itemsCounter)return;var feed_id=feed.getAttribute("data-feed-id");var heading=feed.querySelector("h2:first-of-type");heading.className="loading-icon";var request=new XMLHttpRequest;request.onload=function(){heading.className="";feed.removeAttribute("data-feed-error");var lastChecked=feed.querySelector(".feed-last-checked");if(lastChecked){lastChecked.innerHTML=lastChecked.getAttribute("data-after-update")}var response=JSON.parse(this.responseText);if(response.result){itemsCounter.innerHTML=response.items_count.items_unread+"/"+response.items_count.items_total}else{feed.setAttribute("data-feed-error","1");var errorMessageElement=feed.querySelector(".feed-parsing-error");if(errorMessageElement){errorMessageElement.innerHTML=response.feed.parsing_error_message}}if(callback){callback(response)}else{Miniflux.Item.CheckForUpdates()}};request.open("POST","?action=refresh-feed&feed_id="+feed_id,true);request.send()},UpdateAll:function(nb_concurrent_requests){feeds=Array.prototype.slice.call(document.querySelectorAll("article:not([data-feed-disabled])"));if(nb_concurrent_requests){queue_length=nb_concurrent_requests}updateInterval=setInterval(function(){while(feeds.length>0&&queue.length<queue_length){var feed=feeds.shift();queue.push(parseInt(feed.getAttribute("data-feed-id"),10));Miniflux.Feed.Update(feed,Miniflux.Feed.OnFeedUpdated)}},100)},OnFeedUpdated:function(response){var index=queue.indexOf(response.feed_id);if(index>=0)queue.splice(index,1);if(feeds.length===0&&queue.length===0){clearInterval(updateInterval);Miniflux.Item.CheckForUpdates()}}}}();Miniflux.Item=function(){var latest_feeds_items={};var unreadItems=false;var nbUnreadItems=function(){var navCounterElement=document.getElementById("nav-counter");if(navCounterElement){return parseInt(navCounterElement.textContent,10)||0}}();var nbPageItems=function(){var pageCounterElement=document.getElementById("page-counter");if(pageCounterElement){return parseInt(pageCounterElement.textContent,10)||0}}();function simulateMouseClick(element){var event=document.createEvent("MouseEvents");event.initEvent("mousedown",true,true);element.dispatchEvent(event);event=document.createEvent("MouseEvents");event.initEvent("mouseup",true,true);element.dispatchEvent(event);element.click()}function getItemID(item){return item.getAttribute("data-item-id")}function changeLabel(links){if(links.length===0){return}for(var i=0;i<links.length;i++){var link=links[i];if(link.hasAttribute("data-reverse-label")){var content=link.innerHTML;link.innerHTML=link.getAttribute("data-reverse-label");link.setAttribute("data-reverse-label",content)}if(link.hasAttribute("data-reverse-title")){var title=link.getAttribute("title");link.setAttribute("title",link.getAttribute("data-reverse-title"));link.setAttribute("data-reverse-title",title)}}}function changeAction(links,action){if(links.length===0){return}for(var i=0;i<links.length;i++){links[i].setAttribute("data-action",action)}}function changeBookmarkLabel(item){var links=item.querySelectorA
Miniflux.App.Run();