Created
November 9, 2023 05:20
-
-
Save zisra/3a6985ce4b332fe1fe5c1a8933284a42 to your computer and use it in GitHub Desktop.
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
function getNumber(el) { | |
const value = el.querySelector('[data-e2e="video-views"]').textContent; | |
if (value.endsWith("K")) { | |
return parseInt(value.replace("K", "")) * 1_000; | |
} else if (value.endsWith("M")) { | |
return parseInt(value.replace("M", "")) * 1_000_000; | |
} | |
} | |
const container = document.querySelector('[data-e2e="user-post-item-list"]'); | |
const children = container.children; | |
const sortedChildren = Array.from(children).sort( | |
(a, b) => getNumber(b) - getNumber(a), | |
); | |
container.replaceChildren(...sortedChildren); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment