Created
November 16, 2016 14:17
-
-
Save laggingreflex/bd51222128101507d5a29844a2e777fc to your computer and use it in GitHub Desktop.
Sort github comments by reactions
This file contains 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
(() => { | |
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