<commit_before>var Util = (function (Util) {
    var intervalId = null;

    var handleKeypress = function (keypress) {

        if (keypress.which == 0) {
            return;
        }

        keypress.preventDefault();
        if (intervalId) {
            clearTimeout(intervalId);
        }

        var passwordField = keypress.target,
            hiddenPassword = document.getElementById(passwordField.id + '_secret'),
            caretPosition = passwordField.selectionStart,
            selectionSize = passwordField.selectionEnd - passwordField.selectionStart,
            character = String.fromCharCode(keypress.which);

        hiddenPassword.value = replaceCharacters(hiddenPassword.value, caretPosition, selectionSize, character);
        passwordField.value = replaceCharacters(generateStars(hiddenPassword), caretPosition, 1, character);
        passwordField.setSelectionRange(caretPosition + 1, caretPosition + 1);

        intervalId = setTimeout(function () {
            var caretStart = passwordField.selectionStart,
                caretEnd = passwordField.selectionEnd;
            passwordField.value = generateStars(hiddenPassword);
            passwordField.setSelectionRange(caretStart, caretEnd);
            intervalId = null;
        }, 1000);
    };

    var ignoreCharacter = function(charCode) {
        return charCode == 0;
    };

    var handleKeydown = function (keydown) {

        if (keydown.which == 8 || keydown.which == 46) {
            keydown.preventDefault();
            if (intervalId) {
                clearTimeout(intervalId);
            }
            var passwordField = keydown.target,
                hiddenPassword = document.getElementById(passwordField.id + '_secret'),
                selectionSize = passwordField.selectionEnd - passwordField.selectionStart,
                caretPosition = passwordField.selectionStart;

            // Delete highlighted or single character
            if (selectionSize != 0) {
                hiddenPassword.value = deleteSelection(hiddenPassword.value, caretPosition, selectionSize);
            } else if (keydown.which == 46) {
                hiddenPassword.value = deleteNextCharacter(hiddenPassword.value, caretPosition);
            } else {
                hiddenPassword.value = deletePreviousCharacter(hiddenPassword.value, caretPosition);
                caretPosition--;
            }
            passwordField.value = generateStars(hiddenPassword);
            passwordField.setSelectionRange(caretPosition, caretPosition);
        }
    };

    var deletePreviousCharacter = function (string, place) {

        if (place == 0) {
            return string;
        } else {
            return replaceCharacters(string, place - 1, 1, '');
        }
    };

    var deleteNextCharacter = function (string, place) {
        return replaceCharacters(string, place, 1, '');
    };

    var deleteSelection = function (string, place, length) {
        return replaceCharacters(string, place, length, '');
    };

    var replaceCharacters = function (string, place, length, replacement) {
        return string.slice(0, place) + replacement + string.slice(place + length);
    };

    var generateStars = function (field) {
        return Array(field.value.length + 1).join("*");
    };

    var libSupported = function (field) {
        if (typeof window.matchMedia !== "function") {
            return false;
        }

        if (typeof field.setSelectionRange !== 'function') {
            return false;
        }

        return true;
    };

    Util.createHint = function (field) {

        if (!libSupported(field)) {
            return;
        }

        var isMobile = window.matchMedia("only screen and (max-width: 760px)");

        if (isMobile.matches) {
            return;
        }

        passwordField = field;

        hiddenPassword = passwordField.cloneNode(true);
        hiddenPassword.id = passwordField.id + '_secret';
        hiddenPassword.className += ' hide';
        passwordField.type = 'text';

        passwordField.parentNode.appendChild(hiddenPassword);

        passwordField.onkeypress = handleKeypress;
        passwordField.onkeydown = handleKeydown;
    };

    return Util;
})(Util || {});<commit_msg>Changed from a module pattern to prototype pattern.<commit_after>var PasswordHint = function(field, options) {
  this.passwordField = field;
  this.hiddenPassword = field.cloneNode(true);
  this.intervalId = null;

  this.obscureCharacter = options && options.hasOwnProperty('obscureCharacter') ? options.obscureCharacter : '\u25CF';
  this.delay = options && options.hasOwnProperty('delay') ? options.delay : 1000;
};

PasswordHint.prototype.replaceCharacters = function (string, place, length, replacement) {
  return string.slice(0, place) + replacement + string.slice(place + length);
};

PasswordHint.prototype.deletePreviousCharacter = function (string, place) {
  return (place == 0) ? string : this.replaceCharacters(string, place - 1, 1, '');
};

PasswordHint.prototype.deleteNextCharacter = function (string, place) {
  return this.replaceCharacters(string, place, 1, '');
};

PasswordHint.prototype.deleteSelection = function (string, place, length) {
  return this.replaceCharacters(string, place, length, '');
};

PasswordHint.prototype.generateStars = function (string) {
  return Array(string.length + 1).join(this.obscureCharacter);
};

PasswordHint.prototype.islibSupported = function () {
  return typeof window.matchMedia === 'function' && typeof this.passwordField.setSelectionRange === 'function';
};

PasswordHint.prototype.isMobileDevice = function () {
  return window.matchMedia('only screen and (max-width: 760px)').matches;
};

PasswordHint.prototype.hidePassword = function() {
  var start = this.passwordField.selectionStart,
      end = this.passwordField.selectionEnd;

  this.passwordField.value = this.generateStars(this.hiddenPassword.value);
  this.passwordField.setSelectionRange(start, end);
  this.intervalId = null;
};

PasswordHint.prototype.ignoreCharacter = function(charCode) {
  return charCode == 0;
};

PasswordHint.prototype.handleKeypress = function (keypress) {

  if (keypress.which == 0) {
    return;
  }

  keypress.preventDefault();
  if (this.intervalId) {
    clearTimeout(this.intervalId);
  }

  var caretPosition = this.passwordField.selectionStart,
      selectionSize = this.passwordField.selectionEnd - this.passwordField.selectionStart,
      character = String.fromCharCode(keypress.which);

  this.hiddenPassword.value = this.replaceCharacters(this.hiddenPassword.value, caretPosition, selectionSize, character);
  this.passwordField.value = this.replaceCharacters(this.generateStars(this.hiddenPassword.value), caretPosition, 1, character);
  this.passwordField.setSelectionRange(caretPosition + 1, caretPosition + 1);

  this.intervalId = setTimeout(this.hidePassword.bind(this), this.delay);
};

PasswordHint.prototype.handleKeydown = function (keydown) {

  if (keydown.which == 8 || keydown.which == 46) {
    keydown.preventDefault();
    if (this.intervalId) {
      clearTimeout(this.intervalId);
    }

    var selectionSize = this.passwordField.selectionEnd - this.passwordField.selectionStart,
        caretPosition = this.passwordField.selectionStart;

    // Delete highlighted or single character
    if (selectionSize != 0) {
      this.hiddenPassword.value = this.deleteSelection(this.hiddenPassword.value, caretPosition, selectionSize);
    } else if (keydown.which == 46) {
      this.hiddenPassword.value = this.deleteNextCharacter(this.hiddenPassword.value, caretPosition);
    } else {
      this.hiddenPassword.value = this.deletePreviousCharacter(this.hiddenPassword.value, caretPosition);
      caretPosition--;
    }
    this.passwordField.value = this.generateStars(this.hiddenPassword.value);
    this.passwordField.setSelectionRange(caretPosition, caretPosition);
  }
};

PasswordHint.prototype.startHinting = function () {
  if (!this.islibSupported() || this.isMobileDevice()) {
      return;
  }

  this.hiddenPassword.id = this.passwordField.id + '_secret';
  this.hiddenPassword.className += ' hide';
  this.passwordField.type = 'text';

  this.passwordField.parentNode.appendChild(this.hiddenPassword);

  this.passwordField.onkeypress = this.handleKeypress.bind(this);;
  this.passwordField.onkeydown = this.handleKeydown.bind(this);;
};
{'fraction_non_alphanumeric': 0.11166726254320104, 'fraction_numerical': 0.0059587653438207605, 'mean_word_length': 3.2002002002002, 'pattern_counts': {'":': 0, '<': 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': '714312', 'n_tokens_mistral': 2289, 'n_tokens_neox': 2185, 'n_words': 435}