<commit_before>var battery;
var config;

var CHARGING_MASK =           0x80;
var LEVEL_MASK =              0x7f;
var BATTERY_API_UNSUPPORTED = 0x70;

var PKEY_CONFIG = "pebble-watch-11weeks-config";
var DEFAULT_CONFIG = 0;

var getBatteryStateInt = function () {
  'use strict';
  var state = 0;
  console.log("battery is: " + battery);
  if (battery) {
    state = Math.round(battery.level * 100);
    if (battery.charging) {
      state |= CHARGING_MASK;
    }
    console.log('got battery state: ' + state);
  } else {
    state = BATTERY_API_UNSUPPORTED;
    console.log('battery API unsupported.');
  }
  return state;
};

var sendBatteryState = function () {
  'use strict';
  var dict = {
    "KEY_PHONE_BATTERY": getBatteryStateInt()
  };
  Pebble.sendAppMessage(dict, function() {
    console.log('Message sent successfully: ' + JSON.stringify(dict));
  }, function(e) {
    console.log('Message failed: ' + JSON.stringify(e));
  });
};

var handleBattery = function () {
  'use strict';
  if (battery) {
    battery.addEventListener('chargingchange', sendBatteryState);
    battery.addEventListener('levelchange', sendBatteryState);
  }
  sendBatteryState();
};

var initBattery = function () {
  'use strict';
  battery = navigator.battery || navigator.webkitBattery || navigator.mozBattery;
  console.log("set battery: " + battery);
  if (navigator.getBattery) {
    console.log("battery API exists.");
    navigator.getBattery().then(function (b) {
      battery = b;
      console.log("set battery in then(): " + b);
      handleBattery();
    });
  } else {
    handleBattery();
  }
};

var sendConfig = function () {
  'use strict';
  var dict = {
    'KEY_CONFIG_VALUE': config
  };
  Pebble.sendAppMessage(dict, function() {
    console.log('Message sent successfully: ' + JSON.stringify(dict));
  }, function(e) {
    console.log('Message failed: ' + JSON.stringify(e));
  });
};

Pebble.addEventListener('ready', function (e) {
  'use strict';
  initBattery();
});

Pebble.addEventListener('showConfiguration', function(e) {
  'use strict';
  Pebble.openURL('http://rawgit.com/programus/pebble-watchface-11weeks/app-config/src/html/config.html');
});

Pebble.addEventListener('webviewclosed', function(e) {
  // Decode the user's preferences
  var configData = JSON.parse(decodeURIComponent(e.response));
  config = configData.config;
  sendConfig();
});<commit_msg>use new url of moved html folder.<commit_after>var battery;
var config;

var CHARGING_MASK =           0x80;
var LEVEL_MASK =              0x7f;
var BATTERY_API_UNSUPPORTED = 0x70;

var PKEY_CONFIG = "pebble-watch-11weeks-config";
var DEFAULT_CONFIG = 0;

var getBatteryStateInt = function () {
  'use strict';
  var state = 0;
  console.log("battery is: " + battery);
  if (battery) {
    state = Math.round(battery.level * 100);
    if (battery.charging) {
      state |= CHARGING_MASK;
    }
    console.log('got battery state: ' + state);
  } else {
    state = BATTERY_API_UNSUPPORTED;
    console.log('battery API unsupported.');
  }
  return state;
};

var sendBatteryState = function () {
  'use strict';
  var dict = {
    "KEY_PHONE_BATTERY": getBatteryStateInt()
  };
  Pebble.sendAppMessage(dict, function() {
    console.log('Message sent successfully: ' + JSON.stringify(dict));
  }, function(e) {
    console.log('Message failed: ' + JSON.stringify(e));
  });
};

var handleBattery = function () {
  'use strict';
  if (battery) {
    battery.addEventListener('chargingchange', sendBatteryState);
    battery.addEventListener('levelchange', sendBatteryState);
  }
  sendBatteryState();
};

var initBattery = function () {
  'use strict';
  battery = navigator.battery || navigator.webkitBattery || navigator.mozBattery;
  console.log("set battery: " + battery);
  if (navigator.getBattery) {
    console.log("battery API exists.");
    navigator.getBattery().then(function (b) {
      battery = b;
      console.log("set battery in then(): " + b);
      handleBattery();
    });
  } else {
    handleBattery();
  }
};

var sendConfig = function () {
  'use strict';
  var dict = {
    'KEY_CONFIG_VALUE': config
  };
  Pebble.sendAppMessage(dict, function() {
    console.log('Message sent successfully: ' + JSON.stringify(dict));
  }, function(e) {
    console.log('Message failed: ' + JSON.stringify(e));
  });
};

Pebble.addEventListener('ready', function (e) {
  'use strict';
  initBattery();
});

Pebble.addEventListener('showConfiguration', function(e) {
  'use strict';
  Pebble.openURL('http://rawgit.com/programus/pebble-watchface-11weeks/app-config/html/config.html');
});

Pebble.addEventListener('webviewclosed', function(e) {
  // Decode the user's preferences
  var configData = JSON.parse(decodeURIComponent(e.response));
  config = configData.config;
  sendConfig();
});
{'fraction_non_alphanumeric': 0.15121136173767752, 'fraction_numerical': 0.007101086048454469, 'mean_word_length': 3.793793793793794, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2937734', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1596, 'n_words': 312}