xutx73 / BcPageHack

// ==UserScript==
// @name        BcPageHack
// @namespace   BC
// @include     http://10.154.212.24:8080/projects/
// @version     1
// @grant       GM_xmlhttpRequest
// ==/UserScript==

var div = document.getElementById("l:groups");
var spans = div.getElementsByTagName("span");
var inner_span = ''
var tmp = ''
var exclude ="(AllTheDNE|AllTheDr0|MyC0F|MyDR0|MyIISNGMT|MyIISWhNgmt|MyMMX|MySRE|TASDev23|X|other_TasDev23_Discovery)";

function RemoveGroups ()
{
  var patt = new RegExp(exclude);
 
  for(var i=1;i<spans.length;i++)
  {
    var res = patt.test(spans[i].innerHTML);
    if ( ! res )
    {
      GM_xmlhttpRequest ( {
        method: "POST",
        url:    "http://10.154.212.24:8080/projects/disableGroup?groupName="+spans[i].innerHTML,
        } ); 
    }
    i++;
  }

  
}

function displayGroupsInTheLeft ()
{
  var patt = new RegExp(exclude);
  
  for(var i=1;i<spans.length;i++)
  {
    var res = patt.test(spans[i].innerHTML);
    if ( ! res )
    {
      inner_span+='<div><span>'+spans[i].innerHTML+'</span>';
      var t = i+1;
      if ( t < spans.length )
      {
        ++i;
      }
      inner_span+='<span>  [ '+spans[i].innerHTML+' ] </span></div>';
    } else {
      if ( t < spans.length )
      {
        ++i;
      }
    }
  }
}

    
  displayGroupsInTheLeft();
  tmp=inner_span;
  div.innerHTML =  '<div  id="zs0" style="display: inline-block; float: left; height: 100%; overflow: scroll;" > <div id="zs1" > '+tmp+'</div></div>' + div.innerHTML ;
  
  //MAKE A BUTTON with onclick function ( evenet )
  var btn = document.createElement("BUTTON");
  var t = document.createTextNode("Remove All Groups");
  btn.addEventListener("click", RemoveGroups, true);
  btn.type="reset";
  btn.appendChild(t);
  var myspan = document.getElementById("zs1");
  myspan.parentNode.insertBefore(btn, myspan);