// ==UserScript==
// @name          Highlight My Comments
// @namespace     http://uwmike.com
// @description   Highlights comments by the current user on Reddit
// @include       http://reddit.com/info/*
// @include       http://*.reddit.com/info/*
// @include       http://reddit.com/user/*
// @include       http://*.reddit.com/user/*
// ==/UserScript==

var userURL, allLinks, thisURL;

userURL = document.getElementById('topbar').getElementsByTagName('a')[0].href;
allLinks = document.getElementById('main').getElementsByTagName('a')
thisURL = String(window.location);

if (thisURL.indexOf('reddit.com/info') != -1)
{
	// comments page
	for (var i = 0; i < allLinks.length; i++) {
		if (allLinks[i].href == userURL)
		{
			var wrap = allLinks[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
			if (wrap.nodeName == 'DIV' && wrap.id && wrap.id.substring(0, 5) == 'table')
			{
				var arrow = document.createElement('div');
				wrap.style.position = 'relative';
				arrow.style.height = '1px';
				arrow.style.width = '1px';
				arrow.style.border = '10px solid transparent';
				arrow.style.borderLeftColor = 'rgb(198, 222, 247)';
				arrow.style.borderRightWidth = '0';
				arrow.style.position = 'absolute'
				arrow.style.top = '8px';
				arrow.style.left = '-12px';
				wrap.appendChild(arrow);
			}
		}
	}
}
else if (thisURL.indexOf('reddit.com/user'))
{
	// user page
	for (var i = 0; i < allLinks.length; i++) {
		if (allLinks[i].innerHTML == 'permalink')
		{
			var newLink = document.createElement('a');
			newLink.innerHTML = 'context';
			urlParts = String(allLinks[i].href).split('/');
			last = urlParts.pop();
			newLink.href = urlParts.join('/') + '#' + last;
			newLink.className = 'bylink';
			allLinks[i].parentNode.appendChild(newLink);
		}
	}
}
