klantoris / select quick eq

// ==UserScript==
// @name    	select quick eq
// @namespace   BW
// @include 	http://r*.bloodwars.interia.pl/?a=equip*
// @version 	1
// @grant   	none
// ==/UserScript==
	function findItemInZK(itemName) {
    	console.log("Searching for'"+itemName+"'");
    	var iterator = document.evaluate("//div[@id='hc_carm1']", document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null );
    	var thisNode = iterator.iterateNext();
    	var found = 0;
    	//while (thisNode) {
      	var children = thisNode.childNodes;
      	for (var i = 0; i < children.length; i++) {
        	var child = children[i];

        	if (child.nodeName == "DIV" && child.textContent.indexOf(itemName) != -1) {
            	if (child.getElementsByClassName('checkbox')[0].checked == false)
            	child.getElementsByClassName('checkbox')[0].click();
            	found = found + 1;
       	}
      	//}
      	//thisNode = iterator.iterateNext();
    	}
   	 
    	return found;
	}

	unsafeWindow.selectElements=function(s) {
    	var list = s.split('|');
    	var found = 0;
    	for(var i=0; i < list.length; i++) {
        	console.log(list[i]);       	 
        	if (list[i].trim() != "") {

           	found = found + findItemInZK(list[i].trim());
          	// return;
        	}
    	}
    	if (found>0) {
       	console.log("takeborrow="+document.getElementsByName('takeborrow')[0]);
       	document.getElementsByName('takeborrow')[0].click();
    	}
  	 
	};


(function()
{
	function parseDiv(ss) {
    	var s=ss.match(/[^']*'([^,]*)',.*/)[1];
    	var l=s.split(/[^>]*>([^<]+)<\/div>/);
    	return l;
	}
    
	var iterator = document.evaluate('//fieldset', document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null );
	try {
   	var thisNode = iterator.iterateNext();
 
    	while (thisNode) {
      	var children = thisNode.childNodes;

      	for (var i = 0; i < children.length; i++) {
        	var child = children[i];
        	if (child.nodeName == "DIV" && child.childNodes.length>0) {
            	var id = 0;
            	var elements;
            	for(var j=0; j<child.childNodes.length; j++) {
                	var c = child.childNodes[j];
                	if (c.nodeName == "DIV") {
                   	id = c.textContent;
                   	elements = parseDiv(c.getAttribute("onmouseover"));
                	}
            	}
            	var p = document.createElement("div");
            	p.textContent = "We\u017a: "+id;
            	p.setAttribute("style", "text-align: center; font-size: 12px; font-weight: bold; color: black; background-color: rgba(155, 155, 0, 1);")
            	p.setAttribute("onclick", "return selectElements('"+elements.join('|')+"');");
            	child.appendChild(p);
        	}
      	}
      	thisNode = iterator.iterateNext();
    	}    
	}
	catch (e) {
    	dump( 'Error: Document tree modified during iteration ' + e );
	}
    
})();