Skip to content

Instantly share code, notes, and snippets.

@webdesignberlin
Forked from laggingreflex/sort.js
Created November 18, 2016 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdesignberlin/da272029a45111fde36fdf9e48ad4288 to your computer and use it in GitHub Desktop.
Save webdesignberlin/da272029a45111fde36fdf9e48ad4288 to your computer and use it in GitHub Desktop.
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