Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dimdenGD/OldTwitter
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Oct 8, 2023
2 parents 3b255a0 + 49bbaef commit 5402e5e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
51 changes: 38 additions & 13 deletions layouts/header/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,10 @@ let userDataFunction = async user => {
if(inboxData) {
let conversations = Array.isArray(inboxData.conversations) ? inboxData.conversations : Object.values(inboxData.conversations);
let realConvo = conversations.find(c => c.id_str === lastConvo.id_str);
if(+lastConvo.max_entry_id >= +realConvo.last_read_event_id) {
API.inbox.markRead(lastConvo.max_entry_id);
realConvo.last_read_event_id = lastConvo.max_entry_id;
let lastEventId = lastConvo.conversations[lastConvo.conversation_id].sort_event_id; //reactions dont count towards max_entry_id, but they do towards sort_event_id so that conversations appear above others when theres a new reaction
if(+lastEventId >= +realConvo.last_read_event_id) {
API.inbox.markRead(lastEventId);
realConvo.last_read_event_id = lastEventId;
}
}
window.history.pushState(null, document.title, window.location.href)
Expand Down Expand Up @@ -1048,11 +1049,35 @@ let userDataFunction = async user => {
messageElement.classList.add('inbox-message-unread');
isUnread = true;
}
let messageEntry = {}
if(messageUsers.length === 1) { //regular user
if (messageUsers[0].default_profile_image && vars.useOldDefaultProfileImage) {
messageEntry.icon = chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(messageUsers[0].id_str) % 7}_normal.png`);
} else {
messageEntry.icon = messageUsers[0].profile_image_url_https;
}

messageEntry.name = escapeHTML(messageUsers[0].name);
messageEntry.screen_name = '@' + messageUsers[0].screen_name;
} else if (messageUsers.length > 1) { //groups
messageEntry.icon = c.avatar_image_https || chrome.runtime.getURL('/images/group.jpg');
messageEntry.name = c.name ? escapeHTML(c.name) : messageUsers.map(i => escapeHTML(i.name)).join(', ').slice(0, 128);
messageEntry.screen_name = '';
} else if (messageUsers.length === 0) { //weird twitter bug, if you dm yourself (why?) it counts as no messageUsers
if (user.default_profile_image && vars.useOldDefaultProfileImage) {
messageEntry.icon = chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(user.id_str) % 7}_normal.png`);
} else {
messageEntry.icon = user.profile_image_url_https;
}

messageEntry.name = user.name;
messageEntry.screen_name = '@' + user.screen_name;
}
messageElement.innerHTML = /*html*/`
<img src="${messageUsers.length === 1 ? `${(messageUsers[0].default_profile_image && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(messageUsers[0].id_str) % 7}_normal.png`): messageUsers[0].profile_image_url_https}` : (c.avatar_image_https || chrome.runtime.getURL(`/images/group.jpg`))}" width="48" height="48" class="inbox-message-avatar">
<img src="${messageEntry.icon}" width="48" height="48" class="inbox-message-avatar">
<div class="inbox-text">
<b class="inbox-name">${messageUsers.length === 1 ? escapeHTML(messageUsers[0].name) : (c.name ? escapeHTML(c.name) : messageUsers.map(i => escapeHTML(i.name)).join(', ').slice(0, 128))}</b>
<span class="inbox-screenname">${messageUsers.length === 1 ? "@"+messageUsers[0].screen_name : ''}</span>
<b class="inbox-name">${messageEntry.name}</b>
<span class="inbox-screenname">${messageEntry.screen_name}</span>
<span class="inbox-time">${timeElapsed(new Date(+lastMessage.time))}</span>
<br>
<span class="inbox-message-preview">${lastMessage.reason ? 'Accepted conversation' : lastMessage.message_data.text.startsWith('dmservice_reaction_') ? `${lastMessage.message_data.sender_id === user.id_str ? 'You reacted to message' : `${escapeHTML(lastMessageUser.name)} reacted to message`}` : escapeHTML(lastMessage.message_data.text)}</span>
Expand All @@ -1071,9 +1096,9 @@ let userDataFunction = async user => {
modal.querySelector('.name-top').hidden = false;
modal.querySelector('.inbox').hidden = true;
modal.querySelector('.new-message-box').hidden = true;
messageHeaderName.innerText = messageUsers.length === 1 ? messageUsers[0].name : (c.name || messageUsers.map(i => i.name).join(', ').slice(0, 80));
messageHeaderAvatar.src = messageUsers.length === 1 ? `${(messageUsers[0].default_profile_image && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(messageUsers[0].id_str) % 7}_normal.png`): messageUsers[0].profile_image_url_https}` : (c.avatar_image_https || chrome.runtime.getURL(`/images/group.jpg`));
if(messageUsers.length === 1) messageHeaderLink.href = `https://twitter.com/${messageUsers[0].screen_name}`;
messageHeaderName.innerText = messageEntry.name;
messageHeaderAvatar.src = messageEntry.icon;
if(messageUsers.length <= 1) messageHeaderLink.href = `https://twitter.com/${messageEntry.screen_name}`;
setTimeout(() => {
modal.querySelector(".message-new-input").focus();
if(tweetUrlToShareInDMs) modal.querySelector(".message-new-input").value = tweetUrlToShareInDMs;
Expand Down Expand Up @@ -1222,7 +1247,7 @@ let userDataFunction = async user => {
let userElement = document.createElement('div');
userElement.classList.add('new-message-user');
userElement.innerHTML = `
<img class="new-message-user-avatar" src="${`${(u.default_profile_image && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(u.id_str) % 7}_normal.png`): u.profile_image_url_https}`.replace("_normal", "_bigger")}" width="48" height="48">
<img class="new-message-user-avatar" src="${`${(u.profile_image_url_https.includes('default_profile_images') && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(u.id_str) % 7}_normal.png`): u.profile_image_url_https}`.replace("_normal", "_bigger")}" width="48" height="48">
<div class="new-message-user-text">
<b class="new-message-user-name">${escapeHTML(u.name)}</b>
<span class="new-message-user-screenname">@${u.screen_name}</span>
Expand All @@ -1239,7 +1264,7 @@ let userDataFunction = async user => {
modal.querySelector('.inbox').hidden = true;
modal.querySelector('.new-message-box').hidden = true;
messageHeaderName.innerText = u.name;
messageHeaderAvatar.src = `${(u.default_profile_image && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(u.id_str) % 7}_normal.png`): u.profile_image_url_https}`;
messageHeaderAvatar.src = `${(u.profile_image_url_https.includes('default_profile_images') && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(u.id_str) % 7}_normal.png`): u.profile_image_url_https}`;
messageHeaderLink.href = `https://twitter.com/${u.screen_name}`;
setTimeout(() => {
modal.querySelector(".message-new-input").focus();
Expand Down Expand Up @@ -1636,7 +1661,7 @@ let userDataFunction = async user => {
userElement.className = 'search-result-item';
if(index === 0) userElement.classList.add('search-result-item-active');
userElement.innerHTML = `
<img width="16" height="16" class="search-result-item-avatar" src="${`${(user.default_profile_image && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(user.id_str) % 7}_normal.png`): user.profile_image_url_https}`}">
<img width="16" height="16" class="search-result-item-avatar" src="${`${(user.profile_image_url_https.includes('default_profile_images') && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(user.id_str) % 7}_normal.png`): user.profile_image_url_https}`}">
<span class="search-result-item-name ${user.verified || user.id_str === '1708130407663759360' ? 'search-result-item-verified' : ''}">${escapeHTML(user.name)}</span>
<span class="search-result-item-screen-name">@${user.screen_name}</span>
`;
Expand Down Expand Up @@ -1989,7 +2014,7 @@ let userDataFunction = async user => {
userElement.href = `/${user.screen_name}`;
userElement.className = 'search-result-item';
userElement.innerHTML = `
<img width="16" height="16" class="search-result-item-avatar" src="${`${(user.default_profile_image && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(user.id_str) % 7}_normal.png`): user.profile_image_url_https}`}">
<img width="16" height="16" class="search-result-item-avatar" src="${`${(user.profile_image_url_https.includes('default_profile_images') && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(user.id_str) % 7}_normal.png`): user.profile_image_url_https}`}">
<span class="search-result-item-name ${user.verified || user.id_str === '1708130407663759360' ? 'search-result-item-verified' : ''}">${user.name}</span>
<span class="search-result-item-screen-name">@${user.screen_name}</span>
`;
Expand Down
5 changes: 4 additions & 1 deletion scripts/injection.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,15 @@ if(realPath === '/intent/follow') {
let screen_name = location.search.split('screen_name=')[1].split('&')[0];
location.replace(`/${screen_name}`);
}
if (!hrefUrl.includes('newtwitter=true') &&
if (
!hrefUrl.includes('newtwitter=true') &&
(
realPath.startsWith('/i/flow/') ||
realPath.startsWith('/i/premium_sign_up/') ||
realPath.startsWith('/i/events/') ||
realPath.startsWith('/i/spaces/') ||
realPath.startsWith('/i/oauth2') ||
realPath.startsWith('/account') ||
realPath.startsWith('/settings') ||
/^\/[A-z-0-9-_]{1,15}\/status\/\d{5,32}\/analytics$/.test(realPath)
)
Expand Down

0 comments on commit 5402e5e

Please sign in to comment.