Last active
August 29, 2015 14:22
-
-
Save bitoiu/8ba59a850b0139b9f415 to your computer and use it in GitHub Desktop.
Adds GitHub idle mentions on the participants tab
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
(function() { | |
"use strict" | |
$.fn.reduce = [].reduce; | |
var $comments = $('div.issues-listing') | |
var getMentioned = function () { | |
return $.unique($comments.find('a.user-mention').reduce(function(prev, curr) { | |
prev.push(($(curr).attr('href')).split('github.com/')[1]) | |
return prev | |
},[])) | |
} | |
var getActive = function () { | |
return $.unique($comments.find('a.author').reduce(function(prev, curr) { | |
prev.push($(curr).attr('href').replace('/',"")) | |
return prev | |
},[])) | |
} | |
var updateParticipantsView = function(active, onlyMentioned) { | |
if (!onlyMentioned || onlyMentioned.length == 0) { | |
console.log("All mentions are also active") | |
return | |
} | |
var $templateDiv = $('<div class="mentioned-participants discussion-sidebar-item"><h3 class="discussion-sidebar-heading">' + onlyMentioned.length + ' Idle mentions</h3></div>') | |
, $participationAvatars = $('<div class="participation-avatars"></div>') | |
, $avatarTemplate = $comments.find("a.participant-avatar").first() | |
onlyMentioned.forEach(function (val) { | |
var $avatar = $avatarTemplate.clone() | |
, avatarID = Math.floor(Math.random() * 1000) + 1 | |
$avatar.attr("href", "/" + val) | |
.attr("aria-label", val) | |
$avatar.find('img').attr("alt", "/" + val) | |
.attr("src", "https://avatars3.githubusercontent.com/u/" + avatarID + "?v=3&s=40") | |
$participationAvatars.append($avatar) | |
}) | |
$templateDiv.append($participationAvatars) | |
$comments.find("div.participation").after($templateDiv) | |
} | |
var enchanceParticipantAside = function(mentioned, active ) { | |
if( !mentioned ) { | |
console.log("No mentions in the document") | |
return | |
} | |
var onlyMentioned = mentioned.filter(function(val) { | |
return !(active.indexOf(val) > 0) | |
}) | |
console.log(mentioned.length + " mentioned users") | |
console.log(active.length + " active users") | |
console.log(onlyMentioned.length + " mentioned but not active users") | |
updateParticipantsView(active, onlyMentioned) | |
} | |
enchanceParticipantAside(getMentioned(), getActive()); | |
})() |
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
!function(){"use strict";$.fn.reduce=[].reduce;var t=$("div.issues-listing"),n=function(){return $.unique(t.find("a.user-mention").reduce(function(t,n){return t.push($(n).attr("href").split("github.com/")[1]),t},[]))},e=function(){return $.unique(t.find("a.author").reduce(function(t,n){return t.push($(n).attr("href").replace("/","")),t},[]))},i=function(n,e){if(!e||0==e.length)return void console.log("All mentions are also active");var i=$('<div class="mentioned-participants discussion-sidebar-item"><h3 class="discussion-sidebar-heading">'+e.length+" Idle mentions</h3></div>"),r=$('<div class="participation-avatars"></div>'),a=t.find("a.participant-avatar").first();e.forEach(function(t){var n=a.clone(),e=Math.floor(1e3*Math.random())+1;n.attr("href","/"+t).attr("aria-label",t),n.find("img").attr("alt","/"+t).attr("src","https://avatars3.githubusercontent.com/u/"+e+"?v=3&s=40"),r.append(n)}),i.append(r),t.find("div.participation").after(i)},r=function(t,n){if(!t)return void console.log("No mentions in the document");var e=t.filter(function(t){return!(n.indexOf(t)>0)});console.log(t.length+" mentioned users"),console.log(n.length+" active users"),console.log(e.length+" mentioned but not active users"),i(n,e)};r(n(),e())}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment