<commit_before>function isValid(comment) {
  if ($.trim(comment) == 'No Comments') return false;
  return true;
}

$('.comments p').each(function(i, comment) {
  var text = $(comment).html(),
      $div, $header, message;

  if (isValid(text)) {
    $div = $("<div></div>").addClass('rate-my-professors-extension');
    $header = $("<h5></h5>");

    message = 'This user received a reading score of <strong>123.21</strong> can be <strong class="green">trusted</strong>.';
    $header.html(message);
    $div.append($header);
    $(comment).parent().prepend($div);
  }
});<commit_msg>- add in readability scores - select message based on score - allow reading scores to be shown on items that were loaded through ajax<commit_after>var CONTAINER_CLASS = 'rate-my-professors-extension';

function isValid(comment) {
  if ($.trim(comment) == 'No Comments') return false;
  return true;
}

function injectReadingScores() {
  $('.comments p').each(function(i, comment) {
    var text = $(comment).html();

    if (isValid(text)) {
      var $div = $("<div></div>").addClass(CONTAINER_CLASS),
          $header = $("<h5></h5>"),
          message, score;

      score = readability.flesch_kincaid_grade_level(text).toFixed(2);

      message = 'This user received a reading score of <strong>'+score+'</strong> and ';
      if (score < 4.00) {
        message += 'should be <strong class="red">ignored</strong>.';
        $(comment).parents("tr").css('opacity', '0.7');
      } else if (score < 6.00) {
        message += 'should be treated with <strong class="orange">caution</strong>.';
      } else {
        message += 'can be <strong class="green">trusted</strong>.';
      }
      $header.html(message);
      $div.append($header);
      $(comment).parent().prepend($div);
    }
  });
}

// Removes added Reading Scores div containers
// from the page.
function clearReadingScores() {
  $('.'+CONTAINER_CLASS).remove();
}

// Make sure to add the reading scores to new items loaded
// when user clicks the Load More button.
$('#loadMore').on('click', function() {
  setTimeout(function() {
    clearReadingScores();
    injectReadingScores();
  }, 1000);
});

injectReadingScores();
{'fraction_non_alphanumeric': 0.18202659330582302, 'fraction_numerical': 0.010087116001834021, 'mean_word_length': 3.5458333333333334, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '589328', 'n_tokens_mistral': 705, 'n_tokens_neox': 678, 'n_words': 172}