Skip to content

Commit

Permalink
add share tweet in dms button
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Sep 17, 2023
1 parent b05a7e9 commit 95acbca
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 3 deletions.
4 changes: 3 additions & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,5 +575,7 @@
"uploading": { "message": "Uploading" },
"finalization": { "message": "Finalization" },
"processing": { "message": "Processing" },
"quotes": { "message": "Quotes" }
"quotes": { "message": "Quotes" },
"share_tweet_in_dms": { "message": "Share tweet in DMs" },
"share_tweet_to": { "message": "Share tweet to..." }
}
4 changes: 3 additions & 1 deletion _locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -566,5 +566,7 @@
"uploading": { "message": "Загрузка" },
"finalization": { "message": "Завершение" },
"processing": { "message": "Обработка" },
"quotes": { "message": "Цитаты" }
"quotes": { "message": "Цитаты" },
"share_tweet_in_dms": { "message": "Поделиться твитом в сообщениях" },
"share_tweet_to": { "message": "Поделиться твитом..." }
}
4 changes: 3 additions & 1 deletion _locales/uk/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -566,5 +566,7 @@
"uploading": { "message": "Завантаження" },
"finalization": { "message": "Завершення" },
"processing": { "message": "Обробка" },
"quotes": { "message": "Цитати" }
"quotes": { "message": "Цитати" },
"share_tweet_in_dms": { "message": "Поширити твіт повідомленням" },
"share_tweet_to": { "message": "Поширити твіт..." }
}
5 changes: 5 additions & 0 deletions layouts/header/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let notificationsOpened = false;
let isDarkModeEnabled = typeof vars !== 'undefined' ? (vars.darkMode || (vars.timeMode && isDark())) : false;
let activeTweet;
let seenAlgoTweets = [], algoTweetsChanged = false;
let tweetUrlToShareInDMs = null;
setInterval(() => {
if(!algoTweetsChanged) return;
algoTweetsChanged = false;
Expand Down Expand Up @@ -1065,6 +1066,7 @@ let userDataFunction = async user => {
if(messageUsers.length === 1) messageHeaderLink.href = `https://twitter.com/${messageUsers[0].screen_name}`;
setTimeout(() => {
modal.querySelector(".message-new-input").focus();
if(tweetUrlToShareInDMs) modal.querySelector(".message-new-input").value = tweetUrlToShareInDMs;
});

renderConversation(messageData, c.conversation_id);
Expand Down Expand Up @@ -1153,6 +1155,7 @@ let userDataFunction = async user => {
if(location.hash === '#dm') {
location.hash = "";
}
tweetUrlToShareInDMs = null;
});
modal.querySelector('.modal-close').hidden = true;
const inboxList = modal.querySelector('.inbox-list');
Expand Down Expand Up @@ -1228,6 +1231,7 @@ let userDataFunction = async user => {
messageHeaderLink.href = `https://twitter.com/${u.screen_name}`;
setTimeout(() => {
modal.querySelector(".message-new-input").focus();
if(tweetUrlToShareInDMs) modal.querySelector(".message-new-input").value = tweetUrlToShareInDMs;
});

renderConversation(messageData, `${user.id_str}-${u.id_str}`);
Expand Down Expand Up @@ -2249,6 +2253,7 @@ let userDataFunction = async user => {
messageHeaderLink.href = `https://twitter.com/${u.screen_name}`;
setTimeout(() => {
modal.querySelector(".message-new-input").focus();
if(tweetUrlToShareInDMs) modal.querySelector(".message-new-input").value = tweetUrlToShareInDMs;
});

renderConversation(messageData, convo_id);
Expand Down
3 changes: 3 additions & 0 deletions layouts/header/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,9 @@ span.tweet-body-text {
.tweet-interact-more-menu-share:before {
content: "\f185"
}
.tweet-interact-more-menu-share-dms:before {
content: "\f157"
}

.tweet-interact-more-menu-analytics:before {
content: "\f200"
Expand Down
10 changes: 10 additions & 0 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,7 @@ async function appendTweet(t, timelineContainer, options = {}) {
<span class="tweet-interact-more-menu-copy">${LOC.copy_link.message}</span>
<span class="tweet-interact-more-menu-embed">${LOC.embed_tweet.message}</span>
${navigator.canShare ? `<span class="tweet-interact-more-menu-share">${LOC.share_tweet.message}</span>` : ''}
<span class="tweet-interact-more-menu-share-dms">${LOC.share_tweet_in_dms.message}</span>
<span class="tweet-interact-more-menu-newtwitter">${LOC.open_tweet_newtwitter.message}</span>
${t.user.id_str === user.id_str ? /*html*/`
<hr>
Expand Down Expand Up @@ -2317,6 +2318,7 @@ async function appendTweet(t, timelineContainer, options = {}) {
const tweetInteractMoreMenuCopyUserId = tweet.getElementsByClassName('tweet-interact-more-menu-copy-user-id')[0];
const tweetInteractMoreMenuEmbed = tweet.getElementsByClassName('tweet-interact-more-menu-embed')[0];
const tweetInteractMoreMenuShare = tweet.getElementsByClassName('tweet-interact-more-menu-share')[0];
const tweetInteractMoreMenuShareDMs = tweet.getElementsByClassName('tweet-interact-more-menu-share-dms')[0];
const tweetInteractMoreMenuNewtwitter = tweet.getElementsByClassName('tweet-interact-more-menu-newtwitter')[0];
const tweetInteractMoreMenuAnalytics = tweet.getElementsByClassName('tweet-interact-more-menu-analytics')[0];
const tweetInteractMoreMenuRefresh = tweet.getElementsByClassName('tweet-interact-more-menu-refresh')[0];
Expand Down Expand Up @@ -3298,6 +3300,14 @@ async function appendTweet(t, timelineContainer, options = {}) {
if(tweetInteractMoreMenuShare) tweetInteractMoreMenuShare.addEventListener('click', () => {
navigator.share({ url: `https://twitter.com/${t.user.screen_name}/status/${t.id_str}` });
});
tweetInteractMoreMenuShareDMs.addEventListener('click', () => {
tweetUrlToShareInDMs = `https://twitter.com/${t.user.screen_name}/status/${t.id_str}`;
document.getElementById('messages').click();
setTimeout(() => {
let title = document.querySelector('div.inbox h1.nice-header.larger');
title.innerText = LOC.share_tweet_to.message;
});
});
tweetInteractMoreMenuNewtwitter.addEventListener('click', () => {
openInNewTab(`https://twitter.com/${t.user.screen_name}/status/${t.id_str}?newtwitter=true`);
});
Expand Down
10 changes: 10 additions & 0 deletions scripts/tweetviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ class TweetViewer {
<span class="tweet-interact-more-menu-copy">${LOC.copy_link.message}</span>
<span class="tweet-interact-more-menu-embed">${LOC.embed_tweet.message}</span>
${navigator.canShare ? `<span class="tweet-interact-more-menu-share">${LOC.share_tweet.message}</span>` : ''}
<span class="tweet-interact-more-menu-share-dms">${LOC.share_tweet_in_dms.message}</span>
<span class="tweet-interact-more-menu-newtwitter">${LOC.open_tweet_newtwitter.message}</span>
${t.user.id_str === user.id_str ? /*html*/`
<hr>
Expand Down Expand Up @@ -1397,6 +1398,7 @@ class TweetViewer {
const tweetInteractMoreMenuLog = tweet.getElementsByClassName('tweet-interact-more-menu-log')[0];
const tweetInteractMoreMenuEmbed = tweet.getElementsByClassName('tweet-interact-more-menu-embed')[0];
const tweetInteractMoreMenuShare = tweet.getElementsByClassName('tweet-interact-more-menu-share')[0];
const tweetInteractMoreMenuShareDMs = tweet.getElementsByClassName('tweet-interact-more-menu-share-dms')[0];
const tweetInteractMoreMenuNewtwitter = tweet.getElementsByClassName('tweet-interact-more-menu-newtwitter')[0];
const tweetInteractMoreMenuAnalytics = tweet.getElementsByClassName('tweet-interact-more-menu-analytics')[0];
const tweetInteractMoreMenuRefresh = tweet.getElementsByClassName('tweet-interact-more-menu-refresh')[0];
Expand Down Expand Up @@ -2272,6 +2274,14 @@ class TweetViewer {
if(tweetInteractMoreMenuShare) tweetInteractMoreMenuShare.addEventListener('click', () => {
navigator.share({ url: `https://twitter.com/${t.user.screen_name}/status/${t.id_str}` });
});
tweetInteractMoreMenuShareDMs.addEventListener('click', () => {
tweetUrlToShareInDMs = `https://twitter.com/${t.user.screen_name}/status/${t.id_str}`;
document.getElementById('messages').click();
setTimeout(() => {
let title = document.querySelector('div.inbox h1.nice-header.larger');
title.innerText = LOC.share_tweet_to.message;
});
});
tweetInteractMoreMenuNewtwitter.addEventListener('click', () => {
openInNewTab(`https://twitter.com/${t.user.screen_name}/status/${t.id_str}?newtwitter=true`);
});
Expand Down

0 comments on commit 95acbca

Please sign in to comment.