Back to Top

Wednesday, December 17, 2008

Everything old is new again - SMOG

Warning! The site which the script uses to provide the service contains a malicious iframe. While most probably the site itself is not malicious, I don't recommend using the script below until the issues have been cleared up. If you included it in your site, please disable it until the problems have been cleared up. (If you subscribe to the blog, I'll post a note when this is the case.)

As I've said many times, in the computer domain we are especially tempted to forget things that came before us, solutions that have already been found, even though there are lots of very cool things if we just dig.

For example via this Perl Advent Calendar entry I found out about SMOG - Simple Measure of Gobbledygook. It is a relatively simple formula, which claims to have "an outstandingly high 0.985 correlation with the grades of readers who had 100% comprehension of test materials". Very interesting.

So I added a button after each post title using which you can submit the given article for a SMOG evaluation. Because RSS readers usually don't render JS, you'll have to visit the blog on the web to see these buttons. If you want to add them to your blog, here is the source:

<script src=""></script>
.smog-button {
  border: 1px solid black; background-color: #dfffbf; color: rgb(51, 0, 0);
/* <![CDATA[ */
$(document).ready(function() {
  $('').each(function(i, e) {
    var titleElement = $('.post-title', e);    
    var postBodyText = $('.post-body', e).html();
    //remove <code> and <pre> entirely
    postBodyText = postBodyText.replace(/<\s*(?:code|pre)[\s\S]*?\/(?:code|pre)[\s\S]*?>/gi, '');
    //strip the other tags
    postBodyText = postBodyText.replace(/<[\s\S]*?>/gi, '');
    if (postBodyText.length < 100) return;
    //escape " and limit length
    var title = titleElement.text().substring(0, 40).replace(/"/g, '"');   
    postBodyText = postBodyText.substring(0, 10000).replace(/"/g, '"');
    $('a', titleElement).after(
      '<form name="dataForm" method="post" target = "_blank" action="">'
      + '<input type="hidden" name="document_title" value="' + title + '" />'
      + '<input type="hidden" name="user_text" value="' + postBodyText + '" />'
      + '<input type="hidden" name="service_id" value="WordsCount">'
      + '<input type="hidden" name="service_name" value="SMOG Calculator">'
      + '<input class="smog-button" type="submit" value="SMOG" />'
      + '</form>');       
/* ]]> */

PS. Most of my posts seem to have a surprisingly high SMOG score - somewhere in the some college-post-graduate degree interval - considering that English is my second language...


Post a Comment

You can use some HTML tags, such as <b>, <i>, <a>. Comments are moderated, so there will be a delay until the comment appears. However if you comment, I follow.