<commit_before>'use strict';
const shell = require('electron').shell;

var timer, minutes = 25, seconds = 60,
    pomodoroIntervalId, pomodoroTime;

var display = document.querySelector('#time');
var display_short = document.querySelector('#time_short');
var display_long = document.querySelector('#time_long');

$(document).on('click', 'a[href^="http"]', function(event) {
    event.preventDefault();
    shell.openExternal(this.href);
});

$('#start').click(() => {
  if(minutes == 25 && seconds == 60){
    pomodoroTime = minutes * seconds;
  }else{
    pomodoroTime = minutes * 60 + seconds;
  }

  startTimer(pomodoroTime, display);
  $('#stop').show();
  $('#start').hide();
})

$('#stop').click(() => {
  stopTimer();
  $('#start').show();
  $('#stop').hide();
});

$('#reset').click(() => {
  minutes = 25;
  seconds = 60;
  display.textContent = "25:00";
  resetTimer();

  $('#start').show();
  $('#stop').hide();
});

$('#short_start').click(() => {
  if(minutes == 5 && seconds == 60){
    pomodoroTime = minutes * seconds;
  }else{
    pomodoroTime = minutes * 60 + seconds;
  }

  startTimer(pomodoroTime, display_short);
  $('#short_stop').show();
  $('#short_start').hide();
})

$('#short_stop').click(() => {
  stopTimer();
  $('#short_start').show();
  $('#short_stop').hide();
});

$('#short_reset').click(() => {
  minutes = 5;
  seconds = 60;
  display_short.textContent = "05:00";
  resetTimer(display_short);

  $('#short_start').show();
  $('#short_stop').hide();
});

$('#long_start').click(() => {
  if(minutes == 10 && seconds == 60){
    pomodoroTime = minutes * seconds;
  }else{
    pomodoroTime = minutes * 60 + seconds;
  }

  startTimer(pomodoroTime, display_long);

  $('#long_stop').show();
  $('#long_start').hide();
})

$('#long_stop').click(() => {
  stopTimer();
  $('#long_start').show();
  $('#long_stop').hide();
});

$('#long_reset').click(() => {
  minutes = 10;
  seconds = 60;
  display_long.textContent = "10:00";
  resetTimer();
  $('#long_start').show();
  $('#long_stop').hide();
});

function startTimer(duration, display) {
  timer = duration;
  clearInterval(pomodoroIntervalId);
  pomodoroIntervalId = setInterval(function(){
    if (--timer < 0) {
        timer = duration;
    }

    minutes = parseInt(timer/60, 10);
    seconds = parseInt(timer%60, 10);

    minutes = minutes < 10 ? '0'+minutes : minutes;
    seconds = seconds < 10 ? '0'+seconds : seconds;

    display.textContent = minutes+ ":" + seconds;

    if(minutes == 0 && seconds == 0){
      notifyUser();
      stopTimer();
    }
  }, 1000);
}

function stopTimer(){
  clearInterval(pomodoroIntervalId);
}

function resetTimer() {
  clearInterval(pomodoroIntervalId);
}

function closeApp(){
  ipc.send('closeApp', 'close');
}

$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
    clearInterval(pomodoroIntervalId);

    let activeTab = e.target.toString();
    let nameActiveTab = activeTab.split('#');

    if(nameActiveTab[1]=='pomodoro'){
      minutes = 25, seconds = 60;
      document.querySelector('#time').textContent = "25:00";
    }else if(nameActiveTab[1]=='short'){
      minutes = 5, seconds = 60;
      document.querySelector('#time_short').textContent = "05:00";
    }else {
      minutes = 10, seconds = 60;
      document.querySelector('#time_long').textContent = "10:00";
    }
 })<commit_msg>refactored app.js<commit_after>'use strict';
const shell = require('electron').shell;

class Timer {
    constructor(minutes, seconds = 60) {
        this.minutes = minutes;
        this.seconds = seconds;
        this.initialMinutes = minutes;
        this.initialSeconds = seconds;
        this.timer;
        this.pomodoroTime;
    }

    startTimer(display) {
        this._initializePomotime();
        this.timer = this.pomodoroTime;
        clearInterval(this.pomodoroIntervalId);

        this.pomodoroIntervalId = setInterval(() => {
            if (--(this.timer) < 0) {
                this.timer = this.pomodoroTime;
            }

            this.minutes = parseInt(this.timer / 60, 10);
            this.seconds = parseInt(this.timer % 60, 10);

            this.minutes = this.minutes < 10 ? '0' + this.minutes : this.minutes;
            this.seconds = this.seconds < 10 ? '0' + this.seconds : this.seconds;

            display.textContent = this.minutes + ":" + this.seconds;

            if (this.minutes == 0 && this.seconds == 0) {
                notifyUser();
                this.stopTimer();
            }
        }, 1000);
    }

    stopTimer() {
        clearInterval(this.pomodoroIntervalId);
    }

    resetTimer(selector) {
        this.minutes = this.initialMinutes;
        this.seconds = this.initialSeconds;
        clearInterval(this.pomodoroIntervalId);
        const lol =
            document.querySelector(selector).textContent = `${this._getDoubleDigit(this.initialMinutes)}:00`;
    }

    _getDoubleDigit(number) {
        const filledNumber = '0' + number.toString();
        return filledNumber.length >= 3 ? filledNumber.slice(1, filledNumber.length) : filledNumber;
    }

    _initializePomotime() {
        if (this.minutes == this.initialMinutes && this.seconds == this.initialSeconds) {
            this.pomodoroTime = this.minutes * this.seconds;
        } else {
            this.pomodoroTime = this.minutes * 60 + this.seconds;
        }
    }
}

var display = document.querySelector('#time');
var display_short = document.querySelector('#time_short');
var display_long = document.querySelector('#time_long');

$(document).on('click', 'a[href^="http"]', function (event) {
    event.preventDefault();
    shell.openExternal(this.href);
});


let normalTimer = new Timer(25);

$('#start').click(() => {

    normalTimer.startTimer(display);
    $('#stop').show();
    $('#start').hide();
})

$('#stop').click(() => {
    normalTimer.stopTimer();
    $('#start').show();
    $('#stop').hide();
});

$('#reset').click(() => {
    normalTimer.resetTimer('#time');

    $('#start').show();
    $('#stop').hide();
});

let shortTimer = new Timer(5);

$('#short_start').click(() => {
    shortTimer.startTimer(display_short);
    $('#short_stop').show();
    $('#short_start').hide();
})

$('#short_stop').click(() => {
    shortTimer.stopTimer();

    $('#short_start').show();
    $('#short_stop').hide();
});

$('#short_reset').click(() => {
    shortTimer.resetTimer('#time_short');

    $('#short_start').show();
    $('#short_stop').hide();
});

let longTimer = new Timer(10);

$('#long_start').click(() => {
    longTimer.startTimer(display_long);

    $('#long_stop').show();
    $('#long_start').hide();
})

$('#long_stop').click(() => {
    longTimer.stopTimer();
    $('#long_start').show();
    $('#long_stop').hide();
});

$('#long_reset').click(() => {
    longTimer.resetTimer('#time_long');

    $('#long_start').show();
    $('#long_stop').hide();
});


function closeApp() {
    ipc.send('closeApp', 'close');
}

$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
    let activeTab = e.target.toString();
    let nameActiveTab = activeTab.split('#');

    if (nameActiveTab[1] == 'pomodoro') {
        normalTimer.resetTimer('#time');
    }
    else if (nameActiveTab[1] == 'short') {
        shortTimer.resetTimer('#time_short');
    }
    else {
        longTimer.resetTimer('#time_long');
    }
})
{'fraction_non_alphanumeric': 0.2054364157901926, 'fraction_numerical': 0.017347356918453762, 'mean_word_length': 3.2893966022261276, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 23, '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': '1106851', 'n_tokens_mistral': 2439, 'n_tokens_neox': 2332, 'n_words': 389}