<commit_before>// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

function updateIcon() {
  var xmlHttp = new XMLHttpRequest();
  xmlHttp.open( "GET", "https://alerts.skia.org/json/alerts/", false );
  xmlHttp.send(null);
  var alerts = JSON.parse(xmlHttp.responseText);
  var numActiveInfraAlerts = 0;
  for (var i = 0; i < alerts.length; i++) {
    if (alerts[i]["category"] == "infra" && alerts[i]["snoozedUntil"] == 0) {
      numActiveInfraAlerts++;
    }
  }
  chrome.browserAction.setIcon({path:"bell.png"});
  chrome.browserAction.setTitle({title:"Alerts for Skia Troopers"});
  chrome.browserAction.setBadgeText({text: String(numActiveInfraAlerts)});
  if (numActiveInfraAlerts > 0) {
    chrome.browserAction.setBadgeBackgroundColor({color: "red"});
  } else {
    chrome.browserAction.setBadgeBackgroundColor({color: "green"});
  }

  setTimeout(updateIcon, 10000);<commit_msg>Keep background thread alive even if alertserver down and add async request<commit_after>// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

function updateIcon() {
  var xmlHttp = new XMLHttpRequest();
  xmlHttp.open("GET", "https://alerts.skia.org/json/alerts/", true);
  xmlHttp.timeout = 5000;
  xmlHttp.onload = function(e) {
    if (xmlHttp.readyState === XMLHttpRequest.DONE && xmlHttp.status === 200) {
      var alerts = JSON.parse(xmlHttp.responseText);
      var numActiveInfraAlerts = 0;
      for (var i = 0; i < alerts.length; i++) {
        if (alerts[i]["category"] == "infra" && alerts[i]["snoozedUntil"] == 0) {
          numActiveInfraAlerts++;
        }
      }
      chrome.browserAction.setIcon({path:"bell.png"});
      chrome.browserAction.setTitle({title:"Alerts for Skia Troopers"});
      chrome.browserAction.setBadgeText({text: String(numActiveInfraAlerts)});
      if (numActiveInfraAlerts > 0) {
        chrome.browserAction.setBadgeBackgroundColor({color: "red"});
      } else {
        chrome.browserAction.setBadgeBackgroundColor({color: "green"});
      }
    } else {
      console.error("Error talking to alertserver.");
    }
  }
  xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == XMLHttpRequest.DONE) {
      setTimeout(updateIcon, 10000);
    }
  }
  xmlHttp.onerror = function(e) {
    console.error("Error talking to alertserver.");
  }
  xmlHttp.send(null);
{'fraction_non_alphanumeric': 0.14280109846998823, 'fraction_numerical': 0.012946253432718713, 'mean_word_length': 3.7486033519553073, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 15}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4812837', 'n_tokens_mistral': 860, 'n_tokens_neox': 798, 'n_words': 186}