Skip to content

Instantly share code, notes, and snippets.

@kjirou
Created February 2, 2018 06:54
Show Gist options
  • Save kjirou/4d9e7677c7958db0077df20b968b7bf6 to your computer and use it in GitHub Desktop.
Save kjirou/4d9e7677c7958db0077df20b968b7bf6 to your computer and use it in GitHub Desktop.
SlackのReacticon登録数ランキングを出すスニペット
// 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);
@kjirou
Copy link
Author

kjirou commented Feb 2, 2018

gist の raw が text/plain で、Chrome だとそれを基本的には script タグとして実行できないから xhr を使う

var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://gist.githubusercontent.com/kjirou/4d9e7677c7958db0077df20b968b7bf6/raw/e607680d0bdae357647b0984a959dfadbfaa91a5/slack-reacticon-ranking.js', false);
xhr.send();
eval(xhr.response);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment