Skip to content

Commit

Permalink
support suspended messages (#282) mfw
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Sep 30, 2023
1 parent c06d82e commit 0b38671
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
29 changes: 26 additions & 3 deletions layouts/home/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function fixTweetThreadLine() {
}

async function createShamelessPlug(firstTime = true) {
return;

let dimden = await API.user.getV2('dimdenEFF');
chrome.storage.local.set({'followingDeveloper': dimden.following}, () => {});

Expand Down Expand Up @@ -191,8 +193,11 @@ async function updateTimeline(mode = 'rewrite') {
s = s.value; tl = tl.value;
if(mode === 'rewrite' || mode === 'append') cursorBottom = tl.cursorBottom;
if(mode === 'rewrite' || mode === 'prepend') cursorTop = tl.cursorTop;

let suspended = tl.suspended;

tl = tl.list;
if(vars.timelineType === 'algo' || vars.timelineType === 'algov2') {
if((vars.timelineType === 'algo' || vars.timelineType === 'algov2') && !suspended) {
tl = tl.filter(t => !seenTweets.includes(t.id_str));
for(let t of tl) {
seenTweets.push(t.id_str);
Expand Down Expand Up @@ -221,7 +226,7 @@ async function updateTimeline(mode = 'rewrite') {
// first update
if (timeline.data.length === 0) {
timeline.data = tl;
renderTimeline({ mode: 'rewrite', data: tl });
renderTimeline({ mode: 'rewrite', data: tl, suspended });
}
// update
else {
Expand Down Expand Up @@ -290,7 +295,25 @@ async function renderTimeline(options = {}) {
if(!options.mode) options.mode = 'rewrite';
if(!options.data) options.data = timeline.data;
let timelineContainer = document.getElementById('timeline');
if(options.mode === 'rewrite') timelineContainer.innerHTML = '';
if(options.mode === 'rewrite') {
if(options.suspended) {
try {
timelineContainer.innerHTML = /*html*/`
<div style="color:var(--almost-black);padding:20px;word-break: break-word;" class="box">
<h2 class="nice-header" style="margin-bottom:0">${options.suspended.content.itemContent.content.headerText}</h2>
<p>${options.suspended.content.itemContent.content.bodyText.replace(/\sX\s/g, ' Twitter ')}</p>
<div>
${options.suspended.content.itemContent.content.bodyRichText.entities.map(e => `<a href="${e.ref.url}" target="_blank">${e.ref.url}</a>`).join('<br>')}
</div>
</div>
`;
document.getElementById('tweets-loading').hidden = true;
document.getElementById('load-more').hidden = true;
} catch(e) {
console.error(e);
}
} else timelineContainer.innerHTML = '';
}
let data = options.data;

let toRender = [];
Expand Down
9 changes: 6 additions & 3 deletions scripts/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,8 @@ const API = {
let out = {
list: tweets,
cursorBottom: cb ? cb.content.value : undefined,
cursorTop: ct ? ct.content.value : undefined
cursorTop: ct ? ct.content.value : undefined,
suspended: entries.find(e => e.entryId === 'messageprompt-suspended-prompt')
}
debugLog('timeline.getChronologicalV2', 'end', {cursor, count, out});
return resolve(out);
Expand Down Expand Up @@ -713,7 +714,8 @@ const API = {
let out = {
list,
cursorBottom: cb ? cb.content.operation.cursor.value : undefined,
cursorTop: ct ? ct.content.operation.cursor.value : undefined
cursorTop: ct ? ct.content.operation.cursor.value : undefined,
suspended: entries.find(e => e.entryId === 'messageprompt-suspended-prompt')
}
debugLog('timeline.getAlgorithmical', 'end', {cursor, count, out});
return resolve(out)
Expand Down Expand Up @@ -777,7 +779,8 @@ const API = {
let out = {
list: tweets,
cursorBottom: cb ? cb.content.value : undefined,
cursorTop: ct ? ct.content.value : undefined
cursorTop: ct ? ct.content.value : undefined,
suspended: entries.find(e => e.entryId === 'messageprompt-suspended-prompt')
}
for(let tweet of out.list) {
tweet.algo = true;
Expand Down
10 changes: 5 additions & 5 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1547,11 +1547,7 @@ async function appendTweet(t, timelineContainer, options = {}) {
}
if(t.socialContext) {
options.top = {};
if(t.socialContext.description) {
options.top.text = `<a target="_blank" href="https://twitter.com/i/topics/${t.socialContext.topic_id}">${t.socialContext.name}</a>`;
options.top.icon = "\uf008";
options.top.color = isDarkModeEnabled ? "#7e5eff" : "#3300FF";
} else if(t.socialContext.contextType === "Like") {
if(t.socialContext.contextType === "Like") {
if (!vars.heartsNotStars) {
LOC.replacer_liked_to_favorited.message.split('|').forEach(el => {
t.socialContext.text = t.socialContext.text.replace(new RegExp(el.split('->')[0], "g"), el.split('->')[1]);
Expand All @@ -1577,6 +1573,10 @@ async function appendTweet(t, timelineContainer, options = {}) {
options.top.text = t.socialContext.text;
options.top.icon = "\uf011";
options.top.color = isDarkModeEnabled ? "#7e5eff" : "#3300FF";
} else if(t.socialContext.topic_id) {
options.top.text = `<a target="_blank" href="https://twitter.com/i/topics/${t.socialContext.topic_id}">${t.socialContext.name}</a>`;
options.top.icon = "\uf008";
options.top.color = isDarkModeEnabled ? "#7e5eff" : "#3300FF";
} else {
console.log(t.socialContext);
}
Expand Down

0 comments on commit 0b38671

Please sign in to comment.