mirror of
https://github.com/zedeus/nitter.git
synced 2026-03-04 13:19:57 -05:00
Fix search repeating when the end has been reached
This commit is contained in:
@@ -12,7 +12,10 @@ function isDuplicate(item, itemClass) {
|
||||
const tweet = item.querySelector(".tweet-link");
|
||||
if (tweet == null) return false;
|
||||
const href = tweet.getAttribute("href");
|
||||
return document.querySelector(itemClass + " .tweet-link[href='" + href + "']") != null;
|
||||
return (
|
||||
document.querySelector(itemClass + " .tweet-link[href='" + href + "']") !=
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
@@ -38,11 +41,12 @@ window.onload = function () {
|
||||
var url = new URL(loadMore.children[0].href);
|
||||
url.searchParams.append("scroll", "true");
|
||||
|
||||
fetch(url.toString()).then(function (response) {
|
||||
if (response.status === 404) throw "error";
|
||||
|
||||
fetch(url.toString())
|
||||
.then(function (response) {
|
||||
if (response.status > 299) throw "error";
|
||||
return response.text();
|
||||
}).then(function (html) {
|
||||
})
|
||||
.then(function (html) {
|
||||
var parser = new DOMParser();
|
||||
var doc = parser.parseFromString(html, "text/html");
|
||||
loadMore.remove();
|
||||
@@ -59,7 +63,8 @@ window.onload = function () {
|
||||
if (newLoadMore == null) return;
|
||||
if (isTweet) container.appendChild(newLoadMore);
|
||||
else insertBeforeLast(container, newLoadMore);
|
||||
}).catch(function (err) {
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.warn("Something went wrong.", err);
|
||||
if (failed > 3) {
|
||||
loadMore.children[0].text = "Error";
|
||||
|
||||
@@ -168,6 +168,11 @@ proc getGraphTweetSearch*(query: Query; after=""): Future[Timeline] {.async.} =
|
||||
result = parseGraphSearch[Tweets](js, after)
|
||||
result.query = query
|
||||
|
||||
# when no more items are available the API just returns the last page in
|
||||
# full. this detects that and clears the page instead.
|
||||
if after.len > 0 and after[0..<64] == result.bottom[0..<64]:
|
||||
result.content.setLen(0)
|
||||
|
||||
proc getGraphUserSearch*(query: Query; after=""): Future[Result[User]] {.async.} =
|
||||
if query.text.len == 0:
|
||||
return Result[User](query: query, beginning: true)
|
||||
|
||||
@@ -27,7 +27,7 @@ proc createStatusRouter*(cfg: Config) =
|
||||
if @"scroll".len > 0:
|
||||
let replies = await getReplies(id, getCursor())
|
||||
if replies.content.len == 0:
|
||||
resp Http404, ""
|
||||
resp Http204
|
||||
resp $renderReplies(replies, prefs, getPath())
|
||||
|
||||
let conv = await getTweet(id, getCursor())
|
||||
|
||||
@@ -129,7 +129,8 @@ proc createTimelineRouter*(cfg: Config) =
|
||||
if @"scroll".len > 0:
|
||||
if query.fromUser.len != 1:
|
||||
var timeline = await getGraphTweetSearch(query, after)
|
||||
if timeline.content.len == 0: resp Http404
|
||||
if timeline.content.len == 0:
|
||||
resp Http204
|
||||
timeline.beginning = true
|
||||
resp $renderTweetSearch(timeline, prefs, getPath())
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user