Skip to content

Commit

Permalink
🐛 Fix 'Read more' not showing on long comments
Browse files Browse the repository at this point in the history
There is some dynamic styling being done on the comments by YouTube when
they load. The delay in the comments loading seems to have caused an
issue where the styling to show 'Read more' for long comments does not
appear.

Add a hacky workaround that executes once after comments are toggled on,
which removes the extra 'hid' CSS class from long comments just as
YouTube would normally do.
  • Loading branch information
dideler committed Aug 20, 2017
1 parent 533888f commit 7df9a76
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function toggleComments() {
} else {
label.textContent = 'Hide comments';
}

showReadMore();
}

function inject() {
Expand All @@ -31,6 +33,19 @@ function addButton() {
document.getElementById('toggle-comments').addEventListener('click', toggleComments);
}

function showReadMore() {
showReadMore = function() {}; // Become a no-op after executing.

const maxHeight = 65;
const commentContents = document.getElementsByClassName('comment-renderer-text-content');

for (var comment of commentContents) {
if (comment.scrollHeight > maxHeight) {
comment.nextElementSibling.classList.remove('hid');
}
};
}

(function () {
document.addEventListener('DOMContentLoaded', inject); // Static navigation (i.e. initial page load)
document.addEventListener('spfdone', inject); // Dynamic navigation (i.e. subsequent page loads)
Expand Down

0 comments on commit 7df9a76

Please sign in to comment.