X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;ds=sidebyside;f=js%2Fviewfeed.js;h=886d13f066ba00f9aa8464dd428006b1004b7dcf;hb=50052fb78a3a9d1bb3fa488e7fd7b23125c38124;hp=4d65669617416a86138eb479d144ccbef0cd97de;hpb=9563e3bcd662b87ea6779714b51afb61571dd32d;p=tt-rss.git diff --git a/js/viewfeed.js b/js/viewfeed.js index 4d656696..886d13f0 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -1007,28 +1007,25 @@ function postMouseOut(id) { function unpackVisibleHeadlines() { if (!isCdmMode()) return; - $$("#headlines-frame div[id*=RROW][data-content]").each((row) => { - //console.log('checking', row.id); + const rows = $$("#headlines-frame div[id*=RROW][data-content]"); + const threshold = $("headlines-frame").scrollTop + $("headlines-frame").offsetHeight + 300; - if (row.offsetTop <= $("headlines-frame").scrollTop + $("headlines-frame").offsetHeight) { - console.log("unpacking: " + row.id); + for (let i = 0; i < rows.length; i++) { + const row = rows[i]; - let content; + if (row.offsetTop <= threshold) { + console.log("unpacking: " + row.id); - try { - content = JSON.parse(row.getAttribute("data-content")); - } catch (e) { - content = "Error decoding content: " + row.getAttribute("data-content"); - } + const content = row.getAttribute("data-content"); - row.select(".cdmContentInner")[0].innerHTML = content; + row.select(".cdmContentInner")[0].innerHTML = content; row.removeAttribute("data-content"); PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, row); - } else { - throw $break; - } - }); + } else { + break; + } + } } function headlines_scroll_handler(e) { @@ -1041,8 +1038,6 @@ function headlines_scroll_handler(e) { _headlines_scroll_offset = e.scrollTop; - const hsp = $("headlines-spacer"); - unpackVisibleHeadlines(); // set topmost child in the buffer as active @@ -1052,18 +1047,18 @@ function headlines_scroll_handler(e) { const rows = $$("#headlines-frame > div[id*=RROW]"); for (let i = 0; i < rows.length; i++) { - const child = rows[i]; + const row = rows[i]; - if ($("headlines-frame").scrollTop <= child.offsetTop && - child.offsetTop - $("headlines-frame").scrollTop < 100 && - child.getAttribute("data-article-id") != _active_article_id) { + if ($("headlines-frame").scrollTop <= row.offsetTop && + row.offsetTop - $("headlines-frame").scrollTop < 100 && + row.getAttribute("data-article-id") != _active_article_id) { if (_active_article_id) { const row = $("RROW-" + _active_article_id); if (row) row.removeClassName("active"); } - _active_article_id = child.getAttribute("data-article-id"); + _active_article_id = row.getAttribute("data-article-id"); showArticleInHeadlines(_active_article_id, true); updateSelectedPrompt(); break; @@ -1072,6 +1067,8 @@ function headlines_scroll_handler(e) { } if (!_infscroll_disable) { + const hsp = $("headlines-spacer"); + if (hsp && hsp.offsetTop - 250 <= e.scrollTop + e.offsetHeight) { hsp.innerHTML = " " + @@ -1087,33 +1084,31 @@ function headlines_scroll_handler(e) { updateFloatingTitle(); } - catchupCurrentBatchIfNeeded(); - if (getInitParam("cdm_auto_catchup") == 1) { - // let's get DOM some time to settle down - const ts = new Date().getTime(); - if (ts - _last_headlines_update < 100) return; + let rows = $$("#headlines-frame > div[id*=RROW][class*=Unread]"); - $$("#headlines-frame > div[id*=RROW][class*=Unread]").each( - function(child) { - if ($("headlines-frame").scrollTop > (child.offsetTop + child.offsetHeight/2)) { - - const id = child.getAttribute("data-article-id") + for (let i = 0; i < rows.length; i++) { + const row = rows[i]; + + if ($("headlines-frame").scrollTop > (row.offsetTop + row.offsetHeight/2)) { - if (catchup_id_batch.indexOf(id) == -1) - catchup_id_batch.push(id); + const id = row.getAttribute("data-article-id") - //console.log("auto_catchup_batch: " + catchup_id_batch.toString()); - } + if (catchup_id_batch.indexOf(id) == -1) + catchup_id_batch.push(id); - }); + //console.log("auto_catchup_batch: " + catchup_id_batch.toString()); + } else { + break; + } + } if (_infscroll_disable) { - const child = $$("#headlines-frame div[id*=RROW]").last(); + const row = $$("#headlines-frame div[id*=RROW]").last(); - if (child && $("headlines-frame").scrollTop > - (child.offsetTop + child.offsetHeight - 50)) { + if (row && $("headlines-frame").scrollTop > + (row.offsetTop + row.offsetHeight - 50)) { console.log("we seem to be at an end"); @@ -1138,7 +1133,7 @@ function openNextUnreadFeed() { function catchupBatchedArticles() { if (catchup_id_batch.length > 0 && !_infscroll_request_sent && !_catchup_request_sent) { - console.log("catchupBatchedArticles: working"); + console.log("catchupBatchedArticles, size=", catchup_id_batch.length); // make a copy of the array const batch = catchup_id_batch.slice(); @@ -1156,7 +1151,6 @@ function catchupBatchedArticles() { const batch = reply.ids; batch.each(function (id) { - console.log(id); const elem = $("RROW-" + id); if (elem) elem.removeClassName("Unread"); catchup_id_batch.remove(id); @@ -1807,14 +1801,3 @@ function updateFloatingTitle(unread_only) { } } } - -function catchupCurrentBatchIfNeeded() { - if (catchup_id_batch.length > 0) { - window.clearTimeout(catchup_timeout_id); - catchup_timeout_id = window.setTimeout(catchupBatchedArticles, 1000); - - if (catchup_id_batch.length >= 10) { - catchupBatchedArticles(); - } - } -}