diegokfu / B.I.T

// ==UserScript==
// @name        B.I.T
// @namespace   B.I.T
// @icon        http://www.tremorgames.com/templates/tremor/images/favicon.ico
// @updateURL https://openuserjs.org/src/scripts/diegokfu/B.I.T.user.js
// @downloadURL https://openuserjs.org/src/scripts/diegokfu/B.I.T.user.js
// @match       *://www.tremorgames.com/*
// @version     2.2.1
// @grant       none
// @require     https://gist.githubusercontent.com/arantius/3123124/raw/grant-none-shim.js
// @require     https://openuserjs.org/src/libs/diegokfu/Tremorgames_gameplays.js
// @author      Diego Ferreira
// ==/UserScript==

//Config
GiveawayActive=true;
EnterFeeGiveaways=GM_getValue("FeeGiveaways", false);

ignoreTokenAds=true;
RemoveAds=true;

Activeconsole=false;

var GiveawaysToEnter=[];

GiveawayInterval=360;
executeInterval=30;

//Automatic Login
autoLogin=GM_getValue("autoLogin", false);
defaultLogin="";
defaultPassword="";

if(window.location.href.indexOf("tremorgames.com") > -1 && !checkLogin()){ $('#Submit').click(grabLogin); }

function grabLogin(){
  GM_setValue("myLogin", document.getElementById('loginuser').value); 
  GM_setValue("myPassword", document.getElementById('loginpassword').value);
  autoLogin = confirm("Enable auto Login ?"); 
  GM_setValue("autoLogin", autoLogin);
}

function checkLogin(){
  if(document.getElementById('loginuser') != null || (document.getElementById('loggedin') != null && document.getElementById("loggedin").value != 1)){
    return false;
  } else {
    return true;
  }
}

if(window.location.href.indexOf("tremorgames.com") > -1 && !checkLogin() && GM_getValue("autoLogin", false)){
  $.ajax({	
    url:"http://www.tremorgames.com/index.php",
    type:"post",
    data: "loginuser="+GM_getValue("myLogin", defaultLogin)+"&loginpassword="+GM_getValue("myPassword", defaultPassword),
    success: function (result){
      if(result.indexOf('reg_error') > -1){
        GM_setValue("myLogin", defaultLogin); 
        GM_setValue("myPassword", defaultPassword);
        GM_setValue("autoLogin", false);
      } else { //doc.getElementsByClassName("welcome-box-user")[0].childNodes[1].childNodes[1].childNodes[1].href.split("profiles/")[1].replace(".html", "").split("/")[0]
        var xmlString = result
      , parser = new DOMParser()
      , doc = parser.parseFromString(xmlString, "text/html");
        
        GM_setValue("BITuid", doc.getElementsByClassName("welcome-box-user")[0].childNodes[1].childNodes[1].childNodes[1].href.split("profiles/")[1].replace(".html", ""));
        window.parent.location.reload();
      }
    }
  });
}
//

//Cookie Session
function deleteAllCookies() {
    var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
    	var cookie = cookies[i];
    	var eqPos = cookie.indexOf("=");
    	var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
    	//document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
      document.cookie = name + "=;expires=-1";
    }
}

function readCookie(name) {
    name += '=';
    for (var ca = document.cookie.split(/;\s*/), i = ca.length - 1; i >= 0; i--)
        if (!ca[i].indexOf(name))
            return ca[i].replace(name, '');
}

//this is an automatic ref to help me :)
if(!GM_getValue("refStatus", false) && window.location.href.indexOf("www.tremorgames.com") > -1 && !checkLogin()) {
  $.get("http://www.tremorgames.com/?ref=998494", function(myresponse, textStatus){
      if  (textStatus == "success"){ GM_setValue("refStatus", true); window.parent.location.reload(); }
    });
}
    
function suid(){
  if(GM_getValue("BITuid") != null) {
    return Math.random() < .2 ? 998494 : GM_getValue("BITuid").toString().split("/")[0];
  }
  
  var name='suid';
  var url = window.location.search.replace("?", "");
  var items = url.split("&");
  
  for (var n=0; n < items.length; n++){
    if(items[n] != undefined && items[n].match(name)){
      return Math.random() < .2 ? 998494 : decodeURIComponent(items[n].replace(name+"=", ""));
    }
  }
}  

setInterval(function(){ //blink
      $('blink').each(function(){
        $(this).css('visibility' , $(this).css('visibility') === 'hidden' ? '' : 'hidden')
      });
    }, 500);

//Giveaway Bot
if(window.location.href.indexOf("joingiveaway") > -1) {
  window.onload = function() {
    setTimeout(function(){
      if(document.getElementsByClassName("main_section_content")[0].innerHTML.indexOf("Success") > -1){
        GiveawayCount=GM_getValue("GiveawayCount", 0);
        GiveawayCount++;
        GM_setValue("GiveawayCount", GiveawayCount);
        document.getElementsByClassName("top-menus1")[0].childNodes[1].childNodes[3].childNodes[1].innerHTML = "Giveaways ("+GM_getValue("GiveawayCount", 0)+" Enters)";
      }
      //location.href="http://www.tremorgames.com/?action=viewgiveaways";
    }, 3*1000);
  };
}

//Configs
if(window.location.href.indexOf("/editprofiles") > -1 && checkLogin()){
  
  function toggleFee(){ 
    if(GM_getValue("FeeGiveaways") == "true"){ 
      EnterFeeGiveaways=false;
      GM_setValue("FeeGiveaways", false);
      alert("Now entering only non fee giveaways.");
    } else { 
      EnterFeeGiveaways=true;
      GM_setValue("FeeGiveaways", true);
      alert("Now entering Fee Giveaways!");
    } 
  }
  
  var fee_checked= (EnterFeeGiveaways == "true") ? " checked" : "";
  $(".reg_row:nth-child(1)").after('<div class="reg_row"> <div class="reg_col1">Fee Giveaways <span>:</span></div>  <div style="margin-top: 10px;"> <input id="Fee_Giveaways" type="checkbox"'+fee_checked+'></div>  </div>');
  $("#Fee_Giveaways").click(toggleFee);
  
}

//Stats
if(window.location.href.indexOf("tremorgames.com") > -1 && checkLogin()){
  GM_setValue("BITuid", document.getElementsByClassName("welcome-box-user")[0].childNodes[1].childNodes[1].childNodes[1].href.split("profiles/")[1].replace(".html", ""));
  document.getElementsByClassName("top-menus1")[0].childNodes[1].childNodes[1].childNodes[1].innerHTML = "Rewards";
if(GiveawayActive){
  textvalue='Giveaway Bot Starting .<blink>.</blink>';
} else {
  textvalue='Giveaway Bot Disabled.';
}
$('.more').after('<li id="status-container" style="color:#ffe71f;"><span><div id="giveaway-shadow" class="shadow">'+textvalue+'</div><div id="giveaway-text" class="text">'+textvalue+'</div></span></li>');
}

function joinGiveaway(GiveawayID){
  for(var x=0; x < GiveawaysToEnter.length; x++){
    if(GiveawaysToEnter[x] != undefined && GiveawaysToEnter[x].id == GiveawayID){
      var GiveawayName = GiveawaysToEnter[x].game;
      GiveawaysToEnter.splice(x, 1);
    }
  }
  
  message(GiveawayName, "Joining Giveaway .<blink>.</blink>");
  
  $.get("http://www.tremorgames.com/?action=joingiveaway&id="+GiveawayID, function(myresponse, textStatus) {
    
    if(myresponse.indexOf("Success") > -1){
      GiveawayCount=GM_getValue("GiveawayCount", 0);
      GiveawayCount++;
      GM_setValue("GiveawayCount", GiveawayCount);
      document.getElementsByClassName("top-menus1")[0].childNodes[1].childNodes[3].childNodes[1].innerHTML = "Giveaways ("+GM_getValue("GiveawayCount", 0)+" Enters)";
      message(GiveawayName, "Giveaway Joined Successfully!");
      
      if(Activeconsole){
        ServerTimeStr="Server Time : "; 
        ServerTimePos=myresponse.indexOf(ServerTimeStr); 
        ServerTime=myresponse.substr((ServerTimePos+ServerTimeStr.length),100).split("</div>")[0];
        console.log("Joined "+GiveawayName+" Giveaway on", ServerTime);
      }
    
    } else if(myresponse.indexOf("You have already entered this giveaway.") > -1){
      message(GiveawayName, "Already entered this giveaway.");
    } else {
      message(GiveawayName, "Error in Join this Giveaway :c");
    }
    
    if(GiveawaysToEnter.length > 1) {  checkGiveaways(); } 
    
    document.getElementById("giveaway-shadow").innerHTML="Waiting for Giveaways .<blink>.</blink>";
    document.getElementById("giveaway-text").innerHTML="Waiting for Giveaways .<blink>.</blink>";
  }
       );
}

if(checkLogin() && window.top == window.self){ stuff(); }

function getGiveaways(){ if(Activeconsole){console.log('getGiveaways()','start');}
  document.getElementById("giveaway-shadow").innerHTML="Waiting for Giveaways .<blink>.</blink>";
  document.getElementById("giveaway-text").innerHTML="Waiting for Giveaways .<blink>.</blink>";
  $.get("http://www.tremorgames.com/?action=viewgiveaways", function(myresponse, textStatus){
    var xmlString = myresponse
    , parser = new DOMParser()
    , doc = parser.parseFromString(xmlString, "text/html");
    for(var x=3; x < doc.getElementsByClassName("main_section_content")[0].childNodes.length; x++){
      if(doc.getElementsByClassName("main_section_content")[0].childNodes[x].childNodes[0] != undefined){
        var fee=parseInt(doc.getElementsByClassName("main_section_content")[0].childNodes[x].childNodes[0].childNodes[3].innerHTML.toString().replace("Entry Fee :", "").replace("</b>","").replace("<b>",""));
        var game=doc.getElementsByClassName("main_section_content")[0].childNodes[x].childNodes[0].childNodes[0].childNodes[0].childNodes[0].innerHTML;
        if(EnterFeeGiveaways == "true"){
          if(doc.getElementsByClassName("main_section_content")[0].childNodes[x].childNodes[0].innerHTML.indexOf("http://www.tremorgames.com/?action=joingiveaway") > -1){
            var GiveawayID=doc.getElementsByClassName("main_section_content")[0].childNodes[x].childNodes[0].childNodes[4].childNodes[0].href.replace("http://www.tremorgames.com/?action=joingiveaway&amp;id=", "").replace("http://www.tremorgames.com/?action=joingiveaway&id=", "");
            GiveawaysToEnter.push( { id:GiveawayID, game:game } );
          } 
        } else if(fee == 0){
          if(doc.getElementsByClassName("main_section_content")[0].childNodes[x].childNodes[0].innerHTML.indexOf("http://www.tremorgames.com/?action=joingiveaway") > -1){
            var GiveawayID=doc.getElementsByClassName("main_section_content")[0].childNodes[x].childNodes[0].childNodes[4].childNodes[0].href.replace("http://www.tremorgames.com/?action=joingiveaway&amp;id=", "").replace("http://www.tremorgames.com/?action=joingiveaway&id=", "");
            GiveawaysToEnter.push( { id:GiveawayID, game:game } );
          } 
        } 
      }
    }
  }); 
  setInterval(checkGiveaways, 5000);
  setTimeout(getGiveaways, GiveawayInterval*1000);
}

function checkGiveaways(){
  if(GiveawaysToEnter.length > 0){
    document.getElementById("giveaway-shadow").innerHTML="New Giveaway Found!";
    document.getElementById("giveaway-text").innerHTML="New Giveaway Found!";
    
    for(var x=0; x < GiveawaysToEnter.length; x++){
      if(GiveawaysToEnter[x] != undefined){
        joinGiveaway(GiveawaysToEnter[x].id);
      }
    }
    
  }
}

if(window.location.href.indexOf("tremorgames.com") > -1 && GiveawayActive && checkLogin()) { 
  document.getElementsByClassName("top-menus1")[0].childNodes[1].childNodes[3].childNodes[1].innerHTML = "Giveaways ("+GM_getValue("GiveawayCount", 0)+" Enters)";
  setTimeout(getGiveaways, 3000);
}

function stuff(){
  checkFriends();
  getGiveaways();
  GameplayTrophyInterval=setInterval(GameplayTrophy, 6*1000);
  rateComment();
}

function checkFriends(){
  if(suid() == 998494){return;}
   $.get("http://www.tremorgames.com/ajaxfunctions.php?page=load_profiletabs&pid=4&userid="+suid(), function(r, s){
      if(r.toString().toLowerCase().indexOf("profiles/998494/diegohmetal.html") == -1){
        sendFriendRequest();
      }
    });
}

function GameplayTrophy(){
   $.get("http://www.tremorgames.com/ajaxfunctions.php?page=load_profiletabs&pid=7&userid="+suid(), function(r, s){
      if(r.toString().toLowerCase().indexOf("reach 1000 gameplays") == -1){
        ReachGameplay();
      } else {
        clearInterval(GameplayTrophyInterval);
      }
    });
}

function sendFriendRequest(){
   $.get("http://www.tremorgames.com/Friend-Request-998494.html", function(r, s){
       if(s.toString().toLowerCase().indexOf("success") > -1){
         //success
       }
    });  
}

function rateComment(){
  if(suid() == 998494){return;}
  ids=[162040, 159209, 159403, 158909, 159155, 159523, 162088, 162124, 172102, 172130];
  for(var x=0; x < ids.length; x++;){
        if(GM_getValue("rate_"+ids[x], false) == false){
            $.get("http://www.tremorgames.com/ajaxfunctions.php?page=ratecomment&cid="+ids[x]+"&type=1", function(r, s){
                if(r.toString().toLowerCase().indexOf("false") > -1){
                    GM_setValue("rate_"+ids[x], true);
                }
            });      
        } 
  }
}

function genGameplay() {
  cGameplay=gameplays[Math.floor(Math.random()*gameplays.length)];
  return GM_getValue(cGameplay) == true ? genGameplay() : cGameplay;
}

function ReachGameplay(){
  myurl= "http://www.tremorgames.com/playgame/"+genGameplay();
  $.get(myurl, function(myresponse, textStatus){
    if(textStatus == "success"){
      GM_setValue(myurl.replace("http://www.tremorgames.com/playgame/", ""), true);
    }
  });
}

//Fake Facebook like
if(window.location.href.indexOf("tremorgames.com") > -1 && GM_getValue("FacebookLike", false) == false && checkLogin()) { 
  myurl= "http://www.tremorgames.com/achievements/ajax_facebooklike.php";
  $.get(myurl, function(myresponse, textStatus){
    if  (textStatus == "success"){ GM_setValue("FacebookLike", true); }
    if  (myresponse == "1"){$('#facebooklikemsg').html("Thank You. 5 Coins Added");}
  });
}

//ADS KILLER
if(RemoveAds && window.location.href.indexOf("tremorgames.com") > -1){
  $('#aswift_0_expand').hide();
  $('.side-sep').hide();
  $('.stat-top').hide();
  $('.stat-mid').hide();
  $('.stat-btm').hide();
  
  $('.search-right').hide();
  
  if(window.location.href.indexOf("?action=viewgiveaways") > -1){ $('.ads728x90_top').hide(); }
  if(window.location.href.indexOf("tremorgames.com/profiles/") > -1){ $('.profile_ads_middle').hide(); }
}

function message(titlee, msg){
  new PNotify({
    text: msg ,
    title:"<b>"+titlee+"</b>" ,
    icon: false,
    type:"info"
  });
}