2013-10-15 04:38:07 +02:00
|
|
|
Miniflux.Item = (function() {
|
|
|
|
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
// timestamp of the latest item per feed ever seen
|
|
|
|
var latest_feeds_items = [];
|
|
|
|
|
|
|
|
// indicator for new unread items
|
|
|
|
var unreadItems = false;
|
|
|
|
|
2014-11-15 14:32:31 +01:00
|
|
|
var nbUnreadItems = function() {
|
|
|
|
var navCounterElement = document.getElementById("nav-counter");
|
2015-01-27 19:01:21 +01:00
|
|
|
|
2014-11-15 14:32:31 +01:00
|
|
|
if (navCounterElement) {
|
|
|
|
counter = parseInt(navCounterElement.textContent, 10) || 0;
|
|
|
|
return counter;
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
|
|
|
var nbPageItems = function() {
|
|
|
|
var pageCounterElement = document.getElementById("page-counter");
|
2015-01-27 19:01:21 +01:00
|
|
|
|
2014-11-15 14:32:31 +01:00
|
|
|
if (pageCounterElement) {
|
|
|
|
counter = parseInt(pageCounterElement.textContent, 10) || 0;
|
|
|
|
return counter;
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
2015-01-29 23:28:18 +01:00
|
|
|
function simulateMouseClick(element)
|
|
|
|
{
|
|
|
|
var event = document.createEvent("MouseEvents");
|
|
|
|
event.initEvent("mousedown", true, true);
|
|
|
|
element.dispatchEvent(event);
|
|
|
|
|
|
|
|
var event = document.createEvent("MouseEvents");
|
|
|
|
event.initEvent("mouseup", true, true);
|
|
|
|
element.dispatchEvent(event);
|
|
|
|
|
|
|
|
element.click();
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function getItemID(item)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
item_id = item.getAttribute("data-item-id");
|
|
|
|
return item_id;
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
|
2014-08-11 00:03:48 +02:00
|
|
|
function changeLabel(link)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
if (link && link.hasAttribute("data-reverse-label")) {
|
2013-10-15 04:38:07 +02:00
|
|
|
var content = link.innerHTML;
|
|
|
|
link.innerHTML = link.getAttribute("data-reverse-label");
|
|
|
|
link.setAttribute("data-reverse-label", content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function changeBookmarkLabel(item)
|
2014-08-11 00:03:48 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
var link = item.querySelector("a.bookmark");
|
2014-08-11 00:03:48 +02:00
|
|
|
changeLabel(link);
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function changeStatusLabel(item)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
var link = item.querySelector("a.mark");
|
2014-08-11 00:03:48 +02:00
|
|
|
changeLabel(link);
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function showItemAsRead(item)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2015-03-08 12:56:59 +01:00
|
|
|
if (item.getAttribute("data-item-status") === 'read') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
if (item.getAttribute("data-hide")) {
|
|
|
|
hideItem(item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item.setAttribute("data-item-status", "read");
|
|
|
|
changeStatusLabel(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
// Change action
|
|
|
|
var link = item.querySelector("a.mark");
|
|
|
|
if (link) link.setAttribute("data-action", "mark-unread");
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
2015-01-27 19:01:21 +01:00
|
|
|
|
2014-11-15 14:32:31 +01:00
|
|
|
nbUnreadItems--;
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function showItemAsUnread(item)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2015-03-08 12:56:59 +01:00
|
|
|
if (item.getAttribute("data-item-status") === 'unread') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
if (item.getAttribute("data-hide")) {
|
|
|
|
hideItem(item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item.setAttribute("data-item-status", "unread");
|
|
|
|
changeStatusLabel(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
// Change action
|
|
|
|
var link = item.querySelector("a.mark");
|
|
|
|
if (link) link.setAttribute("data-action", "mark-read");
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
2015-01-27 19:01:21 +01:00
|
|
|
|
2014-11-15 14:32:31 +01:00
|
|
|
nbUnreadItems++;
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function hideItem(item)
|
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
if (Miniflux.Event.lastEventType !== "mouse") {
|
2015-07-24 13:58:02 +02:00
|
|
|
var items = document.getElementsByTagName("article");
|
|
|
|
|
|
|
|
if (items[items.length-1].id === "current-item") {
|
|
|
|
Miniflux.Nav.SelectPreviousItem();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Miniflux.Nav.SelectNextItem();
|
|
|
|
}
|
2014-02-15 03:37:07 +01:00
|
|
|
}
|
2013-10-15 04:38:07 +02:00
|
|
|
|
|
|
|
item.parentNode.removeChild(item);
|
2014-11-15 14:32:31 +01:00
|
|
|
nbPageItems--;
|
|
|
|
}
|
2014-12-24 04:13:23 +01:00
|
|
|
|
2014-11-15 14:32:31 +01:00
|
|
|
function updateCounters()
|
|
|
|
{
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
// redirect to unread if we're on a nothing to read page
|
|
|
|
if (window.location.href.indexOf('nothing_to_read=1') > -1 && nbUnreadItems > 0) {
|
|
|
|
window.location.href = '?action=unread';
|
|
|
|
} // reload to get a nothing to read page
|
|
|
|
else if (nbPageItems === 0) {
|
2014-11-15 14:32:31 +01:00
|
|
|
window.location.reload();
|
|
|
|
}
|
2013-10-15 04:38:07 +02:00
|
|
|
|
2014-11-15 14:32:31 +01:00
|
|
|
var pageCounterElement = document.getElementById("page-counter");
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
if (pageCounterElement) pageCounterElement.textContent = nbPageItems || '';
|
2015-01-27 19:01:21 +01:00
|
|
|
|
2014-11-15 14:32:31 +01:00
|
|
|
var navCounterElement = document.getElementById("nav-counter");
|
2015-01-27 19:01:21 +01:00
|
|
|
navCounterElement.textContent = nbUnreadItems || '';
|
2014-11-15 14:32:31 +01:00
|
|
|
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
var pageHeadingElement = document.querySelector("div.page-header h2:first-of-type");
|
|
|
|
if (pageHeadingElement) {
|
|
|
|
pageHeading = pageHeadingElement.firstChild.nodeValue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// special handling while viewing an article.
|
|
|
|
// 1. The article does not have a page-header element
|
|
|
|
// 2. An article could be opened from any page and has the original
|
|
|
|
// page as data-item-page value
|
|
|
|
var itemHeading = document.querySelector("article.item h1:first-of-type");
|
|
|
|
if (itemHeading) {
|
|
|
|
document.title = itemHeading.textContent;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 14:32:31 +01:00
|
|
|
// pagetitle depends on current page
|
|
|
|
var sectionElement = document.querySelector("section.page");
|
|
|
|
switch (sectionElement.getAttribute("data-item-page")) {
|
|
|
|
case "unread":
|
|
|
|
document.title = "Miniflux (" + nbUnreadItems + ")";
|
|
|
|
break;
|
|
|
|
case "feed-items":
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
document.title = "(" + nbPageItems + ") " + pageHeading;
|
2014-11-15 14:32:31 +01:00
|
|
|
break;
|
|
|
|
default:
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
if (pageCounterElement) {
|
|
|
|
document.title = pageHeading + " (" + nbPageItems + ")";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.title = pageHeading;
|
|
|
|
}
|
2014-11-15 14:32:31 +01:00
|
|
|
break;
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function markAsRead(item)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
var item_id = getItemID(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
var request = new XMLHttpRequest();
|
2014-12-24 04:13:23 +01:00
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
request.onload = function() {
|
2015-03-08 12:56:59 +01:00
|
|
|
if (Miniflux.Nav.IsListing()) {
|
|
|
|
showItemAsRead(item);
|
|
|
|
updateCounters();
|
|
|
|
}
|
2013-10-15 04:38:07 +02:00
|
|
|
};
|
|
|
|
request.open("POST", "?action=mark-item-read&id=" + item_id, true);
|
|
|
|
request.send();
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function markAsUnread(item)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
var item_id = getItemID(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
var request = new XMLHttpRequest();
|
2014-12-24 04:13:23 +01:00
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
request.onload = function() {
|
2015-03-08 12:56:59 +01:00
|
|
|
if (Miniflux.Nav.IsListing()) {
|
|
|
|
showItemAsUnread(item);
|
|
|
|
updateCounters();
|
|
|
|
}
|
2013-10-15 04:38:07 +02:00
|
|
|
};
|
|
|
|
request.open("POST", "?action=mark-item-unread&id=" + item_id, true);
|
|
|
|
request.send();
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function markAsRemoved(item)
|
2014-07-26 14:01:25 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
var item_id = getItemID(item);
|
2014-07-26 14:01:25 +02:00
|
|
|
var request = new XMLHttpRequest();
|
2014-12-24 04:13:23 +01:00
|
|
|
|
2014-07-26 14:01:25 +02:00
|
|
|
request.onload = function() {
|
2014-11-15 14:32:31 +01:00
|
|
|
if (Miniflux.Nav.IsListing()) {
|
|
|
|
hideItem(item);
|
2015-01-27 19:01:21 +01:00
|
|
|
|
2014-11-15 14:32:31 +01:00
|
|
|
if (item.getAttribute("data-item-status") === "unread") nbUnreadItems--;
|
|
|
|
updateCounters();
|
|
|
|
}
|
2014-07-26 14:01:25 +02:00
|
|
|
};
|
|
|
|
request.open("POST", "?action=mark-item-removed&id=" + item_id, true);
|
|
|
|
request.send();
|
|
|
|
}
|
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
return {
|
2015-03-08 12:56:59 +01:00
|
|
|
MarkAsRead: markAsRead,
|
2013-10-15 04:38:07 +02:00
|
|
|
MarkAsUnread: markAsUnread,
|
2014-07-26 14:01:25 +02:00
|
|
|
MarkAsRemoved: markAsRemoved,
|
2013-10-15 04:38:07 +02:00
|
|
|
SwitchBookmark: function(item) {
|
2014-09-16 20:42:15 +02:00
|
|
|
var item_id = getItemID(item);
|
|
|
|
var value = item.getAttribute("data-item-bookmark") === "1" ? "0" : "1";
|
|
|
|
var request = new XMLHttpRequest();
|
2014-12-24 04:13:23 +01:00
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
request.onload = function() {
|
2014-12-04 12:08:17 +01:00
|
|
|
var sectionElement = document.querySelector("section.page");
|
2015-01-27 19:01:21 +01:00
|
|
|
|
2014-12-04 12:08:17 +01:00
|
|
|
if (Miniflux.Nav.IsListing() && sectionElement.getAttribute("data-item-page") === "bookmarks") {
|
2014-11-10 18:36:15 +01:00
|
|
|
hideItem(item);
|
2014-11-15 14:32:31 +01:00
|
|
|
updateCounters();
|
2014-11-10 18:36:15 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
item.setAttribute("data-item-bookmark", value);
|
|
|
|
|
|
|
|
if (Miniflux.Nav.IsListing()) {
|
|
|
|
changeBookmarkLabel(item);
|
|
|
|
}
|
2014-12-02 17:08:52 +01:00
|
|
|
else {
|
|
|
|
var link = item.querySelector("a.bookmark-icon");
|
|
|
|
if (link && link.hasAttribute("data-reverse-title")) {
|
|
|
|
var title = link.getAttribute("title");
|
2014-12-24 04:13:23 +01:00
|
|
|
|
2014-12-02 17:08:52 +01:00
|
|
|
link.setAttribute("title", link.getAttribute("data-reverse-title"));
|
|
|
|
link.setAttribute("data-reverse-title", title);
|
|
|
|
}
|
|
|
|
}
|
2014-11-10 18:36:15 +01:00
|
|
|
}
|
2014-09-16 20:42:15 +02:00
|
|
|
};
|
2013-10-15 04:38:07 +02:00
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
request.open("POST", "?action=bookmark&id=" + item_id + "&value=" + value, true);
|
|
|
|
request.send();
|
2013-10-15 04:38:07 +02:00
|
|
|
},
|
|
|
|
SwitchStatus: function(item) {
|
|
|
|
var status = item.getAttribute("data-item-status");
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
if (status === "read") {
|
|
|
|
markAsUnread(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
2014-09-16 20:42:15 +02:00
|
|
|
else if (status === "unread") {
|
|
|
|
markAsRead(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
},
|
2014-09-16 20:42:15 +02:00
|
|
|
Show: function(item) {
|
|
|
|
var link = item.querySelector("a.show");
|
2015-01-29 23:28:18 +01:00
|
|
|
if (link) simulateMouseClick(link);
|
2013-10-15 04:38:07 +02:00
|
|
|
},
|
2014-09-16 20:42:15 +02:00
|
|
|
OpenOriginal: function(item) {
|
|
|
|
var link = item.querySelector("a.original");
|
2015-01-29 23:28:18 +01:00
|
|
|
if (link) simulateMouseClick(link)
|
2013-10-15 04:38:07 +02:00
|
|
|
},
|
2014-09-16 20:42:15 +02:00
|
|
|
DownloadContent: function(item) {
|
2013-10-15 04:38:07 +02:00
|
|
|
var container = document.getElementById("download-item");
|
|
|
|
if (! container) return;
|
|
|
|
|
2014-12-02 16:29:00 +01:00
|
|
|
container.innerHTML = " " + container.getAttribute("data-before-message");
|
|
|
|
container.className = "loading-icon";
|
2015-01-27 19:01:21 +01:00
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.onload = function() {
|
|
|
|
|
|
|
|
var response = JSON.parse(request.responseText);
|
2014-12-02 16:29:00 +01:00
|
|
|
container.className = "";
|
2015-01-27 19:01:21 +01:00
|
|
|
|
|
|
|
if (response['result']) {
|
2013-10-15 04:38:07 +02:00
|
|
|
var content = document.getElementById("item-content");
|
2015-01-27 19:01:21 +01:00
|
|
|
if (content) content.innerHTML = response['content'];
|
|
|
|
|
2014-12-02 16:29:00 +01:00
|
|
|
container.innerHTML = container.getAttribute("data-after-message");
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-12-02 16:29:00 +01:00
|
|
|
container.innerHTML = container.getAttribute("data-failure-message");
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
};
|
2015-01-27 19:01:21 +01:00
|
|
|
|
2014-12-02 16:29:00 +01:00
|
|
|
var item_id = getItemID(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
request.open("POST", "?action=download-item&id=" + item_id, true);
|
|
|
|
request.send();
|
|
|
|
},
|
2015-02-26 17:33:21 +01:00
|
|
|
MarkFeedAsRead: function(feed_id) {
|
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
|
|
|
|
request.onload = function() {
|
2015-03-08 12:56:59 +01:00
|
|
|
var articles = document.getElementsByTagName("article");
|
|
|
|
|
|
|
|
for (var i = 0, ilen = articles.length; i < ilen; i++) {
|
|
|
|
showItemAsRead(articles[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
nbUnreadItems = this.responseText;
|
|
|
|
updateCounters();
|
2015-02-26 17:33:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
request.open("POST", "?action=mark-feed-as-read&feed_id=" + feed_id, true);
|
|
|
|
request.send();
|
|
|
|
},
|
2014-12-24 04:13:23 +01:00
|
|
|
ToggleRTLMode: function() {
|
|
|
|
var tags = [
|
|
|
|
"#current-item h1",
|
|
|
|
"#item-content",
|
2014-12-26 10:24:34 +01:00
|
|
|
"#listing #current-item h2",
|
2015-08-25 22:39:27 +02:00
|
|
|
"#listing #current-item .preview",
|
|
|
|
"#listing #current-item .preview-full-content"
|
2014-12-24 04:13:23 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
for (var i = 0; i < tags.length; i++) {
|
|
|
|
var tag = document.querySelector(tags[i]);
|
|
|
|
|
|
|
|
if (tag) {
|
|
|
|
tag.dir = tag.dir == "" ? "rtl" : "";
|
|
|
|
}
|
|
|
|
}
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
},
|
|
|
|
hasNewUnread: function() {
|
|
|
|
return unreadItems;
|
|
|
|
},
|
|
|
|
CheckForUpdates: function() {
|
|
|
|
if (document.hidden && unreadItems) {
|
|
|
|
Miniflux.App.Log('We already have updates, no need to check again');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.onload = function() {
|
|
|
|
var first_run = (latest_feeds_items.length === 0);
|
|
|
|
var current_unread = false;
|
|
|
|
var response = JSON.parse(this.responseText);
|
|
|
|
|
2015-01-29 02:17:02 +01:00
|
|
|
for (var feed_id in response['feeds']) {
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
var current_feed = response['feeds'][feed_id];
|
|
|
|
|
2015-01-29 02:17:02 +01:00
|
|
|
if (! latest_feeds_items.hasOwnProperty(feed_id) || current_feed.time > latest_feeds_items[feed_id]) {
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
Miniflux.App.Log('feed ' + feed_id + ': New item(s)');
|
|
|
|
latest_feeds_items[feed_id] = current_feed.time;
|
|
|
|
|
|
|
|
if (current_feed.status === 'unread') {
|
|
|
|
Miniflux.App.Log('feed ' + feed_id + ': New unread item(s)');
|
|
|
|
current_unread = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Miniflux.App.Log('first_run: ' + first_run + ', current_unread: ' + current_unread + ', response.nbUnread: ' + response['nbUnread'] + ', nbUnreadItems: ' + nbUnreadItems);
|
|
|
|
|
2015-01-29 02:17:02 +01:00
|
|
|
if (! document.hidden && (response['nbUnread'] !== nbUnreadItems || unreadItems)) {
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
Miniflux.App.Log('Counter changed! Updating unread counter.');
|
|
|
|
unreadItems = false;
|
|
|
|
nbUnreadItems = response['nbUnread'];
|
|
|
|
updateCounters();
|
|
|
|
}
|
2015-01-29 02:17:02 +01:00
|
|
|
else if (document.hidden && ! first_run && current_unread) {
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
Miniflux.App.Log('New Unread! Updating pagetitle.');
|
|
|
|
unreadItems = true;
|
|
|
|
document.title = "↻ " + document.title;
|
2015-01-29 02:17:02 +01:00
|
|
|
}
|
|
|
|
else {
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
Miniflux.App.Log('No update.');
|
|
|
|
}
|
|
|
|
|
|
|
|
Miniflux.App.Log('unreadItems: ' + unreadItems);
|
|
|
|
};
|
2015-01-29 02:17:02 +01:00
|
|
|
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
request.open("POST", "?action=latest-feeds-items", true);
|
|
|
|
request.send();
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|