extension/script.js
/**
 * Extracts the scores from a tweet element.
 * @param {HTMLElement} tweet The tweet to process.
 * @returns {object} Either the scores or a bailout message.
 */
Extracts the scores from a tweet element.
@param {HTMLElement} tweet The tweet to process.
@returns {object} Either the scores or a bailout message.
Extracts the scores from a tweet element . @param { HTMLElement } tweet The tweet to process . @returns { object } Either the scores or a bailout message .
function calculateFeedTweetScores(tweet) {
    const replyButton = tweet.querySelector(FEED_TWEET_REPLY_SELECTOR);
    const likeButton = tweet.querySelector(FEED_TWEET_LIKE_SELECTOR);
    const retweetButton = tweet.querySelector(FEED_TWEET_RETWEET_SELECTOR);
    if (replyButton?.hasAttribute("aria-disabled") || likeButton?.hasAttribute("aria-disabled") || retweetButton?.hasAttribute("aria-disabled")) {
        return {bailout: true, msg: "Cannot calculate ratios for tweets which are not fully interactive."};
    }
    const replyButtonText = replyButton?.textContent;
    const likeButtonText = likeButton?.textContent;
    const retweetButtonText = retweetButton?.textContent;
    const replies = extractNumberFromFormattedText(replyButtonText);
    const likes = extractNumberFromFormattedText(likeButtonText);
    const retweets = extractNumberFromFormattedText(retweetButtonText);
    if (isNaN(replies) || isNaN(likes) || isNaN(retweets)) {
        return {bailout: true, msg: "Cannot calculate ratios for tweet due to unparseable text contents."};
    }
    return makeScores(retweets, likes, replies);
}
function calculateFeedTweetScores ( tweet ) { const replyButton = tweet . querySelector ( FEED_TWEET_REPLY_SELECTOR ) ; const likeButton = tweet . querySelector ( FEED_TWEET_LIKE_SELECTOR ) ; const retweetButton = tweet . querySelector ( FEED_TWEET_RETWEET_SELECTOR ) ; if ( replyButton ?. hasAttribute ( "aria-disabled" ) || likeButton ?. hasAttribute ( "aria-disabled" ) || retweetButton ?. hasAttribute ( "aria-disabled" ) ) { return { bailout : true , msg : "Cannot calculate ratios for tweets which are not fully interactive." } ; } const replyButtonText = replyButton ?. textContent ; const likeButtonText = likeButton ?. textContent ; const retweetButtonText = retweetButton ?. textContent ; const replies = extractNumberFromFormattedText ( replyButtonText ) ; const likes = extractNumberFromFormattedText ( likeButtonText ) ; const retweets = extractNumberFromFormattedText ( retweetButtonText ) ; if ( isNaN ( replies ) || isNaN ( likes ) || isNaN ( retweets ) ) { return { bailout : true , msg : "Cannot calculate ratios for tweet due to unparseable text contents." } ; } return makeScores ( retweets , likes , replies ) ; }
Extracts the scores from a tweet element.
Extracts the scores from a tweet element .
// If a tweet is not fully interactive, ratios will be skewed and it does not make sense to display a ratio bar. // We don't want people to get away with just disabling replies! >:)