function putdata(json)
{ 
  // removes the previous contest entries.
  $("#upcoming > a").remove();
  $("#ongoing > a").remove();
  $("hr").remove();

  // the conditional statements that compare the start and end time with curTime
  // verifies that each contest gets added to right section regardless of the 
  // section it was present in the "json" variable.
  
  //storing locally for notification purpose
  var FetchedContestURLs = {};
  var FetchedContestNames = {};

  // for unread Tag
  var localStorageData = localStorage.getItem("FetchedContestURLs");
  //for first time run prev fetched urls should be equal to null 
  if((localStorageData === null) || (localStorageData.length === 0)){ localStorageData = "{}";}
  var prevFetchContestURLs = JSON.parse(localStorageData);
  var notifierTag = false;

  curTime  = new Date();

  $.each(json.result.ongoing , function(i,post){ 
    flag=0;
    if(post.Platform=="HACKEREARTH"){
      if(localStorage.getItem(post.Platform+post.challenge_type)=="false")flag=1;
    }
    
    if(localStorage.getItem(post.Platform)=="true" && flag==0){
      endTime   = Date.parse(post.EndTime);
      timezonePerfectEndTime  = changeTimezone(endTime).toString().slice(0,21);
      e = new Date(endTime);
      
      if(e>curTime){
        humanReadableEndTime = moment(timezonePerfectEndTime).fromNow();
      //no to contest with same name should come up again
      if(!(post.Name in FetchedContestNames)){
      FetchedContestNames[post.Name] = 1;

        $("#ongoing").append('<a  data='+'"'+post.url+'"'+'>\
          <li><br><h3>'+post.Name+'</h3>\
          <img title="'+post.Platform+'" src="'+icon(post.Platform)+'"></img><br>\
          <h4>End: '+timezonePerfectEndTime+' ( ' + humanReadableEndTime + ' )</h4><br>\
          </li><hr></a>');
      }

      }
    }
  });

  $.each(json.result.upcoming , function(i,post){ 
    flag=0;
    if(post.Platform=="HACKEREARTH"){
      if(localStorage.getItem(post.Platform+post.challenge_type)=="false")flag=1;
    }

    if(localStorage.getItem(post.Platform)=="true" && flag==0){
      // converts the startTime and Endtime revieved
      // to the format required for the Google Calender link to work
      startTime = Date.parse(post.StartTime)
      timezonePerfectStartTime  = changeTimezone(startTime).toString().slice(0,21);
      endTime   = Date.parse(post.EndTime)
      timezonePerfectEndTime  = changeTimezone(endTime).toString().slice(0,21);
      humanReadableStartTime = moment(timezonePerfectStartTime).fromNow();
      humanReadableEndTime = moment(timezonePerfectEndTime).fromNow();

      s = new Date(changeTimezone(startTime).getTime() - ((curTime).getTimezoneOffset()*60000 )).toISOString().slice(0,19).replace(/-/g,"").replace(/:/g,"");
      e = new Date(changeTimezone(endTime).getTime() - ((curTime).getTimezoneOffset()*60000 )).toISOString().slice(0,19).replace(/-/g,"").replace(/:/g,"");
      
      calendarTime = s+'/'+e
      calendarLink = "https://www.google.com/calendar/render?action=TEMPLATE&text="+encodeURIComponent(post.Name)+"&dates="+calendarTime+"&location="+post.url+"&pli=1&uid=&sf=true&output=xml#eventpage_6"
      
      sT = new Date(startTime);
      eT = new Date(endTime);

      FetchedContestURLs[post.url] = 1;


      if(sT<curTime && eT>curTime){
        $("#ongoing").append('<a  data='+'"'+post.url+'"'+'>\
          <li><br><h3>'+post.Name+'</h3>\
          <img title="'+post.Platform+'" src="'+icon(post.Platform)+'"></img><br>\
          <h4>End: '+timezonePerfectEndTime+' ( ' + humanReadableEndTime + ' )</h4><br>\
          </li><hr></a>');
      }
      else if(sT>curTime && eT>curTime){
        //checking whether new contest has been added or not
        unreadTag = '';
        if(!(post.url in prevFetchContestURLs)){
          unreadTag = '<div class="unread">new</div>';
          notifierTag = true;
        }
      if(!(post.Name in FetchedContestNames)){
      FetchedContestNames[post.Name] = 1;

        $("#upcoming").append('<div class="unread-bg">' + unreadTag + '<a  data='+'"'+post.url+'"'+'>\
          <li><br><h3>'+post.Name+'</h3>\
          <img title="'+post.Platform+'" src="'+icon(post.Platform)+'"></img><br>\
          <h4>Start: '+timezonePerfectStartTime+' ( ' + humanReadableStartTime + ' )</h4><br>\
          <h4>Duration: '+post.Duration+'</h4><br>\
          <h4 data='+calendarLink+' class="calendar">Add to Calendar</h4>\
          </li><hr></a></div>');
        }
      }
    }
  });

  //saving into local storage
  localStorage.setItem("FetchedContestURLs",JSON.stringify(FetchedContestURLs));
  if(notifierTag){document.getElementById('scroll-info').style.display = "inline";}
  chrome.browserAction.setBadgeText({text: ""}); // We have 0 unread items.
  setTimeout(function(){$("#scroll-info").fadeOut(700);},5000);
}
// Then add contest fields are added by going through the recieved json.
Then add contest fields are added by going through the recieved json.
Then add contest fields are added by going through the recieved json .
function putdata(json)
{ 
  $("#upcoming > a").remove();
  $("#ongoing > a").remove();
  $("hr").remove();
  var FetchedContestURLs = {};
  var FetchedContestNames = {};
  var localStorageData = localStorage.getItem("FetchedContestURLs");
  if((localStorageData === null) || (localStorageData.length === 0)){ localStorageData = "{}";}
  var prevFetchContestURLs = JSON.parse(localStorageData);
  var notifierTag = false;
  curTime  = new Date();
  $.each(json.result.ongoing , function(i,post){ 
    flag=0;
    if(post.Platform=="HACKEREARTH"){
      if(localStorage.getItem(post.Platform+post.challenge_type)=="false")flag=1;
    }
    if(localStorage.getItem(post.Platform)=="true" && flag==0){
      endTime   = Date.parse(post.EndTime);
      timezonePerfectEndTime  = changeTimezone(endTime).toString().slice(0,21);
      e = new Date(endTime);
      if(e>curTime){
        humanReadableEndTime = moment(timezonePerfectEndTime).fromNow();
      if(!(post.Name in FetchedContestNames)){
      FetchedContestNames[post.Name] = 1;
        $("#ongoing").append('<a  data='+'"'+post.url+'"'+'>\
          <li><br><h3>'+post.Name+'</h3>\
          <img title="'+post.Platform+'" src="'+icon(post.Platform)+'"></img><br>\
          <h4>End: '+timezonePerfectEndTime+' ( ' + humanReadableEndTime + ' )</h4><br>\
          </li><hr></a>');
      }
      }
    }
  });
  $.each(json.result.upcoming , function(i,post){ 
    flag=0;
    if(post.Platform=="HACKEREARTH"){
      if(localStorage.getItem(post.Platform+post.challenge_type)=="false")flag=1;
    }
    if(localStorage.getItem(post.Platform)=="true" && flag==0){
      startTime = Date.parse(post.StartTime)
      timezonePerfectStartTime  = changeTimezone(startTime).toString().slice(0,21);
      endTime   = Date.parse(post.EndTime)
      timezonePerfectEndTime  = changeTimezone(endTime).toString().slice(0,21);
      humanReadableStartTime = moment(timezonePerfectStartTime).fromNow();
      humanReadableEndTime = moment(timezonePerfectEndTime).fromNow();
      s = new Date(changeTimezone(startTime).getTime() - ((curTime).getTimezoneOffset()*60000 )).toISOString().slice(0,19).replace(/-/g,"").replace(/:/g,"");
      e = new Date(changeTimezone(endTime).getTime() - ((curTime).getTimezoneOffset()*60000 )).toISOString().slice(0,19).replace(/-/g,"").replace(/:/g,"");
      calendarTime = s+'/'+e
      calendarLink = "https://www.google.com/calendar/render?action=TEMPLATE&text="+encodeURIComponent(post.Name)+"&dates="+calendarTime+"&location="+post.url+"&pli=1&uid=&sf=true&output=xml#eventpage_6"
      sT = new Date(startTime);
      eT = new Date(endTime);
      FetchedContestURLs[post.url] = 1;
      if(sT<curTime && eT>curTime){
        $("#ongoing").append('<a  data='+'"'+post.url+'"'+'>\
          <li><br><h3>'+post.Name+'</h3>\
          <img title="'+post.Platform+'" src="'+icon(post.Platform)+'"></img><br>\
          <h4>End: '+timezonePerfectEndTime+' ( ' + humanReadableEndTime + ' )</h4><br>\
          </li><hr></a>');
      }
      else if(sT>curTime && eT>curTime){
        unreadTag = '';
        if(!(post.url in prevFetchContestURLs)){
          unreadTag = '<div class="unread">new</div>';
          notifierTag = true;
        }
      if(!(post.Name in FetchedContestNames)){
      FetchedContestNames[post.Name] = 1;
        $("#upcoming").append('<div class="unread-bg">' + unreadTag + '<a  data='+'"'+post.url+'"'+'>\
          <li><br><h3>'+post.Name+'</h3>\
          <img title="'+post.Platform+'" src="'+icon(post.Platform)+'"></img><br>\
          <h4>Start: '+timezonePerfectStartTime+' ( ' + humanReadableStartTime + ' )</h4><br>\
          <h4>Duration: '+post.Duration+'</h4><br>\
          <h4 data='+calendarLink+' class="calendar">Add to Calendar</h4>\
          </li><hr></a></div>');
        }
      }
    }
  });
  localStorage.setItem("FetchedContestURLs",JSON.stringify(FetchedContestURLs));
  if(notifierTag){document.getElementById('scroll-info').style.display = "inline";}
  chrome.browserAction.setBadgeText({text: ""}); 
  setTimeout(function(){$("#scroll-info").fadeOut(700);},5000);
}
function putdata ( json ) { $ ( "#upcoming > a" ) . remove ( ) ; $ ( "#ongoing > a" ) . remove ( ) ; $ ( "hr" ) . remove ( ) ; var FetchedContestURLs = { } ; var FetchedContestNames = { } ; var localStorageData = localStorage . getItem ( "FetchedContestURLs" ) ; if ( ( localStorageData === null ) || ( localStorageData . length === 0 ) ) { localStorageData = "{}" ; } var prevFetchContestURLs = JSON . parse ( localStorageData ) ; var notifierTag = false ; curTime = new Date ( ) ; $ . each ( json . result . ongoing , function ( i , post ) { flag = 0 ; if ( post . Platform == "HACKEREARTH" ) { if ( localStorage . getItem ( post . Platform + post . challenge_type ) == "false" ) flag = 1 ; } if ( localStorage . getItem ( post . Platform ) == "true" && flag == 0 ) { endTime = Date . parse ( post . EndTime ) ; timezonePerfectEndTime = changeTimezone ( endTime ) . toString ( ) . slice ( 0 , 21 ) ; e = new Date ( endTime ) ; if ( e > curTime ) { humanReadableEndTime = moment ( timezonePerfectEndTime ) . fromNow ( ) ; if ( ! ( post . Name in FetchedContestNames ) ) { FetchedContestNames [ post . Name ] = 1 ; $ ( "#ongoing" ) . append ( '<a  data=' + '"' + post . url + '"' + '>\
          <li><br><h3>' + post . Name + '</h3>\
          <img title="' + post . Platform + '" src="' + icon ( post . Platform ) + '"></img><br>\
          <h4>End: ' + timezonePerfectEndTime + ' ( ' + humanReadableEndTime + ' )</h4><br>\
          </li><hr></a>' ) ; } } } } ) ; $ . each ( json . result . upcoming , function ( i , post ) { flag = 0 ; if ( post . Platform == "HACKEREARTH" ) { if ( localStorage . getItem ( post . Platform + post . challenge_type ) == "false" ) flag = 1 ; } if ( localStorage . getItem ( post . Platform ) == "true" && flag == 0 ) { startTime = Date . parse ( post . StartTime ) timezonePerfectStartTime = changeTimezone ( startTime ) . toString ( ) . slice ( 0 , 21 ) ; endTime = Date . parse ( post . EndTime ) timezonePerfectEndTime = changeTimezone ( endTime ) . toString ( ) . slice ( 0 , 21 ) ; humanReadableStartTime = moment ( timezonePerfectStartTime ) . fromNow ( ) ; humanReadableEndTime = moment ( timezonePerfectEndTime ) . fromNow ( ) ; s = new Date ( changeTimezone ( startTime ) . getTime ( ) - ( ( curTime ) . getTimezoneOffset ( ) * 60000 ) ) . toISOString ( ) . slice ( 0 , 19 ) . replace ( / - / g , "" ) . replace ( / : / g , "" ) ; e = new Date ( changeTimezone ( endTime ) . getTime ( ) - ( ( curTime ) . getTimezoneOffset ( ) * 60000 ) ) . toISOString ( ) . slice ( 0 , 19 ) . replace ( / - / g , "" ) . replace ( / : / g , "" ) ; calendarTime = s + '/' + e calendarLink = "https://www.google.com/calendar/render?action=TEMPLATE&text=" + encodeURIComponent ( post . Name ) + "&dates=" + calendarTime + "&location=" + post . url + "&pli=1&uid=&sf=true&output=xml#eventpage_6" sT = new Date ( startTime ) ; eT = new Date ( endTime ) ; FetchedContestURLs [ post . url ] = 1 ; if ( sT < curTime && eT > curTime ) { $ ( "#ongoing" ) . append ( '<a  data=' + '"' + post . url + '"' + '>\
          <li><br><h3>' + post . Name + '</h3>\
          <img title="' + post . Platform + '" src="' + icon ( post . Platform ) + '"></img><br>\
          <h4>End: ' + timezonePerfectEndTime + ' ( ' + humanReadableEndTime + ' )</h4><br>\
          </li><hr></a>' ) ; } else if ( sT > curTime && eT > curTime ) { unreadTag = '' ; if ( ! ( post . url in prevFetchContestURLs ) ) { unreadTag = '<div class="unread">new</div>' ; notifierTag = true ; } if ( ! ( post . Name in FetchedContestNames ) ) { FetchedContestNames [ post . Name ] = 1 ; $ ( "#upcoming" ) . append ( '<div class="unread-bg">' + unreadTag + '<a  data=' + '"' + post . url + '"' + '>\
          <li><br><h3>' + post . Name + '</h3>\
          <img title="' + post . Platform + '" src="' + icon ( post . Platform ) + '"></img><br>\
          <h4>Start: ' + timezonePerfectStartTime + ' ( ' + humanReadableStartTime + ' )</h4><br>\
          <h4>Duration: ' + post . Duration + '</h4><br>\
          <h4 data=' + calendarLink + ' class="calendar">Add to Calendar</h4>\
          </li><hr></a></div>' ) ; } } } } ) ; localStorage . setItem ( "FetchedContestURLs" , JSON . stringify ( FetchedContestURLs ) ) ; if ( notifierTag ) { document . getElementById ( 'scroll-info' ) . style . display = "inline" ; } chrome . browserAction . setBadgeText ( { text : "" } ) ; setTimeout ( function ( ) { $ ( "#scroll-info" ) . fadeOut ( 700 ) ; } , 5000 ) ; }
Then add contest fields are added by going through the recieved json.
Then add contest fields are added by going through the recieved json .
// removes the previous contest entries. // the conditional statements that compare the start and end time with curTime // verifies that each contest gets added to right section regardless of the  // section it was present in the "json" variable. //storing locally for notification purpose // for unread Tag //for first time run prev fetched urls should be equal to null  //no to contest with same name should come up again // converts the startTime and Endtime revieved // to the format required for the Google Calender link to work //checking whether new contest has been added or not //saving into local storage // We have 0 unread items.