From c54f85613d2574f33a352c16854197507a4f9c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=94=95=E1=96=BA=E1=98=8E=E1=95=8A?= Date: Sun, 3 Feb 2019 13:54:14 +0000 Subject: [PATCH] add delay to comment features for links to deleted comments #379 --- sox.features.js | 20 ++++++++++++-------- sox.user.js | 6 +++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/sox.features.js b/sox.features.js index e370a93..1645b56 100644 --- a/sox.features.js +++ b/sox.features.js @@ -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(''); + // 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(''); + } } - } - }); + }); + }, 100); } $(document).on('click', 'span.soxReplyLink', function() { @@ -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); diff --git a/sox.user.js b/sox.user.js index 4e0b708..d9baa06 100644 --- a/sox.user.js +++ b/sox.user.js @@ -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) @@ -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'); });