Created
February 2, 2018 06:54
-
-
Save kjirou/4d9e7677c7958db0077df20b968b7bf6 to your computer and use it in GitHub Desktop.
SlackのReacticon登録数ランキングを出すスニペット
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
// 1. Chrome Devtools の Sources にこれを登録します | |
// 2. https://moneyforward.slack.com/customize/emoji に遷移します | |
// 3. Run すると、Console に表示されます。 | |
authorNodes = document.querySelectorAll('.author_cell .display_flex'); | |
authors = Array.prototype.map.call(authorNodes, v => v.textContent.trim()); | |
ranking = authors.reduce((memo, author) => { | |
if (memo[author]) { | |
memo[author] += 1; | |
} else { | |
memo[author] = 1; | |
} | |
return memo; | |
}, {}); | |
rankingAsArray = Object.keys(ranking).map(author => { | |
return [author, ranking[author]]; | |
}).sort((a, b) => { | |
return b[1] - a[1]; | |
}); | |
rank = 0; | |
rankStep = 1; | |
lastScore = null; | |
rankingAsArray = rankingAsArray.map(v => { | |
if (lastScore === null) { | |
rank = 1; | |
} else if (lastScore === v[1]) { | |
rankStep += 1; | |
} else { | |
rank += rankStep; | |
rankStep = 1; | |
} | |
lastScore = v[1]; | |
return v.concat([rank]); | |
}); | |
rankingText = rankingAsArray.map(v => { | |
return '[' + v[2] + '位] ' + v[0] + ': ' + v[1]; | |
}).join('\n'); | |
output = `SlackのReacticon登録数ランキング: ${new Date().toString()} 版 | |
${rankingText}`; | |
console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gist の raw が
text/plain
で、Chrome だとそれを基本的には script タグとして実行できないから xhr を使う