how to get content of the current page
You could use the javascript DOM API like this:
var headContent = document.getElementsByTagName('head')[0].innerHTML;