Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tweet Quality analyzer. RT to Like ratio. Problems: won't work if something is good both NSFW for example, because most people won't RT it.
// ==UserScript==
// @name TweetQuality
// @namespace http://skiilaa.me/
// @version 1.0
// @description Analyzes Tweet quality.
// @author skiilaa
// @match *://twitter.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const debugLog = false;
var userDDNameElement = document.querySelector("#user-dropdown .username");
if (!userDDNameElement) {
console.log("[TweetQuality] Not logged in.");
return;
}
var userName = userDDNameElement.children[0].innerText;
if (debugLog) console.log(`[TweetQuality] Logged in as ${userName}`);
function tweetCounterParse(x) {
if (x.endsWith("K")) {
return parseFloat(x.substring(0, x.length - 1)) * 1000;
} else if (x.endsWith("M")) {
return parseFloat(x.substring(0, x.length - 1)) * 1000000;
} else if (x == "") {
return 0;
} else {
return parseInt(x);
}
}
function update() {
var tweetList = document.getElementById("stream-items-id");
if (!tweetList) {
console.log(`[TweetQuality] Couldn't get tweet list`);
return;
}
var tweets = Array.from(tweetList.children).filter(x => x.dataset.itemId).filter(x => x.children[0].dataset.screenName == userName);
if (debugLog) console.log(tweets)
var tweetData = tweets.map(x => {
var rts = tweetCounterParse(x.querySelector(".js-actionRetweet .ProfileTweet-actionCountForPresentation").innerText);
var likes = tweetCounterParse(x.querySelector(".js-actionFavorite .ProfileTweet-actionCountForPresentation").innerText);
var result = "?";
if (likes != 0) {
result = (rts / likes * 100) + "%";
}
if (x.querySelector(".ProfileTweet-action-tweetQuality")) return;
var pointDisplay = document.createElement("div");
pointDisplay.classList.add("ProfileTweet-action");
pointDisplay.classList.add("ProfileTweet-action-tweetQuality");
var pointDisplaySpan = document.createElement("span");
pointDisplaySpan.classList.add("ProfileTweet-actionCount");
pointDisplaySpan.innerText = result + "";
pointDisplay.appendChild(pointDisplaySpan)
x.querySelector(`.ProfileTweet-actionList`).appendChild(pointDisplay);
});
}
var prevTweetList = null;
setInterval(() => {
var tweetList = document.getElementById("stream-items-id") ? document.getElementById("stream-items-id").innerHTML : null;
if (tweetList != prevTweetList) {
if (tweetList != null) {
if (debugLog) console.log("[TweetQuality] Updating!")
update();
}
prevTweetList = tweetList;
}
}, 500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.