Skip to content

Commit

Permalink
Seen Posts: Fix "virtual scroller" experiment (better) (AprilSylph#1225)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon authored Aug 19, 2023
1 parent 518b9db commit 2d2a26d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/scripts/seen_posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ const markAsSeen = (articleElement) => {
observer.unobserve(articleElement);
timers.delete(articleElement);

const postElement = articleElement.closest(postSelector);
seenPosts.push(postElement.dataset.id);
const { dataset: { id } } = articleElement.closest(postSelector);
if (seenPosts.includes(id)) return;

seenPosts.push(id);
seenPosts.splice(0, seenPosts.length - 10000);
browser.storage.local.set({ [storageKey]: seenPosts });
};
Expand All @@ -56,13 +58,13 @@ const dimPosts = function (postElements) {
const { id } = postElement.dataset;
const timelineItem = getTimelineItemWrapper(postElement);

if (timelineItem.getAttribute(excludeAttribute) !== null) return;
const isFirstRender = timelineItem.getAttribute(excludeAttribute) === null;
timelineItem.setAttribute(excludeAttribute, '');

if (seenPosts.includes(id)) {
timelineItem.setAttribute(dimAttribute, '');
} else {
if (seenPosts.includes(id) === false) {
observer.observe(postElement.querySelector('article'));
} else if (isFirstRender) {
timelineItem.setAttribute(dimAttribute, '');
}
}
};
Expand Down

0 comments on commit 2d2a26d

Please sign in to comment.