Skip to content

Commit

Permalink
Issue-comments: Fix avatar toggle & append new on update
Browse files Browse the repository at this point in the history
  • Loading branch information
Mottie committed Oct 5, 2018
1 parent ea02975 commit 8b65f6b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions github-issue-comments.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@
</div>
<div class="select-menu-list ghic-menu" role="menu">
${list}
<div class="ghic-participants"></div>
<div class="ghic-participants">
<p><strong>Hide Comments from</strong></p>
<div class="ghic-list"></div>
</div>
</div>
</div>
</div>
Expand All @@ -239,11 +242,11 @@

function addAvatars() {
let indx = 0,

str = "<p><strong>Hide Comments from</strong></p>",
str = "",
unique = [],
// get all avatars
avatars = $$(".timeline-comment-avatar img"),
list = $(".ghic-list"),
len = avatars.length - 1, // last avatar is the new comment with the current user

loop = (callback) => {
Expand All @@ -255,7 +258,7 @@
}
el = avatars[indx];
name = (el.getAttribute("alt") || "").replace("@", "");
if (!unique.includes(name)) {
if (!unique.includes(name) && !$(`.ghic-avatar[aria-label="${name}"]`, list)) {
str += `<span class="ghic-avatar tooltipped tooltipped-n" aria-label="${name}">
${iconHidden}
<img class="ghic-avatar avatar" width="24" height="24" src="${el.src}"/>
Expand All @@ -274,7 +277,11 @@
}
};
loop(() => {
$(".ghic-participants").innerHTML = str;
if ($(".ghic-avatar", list)) {
list.innerHTML += str;
} else {
list.innerHTML = str;
}
});
}

Expand Down Expand Up @@ -546,14 +553,15 @@
// true flag for init - no need to remove classes
hideStuff(keys[indx], true);
}
addAvatars();
}
}

function checkItem(event) {
if (document.getElementById("discussion_bucket")) {
let name,
target = event.target,
wrap = target && target.closest(".dropdown-item");
wrap = target && target.closest(".dropdown-item, .ghic-participants");
if (target && wrap) {
if (target.nodeName === "INPUT") {
getInputValues();
Expand Down

0 comments on commit 8b65f6b

Please sign in to comment.