<commit_before>// global variables
var initialized = false,
  active = false;
  activeColumn = 0,
  port = chrome.runtime.connect({name: 'keytar'});;

// DOM elements
var $keyboard,
  $text,
  $pitch;

var KEY_NOTE_MAPPINGS = {
  'E4': {
    'G3': 'Z',
    'G#3': 'X',
    'B4': 'A',
    'C4': 'S',
    'E4': 'Q',
    'F4': 'W',
  },
  'F4': {
    'G#3': 'C',
    'A4': 'V',
    'C4': 'D',
    'C#4': 'F',
    'F4': 'E',
    'F#4': 'R',
  },
  'F#4': {
    'A4': 'B',
    'A#4': 'N',
    'C#4': 'G',
    'D4': 'H',
    'F#4': 'T',
    'G4': 'Y',
  },
  'G4': {
    'A#4': 'M',
    'B4': ',',
    'D4': 'J',
    'D#4': 'K',
    'G4': 'U',
    'G#4': 'I',
  },
  'G#4': {
    'B4': '.',
    'C4': '/',
    'D#4': 'L',
    'E4': ';',
    'G#4': 'O',
    'A5': 'P',
  },
  'D3': ' ',
  'D#3': ' ',
  'E3': ' ',
  'F3': 'bs',
  'F#3': 'bs'
};

var KeyboardState = function(callback) {
  this.typeKey = callback;
  this.options = KEY_NOTE_MAPPINGS;
};

KeyboardState.prototype.addNote = function(note) {
  if (!(note in this.options)) {
    return;
  }
  this.options = this.options[note];
  console.log('OPTIONS:', this.options);
  if (typeof this.options === 'string') {
    this.typeKey(this.options);
    this.options = KEY_NOTE_MAPPINGS;
    activeColumn = 0;
    activateColumn(activeColumn);
  } else {
    switch (note) {
      case 'E4':
        activeColumn = 1;
        break;
      case 'F4':
        activeColumn = 2;
        break;
      case 'F#4':
        activeColumn = 3;
        break;
      case 'G4':
        activeColumn = 4;
        break;
      case 'G#4':
        activeColumn = 5;
        break;
    }
    activateColumn(activeColumn);
  }
};

var keyboardState = new KeyboardState(playNote);
port.onMessage.addListener(function(msg) {
  console.log('got' + msg.note);
  keyboardState.addNote(msg.note);
});

loadStyle();
loadKeyboard();
$(document).ready(function () {
  $keyboard = $('.kt-keyboard');
  $pitch = $('.kt-active-pitch p');
  $('textarea, input, .tweet-box, [role="textbox"]').focus(function () {
    toggleKeyboard(true);
    $text = $(this);
  }).blur(function () {
    toggleKeyboard(false);
  });
});

function toggleKeyboard(activate) {
  if (!initialized) return;
  active = activate;
  if (activate) {
    $keyboard.addClass('active');
  } else {
    $keyboard.removeClass('active');
  }
}

function activateColumn(column) {
  if (!active) return;
  activeColumn = column;
  if (column == 0) return;
  $('.kt-column').removeClass('active');
  $('.kt-column:eq('+(column-1)+')').addClass('active');
}

function playNote(charTyped) {
  if (!initialized) return;
  if (charTyped === 'bs') {
    $text.html($text.text().splice(0, $text.text().length - 1));
  } else {
    $text.html($text.text() + charTyped);
  }
}

function loadStyle() {
  var link = document.createElement('link');
  link.href = 'https://fonts.googleapis.com/css?family=Roboto';
  link.type = 'text/css';
  link.rel = 'stylesheet';
  document.getElementsByTagName('head')[0].appendChild(link);
}

function loadKeyboard() {
  if (initialized) return;
  initialized = true;

  var $container = document.createElement('div'),
    $activePitch = document.createElement('div'),
    $keyWrap = document.createElement('div'),
    $strings = document.createElement('div'),
    $columns = document.createElement('div'),
    $spacebar = document.createElement('div'),
    $backspace = document.createElement('div');
<commit_msg>Shifted stuff<commit_after>// global variables
var initialized = false,
  active = false;
  activeColumn = 0,
  port = chrome.runtime.connect({name: 'keytar'});;

// DOM elements
var $keyboard,
  $text,
  $pitch;

var KEY_NOTE_MAPPINGS = {
  'F4': {
    'G#3': 'Z',
    'A3': 'X',
    'C4': 'A',
    'C#4': 'S',
    'F4': 'Q',
    'F#4': 'W',
  },
  'F#4': {
    'A4': 'C',
    'A#4': 'V',
    'C#4': 'D',
    'D4': 'F',
    'F#4': 'E',
    'G4': 'R',
  },
  'G4': {
    'A#4': 'B',
    'B4': 'N',
    'D4': 'G',
    'D#4': 'H',
    'G4': 'T',
    'G#4': 'Y',
  },
  'G#4': {
    'B4': 'M',
    'C4': ',',
    'D#4': 'J',
    'E4': 'K',
    'G#4': 'U',
    'A5': 'I',
  },
  'A5': {
    'C4': '.',
    'C#4': '/',
    'E4': 'L',
    'F4': ';',
    'A5': 'O',
    'A#5': 'P',
  },
  'D#3': ' ',
  'E3': ' ',
  'F3': ' ',
  'F#3': 'bs',
  'G3': 'bs'
};

var KeyboardState = function(callback) {
  this.typeKey = callback;
  this.options = KEY_NOTE_MAPPINGS;
};

KeyboardState.prototype.addNote = function(note) {
  if (!(note in this.options)) {
    return;
  }
  this.options = this.options[note];
  console.log('OPTIONS:', this.options);
  if (typeof this.options === 'string') {
    this.typeKey(this.options);
    this.options = KEY_NOTE_MAPPINGS;
    activeColumn = 0;
    activateColumn(activeColumn);
  } else {
    switch (note) {
      case 'F4':
        activeColumn = 1;
        break;
      case 'F#4':
        activeColumn = 2;
        break;
      case 'G4':
        activeColumn = 3;
        break;
      case 'G#4':
        activeColumn = 4;
        break;
      case 'A5':
        activeColumn = 5;
        break;
    }
    activateColumn(activeColumn);
  }
};

var keyboardState = new KeyboardState(playNote);
port.onMessage.addListener(function(msg) {
  console.log('got' + msg.note);
  keyboardState.addNote(msg.note);
});

loadStyle();
loadKeyboard();
$(document).ready(function () {
  $keyboard = $('.kt-keyboard');
  $pitch = $('.kt-active-pitch p');
  $('textarea, input, .tweet-box, [role="textbox"]').focus(function () {
    toggleKeyboard(true);
    $text = $(this);
  }).blur(function () {
    toggleKeyboard(false);
  });
});

function toggleKeyboard(activate) {
  if (!initialized) return;
  active = activate;
  if (activate) {
    $keyboard.addClass('active');
  } else {
    $keyboard.removeClass('active');
  }
}

function activateColumn(column) {
  if (!active) return;
  activeColumn = column;
  if (column == 0) return;
  $('.kt-column').removeClass('active');
  $('.kt-column:eq('+(column-1)+')').addClass('active');
}

function playNote(charTyped) {
  if (!initialized) return;
  if (charTyped === 'bs') {
    $text.html($text.text().slice(0, $text.text().length - 1));
  } else {
    $text.html($text.text() + charTyped);
  }
}

function loadStyle() {
  var link = document.createElement('link');
  link.href = 'https://fonts.googleapis.com/css?family=Roboto';
  link.type = 'text/css';
  link.rel = 'stylesheet';
  document.getElementsByTagName('head')[0].appendChild(link);
}

function loadKeyboard() {
  if (initialized) return;
  initialized = true;

  var $container = document.createElement('div'),
    $activePitch = document.createElement('div'),
    $keyWrap = document.createElement('div'),
    $strings = document.createElement('div'),
    $columns = document.createElement('div'),
    $spacebar = document.createElement('div'),
    $backspace = document.createElement('div');

{'fraction_non_alphanumeric': 0.21818447168709865, 'fraction_numerical': 0.016637478108581436, 'mean_word_length': 2.9704519119351103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6902348', 'n_tokens_mistral': 2609, 'n_tokens_neox': 2596, 'n_words': 489}