<commit_before>'use strict';

var $ = jQuery, stopwatch;

chrome.runtime.onInstalled.addListener(function (details) {
  console.log('previousVersion', details.previousVersion);
});

var Timer = function(options) {
  if(options == null) {
    options = {};
  }
  this.seconds = options.seconds ? options.seconds : 0;
  this.minutes = options.minutes ? options.minutes : 0;
  this.hours = options.hours ? options.hours : 0.0;
  this.notes = options.notes ? options.notes : '';
}
Timer.prototype.setSeconds = function(seconds) {
  this.seconds = seconds;
  this.minutes = this.seconds / 60;
  this.hours = this.minutes / 60;
}
Timer.prototype.formatted = function() {
  function pad2(number) {
    return (number < 10 ? '0' : '') + number;
  }
  function defaultFormatMilliseconds(seconds) {
      var x = seconds, minutes, hours;
      seconds = Math.floor(x % 60)
      x /= 60;
      minutes = Math.floor(x % 60);
      x /= 60;
      hours = Math.floor(x % 24);
      return [pad2(hours), pad2(minutes), pad2(seconds)].join(':');
  }
  return defaultFormatMilliseconds(this.seconds);
}
var activeTimer = new Timer();
var openPort;

var setInactiveIcon = function() {
  chrome.browserAction.setIcon({path: 'images/icon-38-inactive.png'})
};
var setActiveIcon = function() {
  chrome.browserAction.setIcon({path: 'images/icon-38.png'})
};

chrome.runtime.onConnect.addListener(function(port) {
  console.assert(port.name == "freshbooks-trello");
  openPort = port;
  port.onMessage.addListener(function(msg) {
    if (msg.action == "startTimer") {
      setActiveIcon();
      if(!activeTimer) {
        activeTimer = new Timer();
      }
      if(msg.data) {
        if(msg.data.notes) {
          activeTimer.notes = msg.data.notes
        }
        if(msg.data.project_id) {
          activeTimer.project_id = msg.data.project_id
        }
        if(msg.data.task_id) {
          activeTimer.task_id = msg.data.task_id
        }
        if(msg.data.staff_id) {
          activeTimer.staff_id = msg.data.staff_id
        }
      }

      stopwatch.stopwatch('start');

    } else if (msg.action == 'pauseTimer') {
      setInactiveIcon();
      stopwatch.stopwatch('stop');

    } else if (msg.action == "resetTimer" || msg.action == "setTimer") {
      var seconds = 0;
      setInactiveIcon();

      if(msg.data && msg.data.hours) {
        seconds = msg.data.hours * 60 * 60;<commit_msg>fix bug where reset wasn’t resetting properly<commit_after>'use strict';

var $ = jQuery, stopwatch;

chrome.runtime.onInstalled.addListener(function (details) {
  console.log('previousVersion', details.previousVersion);
});

var Timer = function(options) {
  if(options == null) {
    options = {};
  }
  this.seconds = options.seconds ? options.seconds : 0;
  this.minutes = options.minutes ? options.minutes : 0;
  this.hours = options.hours ? options.hours : 0.0;
  this.notes = options.notes ? options.notes : '';
}
Timer.prototype.setSeconds = function(seconds) {
  this.seconds = seconds;
  this.minutes = this.seconds / 60;
  this.hours = this.minutes / 60;
}
Timer.prototype.formatted = function() {
  function pad2(number) {
    return (number < 10 ? '0' : '') + number;
  }
  function defaultFormatMilliseconds(seconds) {
      var x = seconds, minutes, hours;
      seconds = Math.floor(x % 60)
      x /= 60;
      minutes = Math.floor(x % 60);
      x /= 60;
      hours = Math.floor(x % 24);
      return [pad2(hours), pad2(minutes), pad2(seconds)].join(':');
  }
  return defaultFormatMilliseconds(this.seconds);
}
var activeTimer = new Timer();
var openPort;

var setInactiveIcon = function() {
  chrome.browserAction.setIcon({path: 'images/icon-38-inactive.png'})
};
var setActiveIcon = function() {
  chrome.browserAction.setIcon({path: 'images/icon-38.png'})
};

chrome.runtime.onConnect.addListener(function(port) {
  console.assert(port.name == "freshbooks-trello");
  openPort = port;
  port.onMessage.addListener(function(msg) {
    if (msg.action == "startTimer") {
      setActiveIcon();
      if(!activeTimer) {
        activeTimer = new Timer();
      }
      if(msg.data) {
        if(msg.data.notes) {
          activeTimer.notes = msg.data.notes
        }
        if(msg.data.project_id) {
          activeTimer.project_id = msg.data.project_id
        }
        if(msg.data.task_id) {
          activeTimer.task_id = msg.data.task_id
        }
        if(msg.data.staff_id) {
          activeTimer.staff_id = msg.data.staff_id
        }
      }

      stopwatch.stopwatch('start');

    } else if (msg.action == 'pauseTimer') {
      setInactiveIcon();
      stopwatch.stopwatch('stop');

    } else if (msg.action == "resetTimer" || msg.action == "setTimer") {
      var seconds = 0;
      setInactiveIcon();
      if(msg.action == "resetTimer") {
        activeTimer = new Timer();
      }

      if(msg.data && msg.data.hours) {
        seconds = msg.data.hours * 60 * 60;
{'fraction_non_alphanumeric': 0.1493877551020408, 'fraction_numerical': 0.013877551020408163, 'mean_word_length': 2.8259172521467604, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5416312', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1568, 'n_words': 292}