// ==UserScript==
// @name X-Robots-Tag Header detector
// @namespace http://www.joostdevalk.nl/x-robots-tag-play/
// @description Simple Greasemonkey script which pops up a message if you encounter a page using an X-Robots-Tag header.
// @include *
// ==/UserScript==

function printBox(id, message, url) {
	if (top != window) {
		framesets = top.document.getElementsByTagName("frameset");
		if (!framesets[0]) {
			d = top.document;			
		} else {
			d = document;
		}
	} else {
		framesets = document.getElementsByTagName("frameset");
		if (!framesets[0]) {
			d = document;
		} else {
			frames = document.getElementsByTagName("frame");
			d = frames[0].contentWindow.document;
		}
	}
	div = d.createElement("div");
	div.id = id;
	div.innerHTML = '<div style="position: absolute; left: 0px; top: 20px;' +
	'text-align: left; width: 250px; margin-bottom: 5px; z-index: 1000; background-color: #000; padding: 2px;">' +
	'<p style="margin: 2px 0; background-color: inherit;"> ' +
	'<a target="_blank" class="snap_nopreview" style="border-bottom: 1px solid #000; background-color: inherit; ' +
	'font: bold 10px Verdana; color: #fff; font-weight: bold;" href="'+url+'">'+message+'</a>' +
	'</p></div>';
	
	d.body.insertBefore( div, d.body.firstChild );
	window.setTimeout(
		function() {
			var div = d.getElementById( id );
			if ( div ) {
				div.parentNode.removeChild( div );
			}
		}
	, 7500 ); 
}

function readHeaders(url) {
	var r=new XMLHttpRequest();
	r.open('HEAD',url,false);
	r.send(null);
	return r.getAllResponseHeaders();
}

var headers = readHeaders(window.location);

regex = new RegExp("X-Robots-Tag: ([^\n]+)");
var matches = regex.exec(headers);

if (matches) {
	printBox('header',"X-Robots-Header: "+matches[1]);	
}

