Last active
June 14, 2025 12:18
-
-
Save samir-dahal/58e015ee91691416d4778dffebc13330 to your computer and use it in GitHub Desktop.
Set the Twitter detail page to automatically default to the "Most liked" filter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//UPDATE: Pls use this new script as of June 2025 | |
//https://gist.github.com/KyleF0X/f191fd223586973f3bf67cce394a98f6 | |
(function () { | |
const statusMatch = /https:\/\/x\.com\/[^\/]+\/status\/\d+/; | |
const MOST_RELEVANT = "most relevant"; | |
const MOST_LIKED = "most liked"; | |
let toNavigateUrl = null; | |
function findSpanByText(text) { | |
var aTags = document.getElementsByTagName("span"); | |
for (var i = 0; i < aTags.length; i++) { | |
if (aTags[i].textContent.toLowerCase() == text) { | |
return aTags[i]; | |
} | |
} | |
return null; | |
} | |
function performAction(elm) { | |
const sortReply = findSpanByText(MOST_RELEVANT); | |
if (sortReply) { | |
console.log("Found sort reply button"); | |
sortReply.click(); //show sorting hovercard | |
setTimeout(() => { | |
const mostLiked = findSpanByText(MOST_LIKED); | |
if (mostLiked) { | |
console.log('found most liked'); | |
} | |
mostLiked?.click(); //sort by most liked | |
}, 500) | |
} | |
} | |
function runWhenReady(readySelector, callback) { | |
var numAttempts = 0; | |
var tryNow = function () { | |
var elem = document.querySelector(readySelector); | |
if (elem && window.location.href === toNavigateUrl) { | |
console.log('Found: ' + elem); | |
callback(elem); | |
} else { | |
numAttempts++; | |
if (numAttempts >= 34) { | |
console.warn('Giving up after 34 attempts. Could not find: ' + readySelector); | |
} else { | |
setTimeout(tryNow, 250 * Math.pow(1.1, numAttempts)); | |
} | |
} | |
}; | |
tryNow(); | |
} | |
window.navigation.addEventListener("navigate", (event) => { | |
if (!statusMatch.test(event.destination.url)) return; | |
toNavigateUrl = event.destination.url; | |
runWhenReady("article[data-testid='tweet']", performAction); | |
}); | |
})() |
Hi @KyleF0X, thanks for the update.
I've added a comment on top of my script file, so people will navigate to your gist.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
β Fixed Script Available!
Hi @samir-dahal, thanks for the original script! It stopped working due to Twitter UI changes, so I've created an updated version that works with the current Twitter/X interface.
What changed in Twitter's UI:
Key fixes in the updated script:
π Fixed version available here:
https://gist.github.com/KyleF0X/f191fd223586973f3bf67cce394a98f6
The updated script is tested and working as of June 2025. It automatically sorts replies by "Likes" on every tweet you view.
Hope this helps anyone else who was looking for a fix! π