From 7df9a7698dfc696189d83c8ac93fe7a64795840d Mon Sep 17 00:00:00 2001 From: Dennis Ideler Date: Sun, 20 Aug 2017 22:46:36 +0100 Subject: [PATCH] :bug: Fix 'Read more' not showing on long comments 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. --- script.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/script.js b/script.js index 3c718e5..26b631d 100644 --- a/script.js +++ b/script.js @@ -9,6 +9,8 @@ function toggleComments() { } else { label.textContent = 'Hide comments'; } + + showReadMore(); } function inject() { @@ -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)