Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1

Thread: Cookie issues

  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cookie issues

    Issue with the following code is the cookie is not getting updated. It does create the cookie though.

    Browser: Opera

    Code:
    javascript: var report = document.body.innerHTML;
    var worldSpeed = 3;
    var period = 1;
    var timber = report.match(/Timber camp <b>\(Level \d{1,2}/i);
    timber = timber.toString().split(" ")[3];
    minelvl(timber);
    tres = mineres;
    var clay = report.match(/Clay pit <b>\(Level \d{1,2}/i);
    clay = clay.toString().split(" ")[3];
    minelvl(clay);
    cres = mineres;
    var iron = report.match(/Iron mine <b>\(Level \d{1,2}/i);
    iron = iron.toString().split(" ")[3];
    minelvl(iron);
    ires = mineres;
    var totallc = Math.round(tres + cres + ires);
    
    var defendingVillage = document.getElementById('attack_info_def').innerText.match(/\d+\|\d+/gi);
    var value = defendingVillage + '|' + totallc;
    
    checkCookie(value);
    
    //alert('This farm produces ' + value + ' resources per +period+ hours.', "JChilds");
    
    
    function getCookie(c_name)
    {
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
      {
      x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
      y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
      x=x.replace(/^\s+|\s+$/g,"");
      if (x==c_name)
        {
        return unescape(y);
        }
      }
    }
    
    function setCookie(c_name,value,exdays)
    {
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
    }
    
    function checkCookie(value)
    {
    var TargetHaul=getCookie("TargetHaul");
    var v=value;
    alert("hi");
    if (TargetHaul!=undefined && TargetHaul!="")
      {
      v=TargetHaul + ' ' + v;
      setCookie("TargetHaul",v,365);
      }
    else 
      {
        v=value;
        setCookie("TargetHaul",v,365);
      }
    }
    
    
    function minelvl(mine) {
        if (mine == 0) {
            mineres = 5
        }
        if (mine == 1) {
            mineres = 30
        }
        if (mine == 2) {
            mineres = 35
        }
        if (mine == 3) {
            mineres = 41
        }
        if (mine == 4) {
            mineres = 47
        }
        if (mine == 5) {
            mineres = 55
        }
        if (mine == 6) {
            mineres = 64
        }
        if (mine == 7) {
            mineres = 74
        }
        if (mine == 8) {
            mineres = 86
        }
        if (mine == 9) {
            mineres = 100
        }
        if (mine == 10) {
            mineres = 117
        }
        if (mine == 11) {
            mineres = 136
        }
        if (mine == 12) {
            mineres = 158
        }
        if (mine == 13) {
            mineres = 184
        }
        if (mine == 14) {
            mineres = 214
        }
        if (mine == 15) {
            mineres = 249
        }
        if (mine == 16) {
            mineres = 289
        }
        if (mine == 17) {
            mineres = 337
        }
        if (mine == 18) {
            mineres = 391
        }
        if (mine == 19) {
            mineres = 455
        }
        if (mine == 20) {
            mineres = 530
        }
        if (mine == 21) {
            mineres = 616
        }
        if (mine == 22) {
            mineres = 717
        }
        if (mine == 23) {
            mineres = 833
        }
        if (mine == 24) {
            mineres = 969
        }
        if (mine == 25) {
            mineres = 1127
        }
        if (mine == 26) {
            mineres = 1311
        }
        if (mine == 27) {
            mineres = 1525
        }
        if (mine == 28) {
            mineres = 1774
        }
        if (mine == 29) {
            mineres = 2063
        }
        if (mine == 30) {
            mineres = 2400
        }
        mineres = mineres * worldSpeed;
    };
    Last edited by SearchOfGod; 12-31-2011 at 09:41 AM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •