Skip to content

Commit

Permalink
fix repeating timelines
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Jul 22, 2022
1 parent 3d03fc0 commit b274696
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
10 changes: 6 additions & 4 deletions layouts/home/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,11 +947,12 @@ async function appendTweet(t, timelineContainer, options = {}) {
return tweet;
}

async function renderTimeline(append = false) {
async function renderTimeline(append = false, sliceAmount = 0) {
let timelineContainer = document.getElementById('timeline');
if(!append) timelineContainer.innerHTML = '';
for(let i in timeline.data) {
let t = timeline.data[i];
let data = timeline.data.slice(sliceAmount, timeline.data.length);
for(let i in data) {
let t = data[i];
if (t.retweeted_status) {
await appendTweet(t.retweeted_status, timelineContainer, {
top: {
Expand Down Expand Up @@ -1104,9 +1105,10 @@ document.addEventListener('scroll', async () => {
loadingNewTweets = false;
return;
}
let originalLength = timeline.data.length;
timeline.data = timeline.data.concat(tl);
try {
await renderTimeline(true);
await renderTimeline(true, originalLength);
} catch(e) {
loadingNewTweets = false;
}
Expand Down
13 changes: 7 additions & 6 deletions layouts/profile/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ function renderProfile() {

updateSelection();


document.getElementById('profile-bio').innerHTML = escapeHTML(pageUser.description).replace(/\n/g, '<br>').replace(/((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g, '<a href="$1">$1</a>').replace(/(?<!\w)@([\w+]{1,15}\b)/g, `<a href="https://twitter.com/$1">@$1</a>`).replace(/(?<!\w)#([\w+]+\b)/g, `<a href="https://twitter.com/hashtag/$1">#$1</a>`);
if(vars.enableTwemoji) twemoji.parse(document.getElementById('profile-info'));

Expand Down Expand Up @@ -1622,18 +1621,19 @@ async function appendTweet(t, timelineContainer, options = {}) {
return tweet;
}

async function renderTimeline(append = false) {
async function renderTimeline(append = false, sliceAmount = 0) {
let timelineContainer = document.getElementById('timeline');
if(!append) timelineContainer.innerHTML = '';
if(pinnedTweet && subpage === "profile") await appendTweet(pinnedTweet, timelineContainer, {
let data = timeline.data.slice(sliceAmount, timeline.data.length);;
if(pinnedTweet && subpage === "profile" && !append) await appendTweet(pinnedTweet, timelineContainer, {
top: {
text: "Pinned Tweet",
icon: "\uf003",
color: "var(--link-color)"
}
})
for(let i in timeline.data) {
let t = timeline.data[i];
for(let i in data) {
let t = data[i];
if(pinnedTweet && t.id_str === pinnedTweet.id_str) continue;
if (t.retweeted_status) {
await appendTweet(t.retweeted_status, timelineContainer, {
Expand Down Expand Up @@ -1768,10 +1768,11 @@ window.addEventListener('scroll', async () => {
loadingNewTweets = false;
return;
}
let originalLength = timeline.data.length;
timeline.data = timeline.data.concat(tl);
if(previousLastTweet && previousLastTweet.id_str === timeline.data[timeline.data.length - 1].id_str) return stopLoad = true;
previousLastTweet = timeline.data[timeline.data.length - 1];
await renderTimeline(true);
await renderTimeline(true, originalLength);
setTimeout(() => {
setTimeout(() => {
loadingNewTweets = false;
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Old Twitter Layout (2022)",
"description": "A new extension that returns old Twitter's look.",
"version": "1.2.0",
"version": "1.2.1",
"manifest_version": 3,
"homepage_url": "https://github.com/dimdenGD/OldTwitter",
"background": {
Expand Down

0 comments on commit b274696

Please sign in to comment.