// ==UserScript==
// @name           	Auto Join Community on Orkut
// @namespace     	http://www.devilsworkshop.org/2006/10/29/autojoin-communities-on-orkut/
// @description 	Automatically join Communities
// @include        	http://*.orkut.com/*
// ==/UserScript==

(function() {
var i=document.getElementsByTagName('a');
for (var j=i.length-1; j>1; j--) {
    var linkdata =  i[j].getAttribute("href");
    var linkparts = linkdata.split("?");
    if (linkdata.match("Community") == "Community" ) {
        var commjoinlink = document.createElement("a");
        commjoinlink.href="http://www.orkut.com/CommunityJoin.aspx"+"?"+linkparts[1];
        commjoinlink.appendChild(document.createTextNode(" [J]"));

        i[j].parentNode.insertBefore( commjoinlink,i[j].nextSibling);

	var communjoinlink = document.createElement("a");
        communjouninlink.href="http://www.orkut.com/CommunityUnjoin.aspx"+"?"+linkparts[1];
        communjouninlink.appendChild(document.createTextNode(" [U]"));

        i[j].parentNode.insertBefore( communjoinlink,i[j].nextSibling);
        }
    }
})();


window.addEventListener(
	'load',
	function() {
	if ( window.location.href.match("CommunityJoin") == ("CommunityJoin") ) {
		window.location.href = "javascript: _submitForm(document.getElementById('b1'),'join');"
		}

	if ( window.location.href.match("CommunityUnjoin") == ("CommunityUnjoin") ) {
		window.location.href = "javascript: _submitForm(document.getElementById('b1'),'unjoin');"
		}
	},
	true);

