Skip to content

Commit

Permalink
add delay to comment features for links to deleted comments #379
Browse files Browse the repository at this point in the history
  • Loading branch information
shu8 committed Feb 3, 2019
1 parent 2915578 commit c54f856
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 12 additions & 8 deletions sox.features.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,14 +563,17 @@
if (!sox.user.loggedIn) return;

function addReplyLinks() {
$('.comment').each(function() {
if (!$(this).find('.soxReplyLink').length) { //if the link doesn't already exist
if (sox.user.name !== $(this).find('.comment-text a.comment-user').text()) { //make sure the link is not added to your own comments
$(this).find('.comment-text').css('overflow-x', 'hidden');
$(this).find('.comment-text .comment-body').append('<span class="soxReplyLink" title="reply to this user" style="margin-left: -7px">&crarr;</span>');
// Delay needed because of https://github.com/soscripted/sox/issues/379#issuecomment-460001854
setTimeout(() => {
$('.comment').each(function () {
if (!$(this).find('.soxReplyLink').length) { //if the link doesn't already exist
if (sox.user.name !== $(this).find('.comment-text a.comment-user').text()) { //make sure the link is not added to your own comments
$(this).find('.comment-text').css('overflow-x', 'hidden');
$(this).find('.comment-text .comment-body').append('<span class="soxReplyLink" title="reply to this user" style="margin-left: -7px">&crarr;</span>');
}
}
}
});
});
}, 100);
}

$(document).on('click', 'span.soxReplyLink', function() {
Expand Down Expand Up @@ -2443,7 +2446,8 @@
// Description: Only show the comment actions (flag/upvote) when hovering over a comment

function addCSS() {
$('.comment').addClass('sox-onlyShowCommentActionsOnHover');
// Delay needed because of https://github.com/soscripted/sox/issues/379#issuecomment-460001854
setTimeout(() => $('.comment').addClass('sox-onlyShowCommentActionsOnHover'), 100);
}

$(document).on('sox-new-comment', addCSS);
Expand Down
6 changes: 3 additions & 3 deletions sox.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @namespace https://github.com/soscripted/sox
// @homepage https://github.com/soscripted/sox
// @homepageURL https://github.com/soscripted/sox
// @version 2.3.30 DEV
// @version 2.3.31 DEV
// @description Extra optional features for Stack Overflow and Stack Exchange sites
// @contributor ᴉʞuǝ (https://stackoverflow.com/users/1454538/, https://github.com/mezmi)
// @contributor ᔕᖺᘎᕊ (https://stackexchange.com/users/4337810/, https://github.com/shu8)
Expand Down Expand Up @@ -175,8 +175,8 @@
}

//custom events....
sox.helpers.observe('.new_comment, .comment', () => { //custom event that triggers when a new comment appears/show more comments clicked; avoids lots of the same mutationobserver
$(document).trigger('sox-new-comment');
sox.helpers.observe('.new_comment, .comment, .comments', (target) => {
$(document).trigger('sox-new-comment', [target]);
sox.debug('sox-new-comment event triggered');
});

Expand Down

0 comments on commit c54f856

Please sign in to comment.