Skip to content

Instantly share code, notes, and snippets.

@zisra
Created November 9, 2023 05:20
Show Gist options
  • Save zisra/3a6985ce4b332fe1fe5c1a8933284a42 to your computer and use it in GitHub Desktop.
Save zisra/3a6985ce4b332fe1fe5c1a8933284a42 to your computer and use it in GitHub Desktop.
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