diff --git a/scripts/helpers.js b/scripts/helpers.js index 38444c58..ac40f582 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -1615,7 +1615,7 @@ async function appendTweet(t, timelineContainer, options = {}) { if(!options.mainTweet && typeof mainTweetLikers !== 'undefined' && !location.pathname.includes("retweets/with_comments") && !document.querySelector('.modal')) { tweet.addEventListener('click', async e => { - if(e.target.className && (e.target.classList.contains('tweet') || e.target.classList.contains('tweet-body') || e.target.classList.contains('tweet-reply-to') || e.target.className === 'tweet-interact' || e.target.className === 'tweet-media')) { + if (!e.target.closest(".tweet-button") && !e.target.closest(".tweet-edit-section") && !e.target.closest(".dropdown-menu") && !e.target.closest(".tweet-media-element") && !e.target.closest("a") && !e.target.closest("button")) { document.getElementById('loading-box').hidden = false; savePageData(); history.pushState({}, null, `https://twitter.com/${t.user.screen_name}/status/${t.id_str}`); @@ -1641,18 +1641,10 @@ async function appendTweet(t, timelineContainer, options = {}) { currentLocation = location.pathname; } }); - tweet.addEventListener('mousedown', e => { - if(e.button === 1) { - e.preventDefault(); - if(e.target.className && (e.target.classList.contains('tweet') || e.target.classList.contains('tweet-body') || e.target.classList.contains('tweet-reply-to') || e.target.className === 'tweet-interact' || e.target.className === 'tweet-media')) { - openInNewTab(`https://twitter.com/${t.user.screen_name}/status/${t.id_str}`); - } - } - }); } else { if(!options.mainTweet) { tweet.addEventListener('click', e => { - if(e.target.className && (e.target.classList.contains('tweet') || e.target.classList.contains('tweet-body') || e.target.classList.contains('tweet-reply-to') || e.target.className === 'tweet-interact' || e.target.className === 'tweet-media')) { + if(!e.target.closest(".tweet-button") && !e.target.closest(".tweet-edit-section") && !e.target.closest(".dropdown-menu") && !e.target.closest(".tweet-media-element") && !e.target.closest("a") && !e.target.closest("button")) { let tweetData = t; if(tweetData.retweeted_status) tweetData = tweetData.retweeted_status; tweet.classList.add('tweet-preload'); @@ -1663,16 +1655,17 @@ async function appendTweet(t, timelineContainer, options = {}) { new TweetViewer(user, tweetData); } }); - tweet.addEventListener('mousedown', e => { - if(e.button === 1) { - e.preventDefault(); - if(e.target.className && (e.target.classList.contains('tweet') || e.target.classList.contains('tweet-body') || e.target.classList.contains('tweet-reply-to') || e.target.className === 'tweet-interact')) { - openInNewTab(`https://twitter.com/${t.user.screen_name}/status/${t.id_str}`); - } - } - }); } } + tweet.addEventListener('mousedown', e => { + if(e.button === 1) { + // tweet-media-element is clickable, since it should open the tweet in a new tab. + if(!e.target.closest(".tweet-button") && !e.target.closest(".tweet-edit-section") && !e.target.closest(".dropdown-menu") && !e.target.closest("a") && !e.target.closest("button")) { + e.preventDefault(); + openInNewTab(`https://twitter.com/${t.user.screen_name}/status/${t.id_str}`); + } + } + }); tweet.tabIndex = -1; tweet.className = `tweet ${options.mainTweet ? 'tweet-main' : location.pathname.includes('/status/') ? 'tweet-replying' : ''}`.trim(); tweet.dataset.tweetId = t.id_str; @@ -1847,7 +1840,7 @@ async function appendTweet(t, timelineContainer, options = {}) { ${!isMatchingLanguage && options.mainTweet ? /*html*/`
- ${LOC.view_translation.message} + ${LOC.view_translation.message} ` : ``} ${t.extended_entities && t.extended_entities.media ? /*html*/`
@@ -1893,7 +1886,7 @@ async function appendTweet(t, timelineContainer, options = {}) {
` : ''} ${!isQuoteMatchingLanguage ? /*html*/` - ${LOC.view_translation.message} + ${LOC.view_translation.message} ` : ``} ` : ``} @@ -1933,8 +1926,8 @@ async function appendTweet(t, timelineContainer, options = {}) { ` : ''}
${new Date(t.created_at).toLocaleTimeString(undefined, { hour: 'numeric', minute: 'numeric' }).toLowerCase()} - ${new Date(t.created_at).toLocaleDateString(undefined, { day: 'numeric', month: 'short', year: 'numeric' })}  ・ ${t.source ? t.source.split('>')[1].split('<')[0] : 'Unknown'}
- ${options.mainTweet ? '' : formatLargeNumber(t.reply_count).replace(/\s/g, ',')} - ${options.mainTweet ? '' : formatLargeNumber(t.retweet_count).replace(/\s/g, ',')} + ${options.mainTweet ? '' : formatLargeNumber(t.reply_count).replace(/\s/g, ',')} + ${options.mainTweet ? '' : formatLargeNumber(t.retweet_count).replace(/\s/g, ',')} - ${options.mainTweet ? '' : formatLargeNumber(t.favorite_count).replace(/\s/g, ',')} + ${options.mainTweet ? '' : formatLargeNumber(t.favorite_count).replace(/\s/g, ',')} ${(vars.showBookmarkCount || options.mainTweet) && typeof t.bookmark_count !== 'undefined' ? - /*html*/`${formatLargeNumber(t.bookmark_count).replace(/\s/g, ',')}` : + /*html*/`${formatLargeNumber(t.bookmark_count).replace(/\s/g, ',')}` : ''} ${vars.seeTweetViews && t.ext && t.ext.views && t.ext.views.r && t.ext.views.r.ok && t.ext.views.r.ok.count ? /*html*/`${formatLargeNumber(t.ext.views.r.ok.count).replace(/\s/g, ',')}` : ''} - + -