Skip to content

Commit

Permalink
Use cached match data
Browse files Browse the repository at this point in the history
  • Loading branch information
ripexz committed Aug 25, 2014
1 parent 612cf05 commit a64f901
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ var d2betalert = {

getData: function() {
chrome.storage.local.get('dota2matches', function(matchObj){
if (matchObj.valid) {

if (matchObj.dota2matches && matchObj.dota2matches.valid) {
d2betalert.renderMatches(matchObj.dota2matches);
}
else {
this.getDataViaAjax();
d2betalert.getDataViaAjax();
}
});
},
Expand All @@ -21,12 +21,14 @@ var d2betalert = {
},

renderMatches: function(data) {
var matchObj;
var matchObj, countStr;
if (data.valid) {
matchObj = data;
}
else {
matchObj = JSON.parse(data.target.responseText);
matchObj.valid = true;
chrome.storage.local.set({'dota2matches': matchObj});
}

if (matchObj.matches && matchObj.matches.length > 0) {
Expand All @@ -36,16 +38,16 @@ var d2betalert = {
p.innerHTML = '<span class="t1">'+matchObj.matches[i].team1+'</span><span class="vs">vs</span><span class="t2">'+matchObj.matches[i].team2+'</span>';
document.getElementById('match_list').appendChild(p);
}
var str_num = i + '';
countStr = i + '';
this.applyBindings();
}
else {
var p = document.createElement('p');
p.innerHTML = 'No active matches found.';
document.getElementById('match_list').appendChild(p);
var str_num ='0';
countStr = '0';
}
chrome.browserAction.setBadgeText({text:str_num});
chrome.browserAction.setBadgeText({text: countStr});
},

applyBindings: function() {
Expand Down

0 comments on commit a64f901

Please sign in to comment.