Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sort github comments by reactions
(() => {
const q = (e, s) => e.querySelector(s);
const qA = (e, s) => e.querySelectorAll(s);
const num = e => parseInt(e.nextSibling.wholeText.trim())
const d = document.querySelector('.js-discussion.js-socket-channel');
/* uncomment one of these to sort by */
const sortBy = '+1';
// const sortBy = '-1';
// const sortBy = 'smile';
// const sortBy = 'thinking_face';
// const sortBy = 'heart';
// const sortBy = 'tada'; // (hooray/party icon)
const sbc = `g-emoji.mr-1[alias="${sortBy}"]`;
const els =
Array.from(qA(document, '.js-comment-container'))
.filter(e => q(e, sbc))
.sort((...ab) => ab.map(e => num(q(e, sbc))).reduce((a, b) => a < b))
d.innerHTML = '';
els.forEach(e => d.appendChild(e));
})();
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.