Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Today I contributed to the greater good of society:

  var output = "";
  $('h2 a').each(function(i) {
      output += "TITLE: " + $.trim(this.innerHTML) + "\n";
      var email = decodeURIComponent(this.href).slice(13).split("&subject=");
      output += "SUBJECT: " + email[1] + "\n";
      output += "BODY:\n" + email[0].replace(/\n( )+/g, "\n") + "\n\n\n\n";
      console.log(output);
  });
That being said I love the site :)


Slightly tweaked your script to display inline

    $("h2 a").each(function(){
       var email = decodeURIComponent(this.href).slice(13).split("&subject=");
       var subject = email[1];
       var body = email[0].replace(/\n( )+/g, "\n");
       var parent = $(this).parent("h2")
       parent.after($("<div />").text(body));
       parent.after($("<h4 />").text(subject));
    });


This is great! For anyone wondering, use this one.


SO much easier reading it this way :D


   console.log(output); 
needs to be last line outside each() :) Or move var content = "" inside each()


Whoops, you're right, console.log was supposed to be at the very bottom of the script. By default most browser consoles scroll you to the bottom of the output, so I just read the first half scrolling up and never noticed. No matter, amarraja's version is much better.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: