// ==UserScript==
// @name          Flickr Tag Quick Edit
// @description	  Adds an edit link to any editable tag on a Flickr photo page.
// @namespace     http://www.rhyley.org/gm/
// @include       http://www.flickr.com/photos/*
// @include       http://flickr.com/photos/*

//    By Jason Rhyley (www.rhyley.org)
//       Feel free to contact me if you have suggestions or questions.
//       I reserve the right to make fun of your grammar if you do.
// ==/UserScript==

(function() {

current = location.pathname.split('/');
if (unsafeWindow.global_photos[current[3]] && unsafeWindow.global_photos[current[3]].isOwner) {

	editableTags = document.evaluate("//a[contains(@onclick,'tagrs_removeTag')]",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);

	for (i=0; i<editableTags.snapshotLength; i++) {
		thisTag = editableTags.snapshotItem(i);
		tagName = thisTag.getAttribute('onclick').split('\'')[7];
		editURL = '/' + current[1] + '/' + current[2] + '/tags/' + tagName + '/edit/';

		a = document.createElement('a');
		a.setAttribute('class','DelTag');
		a.setAttribute('href',editURL);
		a.setAttribute('title','Edit this tag?');
		a.innerHTML = "[e]";

		s = document.createTextNode(' ')

		thisTag.parentNode.insertBefore(a, thisTag.nextSibling);
		thisTag.parentNode.insertBefore(s, thisTag.nextSibling);
	}
}

})();