Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update emojissue.js #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/emojissue.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(() => {
const REGEX = /https:\/\/github\.com\/(.*)\/(.*)\/issues\/(.*)/;
const REGEX = /https:\/\/github\.com\/(.*)\/(.*)\/(issues|pull)\/(.*)/;
const previousContainer = document.getElementById('emojissue');

if (!REGEX.test(document.location.href)) {
Expand All @@ -15,7 +15,10 @@
}

// Positive Emojis
const positiveEmojis = ['heart', '+1', 'tada'];
const positiveEmojis = ['heart', '+1', 'tada', 'smile'];

// Negative Emojis
const negativeEmojis = ['-1', 'thinking_face']; // "thinking_face" is "confused"

// Find most reacted comments
const comments = document.querySelectorAll('.comment');
Expand All @@ -39,8 +42,18 @@
return prev;
}, 0);

const negativeScore = Array.from(reactions).reduce((prev, cur) => {
const alias = cur.getAttribute('alias');

if (negativeEmojis.indexOf(alias) !== -1) {
return prev + parseInt(cur.nextSibling.textContent.trim(), 10);
}

return prev;
}, 0);

if (score > 0) {
mostReactedComments.push({ id: comment.id, score });
mostReactedComments.push({ id: comment.id, score, negativeScore });
}
}
});
Expand All @@ -49,12 +62,15 @@
return;
}

const generateHTML = args => `
<span class="emoji">🤘</span> See #${args.currentIndex + 1}
<span class="reacts">+${args.topFive[args.currentIndex].score} Reacts</span>
`;
const generateHTML = args => {
let negativeReactString = '';
if (args.topFive[args.currentIndex].negativeScore > 0) {
negativeReactString = '-' + args.topFive[args.currentIndex].negativeScore;
}
return ('<span class="emoji">🤘</span> See #' + (args.currentIndex + 1) + ' <span class="reacts">+' + args.topFive[args.currentIndex].score + ' ' + negativeReactString + ' Reacts</span>');
};

const topFive = mostReactedComments.sort((a, b) => b.score - a.score).slice(0, 5);
const topFive = mostReactedComments.sort((a, b) => (b.score - b.negativeScore) - (a.score - a.negativeScore)).slice(0, 5);
let currentIndex = 0;

const button = document.createElement('button');
Expand Down