<commit_before>var parseUrl = require('url').parse;
var makePassword = require('passwordmaker');

var inputs = {
	domain: document.getElementById('domain'),
	masterPassword: document.getElementById('password-master'),
	generatedPassword: document.getElementById('password-generated')
};

var buttons = {
	copy: document.getElementById('btn-copy'),
	autoFill: document.getElementById('btn-auto-fill'),
	saveMasterPassword: document.getElementById('btn-save-master')
};

var prefs = null;

function loadOptions(done) {
	chrome.storage.sync.get(defaultOptions, function (items) {
		prefs = items;
    done();
	});
}

function initUi() {
  // See https://github.com/emersion/firefox-passwordmaker/issues/1
  var updateTimeout = null;
  var delayedUpdate = function () {
  	if (typeof updateTimeout !== null) {
  		clearTimeout(updateTimeout);
  	}

  	updateTimeout = setTimeout(function () {
  		updateTimeout = null;
  		generatePassword();
  	}, 500);
  };

  var isGeneratedPasswdRevealed = function () {
  	return (inputs.generatedPassword.type == 'text');
  };
  var revealGeneratedPasswd = function () {
  	inputs.generatedPassword.type = 'text';
  	inputs.generatedPassword.select();
  };
  var hideGeneratedPasswd = function () {
  	inputs.generatedPassword.type = 'password';
  };

  // Listen for keyup events
  inputs.domain.addEventListener('keyup', function () {
  	delayedUpdate();
  });
  inputs.masterPassword.addEventListener('keyup', function () {
    buttons.saveMasterPassword.disabled = false;
  	delayedUpdate();
  });

  inputs.generatedPassword.addEventListener('mouseover', function () {
  	if (prefs && prefs.passwordVisibility == 'hover') {
  		revealGeneratedPasswd();
  	}
  });
  inputs.generatedPassword.addEventListener('mouseout', function () {
  	if (prefs && prefs.passwordVisibility == 'hover') {
  		hideGeneratedPasswd();
  	}
  });
  inputs.generatedPassword.addEventListener('focus', function () {
  	if (!inputs.generatedPassword.value.length) {
  		generatePassword();
  	}
  	if (prefs && prefs.passwordVisibility == 'click') {
  		revealGeneratedPasswd();
  	}
  });
  inputs.generatedPassword.addEventListener('blur', function () {
  	if (prefs && prefs.passwordVisibility == 'click') {
  		hideGeneratedPasswd();
  	}
  });
  inputs.generatedPassword.addEventListener('click', function () {
  	if (prefs && prefs.passwordVisibility == 'click' && !isGeneratedPasswdRevealed()) {
  		revealGeneratedPasswd();
  	}
  });

  // Listen for clicks on buttons
  buttons.copy.addEventListener('click', function () {
    inputs.generatedPassword.select();

    var success = false;
    try {
      success = document.execCommand('copy');
    } catch (err) {}

    if (success) {
      window.close();
    }
  });

  buttons.saveMasterPassword.addEventListener('click', function () {
    chrome.storage.local.set({
      masterPassword: inputs.masterPassword.value
    });

    buttons.saveMasterPassword.disabled = true;
  });

  // Auto-fill password
  function autoFillPassword() {
    var password = inputs.generatedPassword.value;

    if (password.length !== 0) {
      password = password.replace('"', '\\"');
      chrome.tabs.executeScript({
        code: 'if (document.activeElement) { document.activeElement.value = "'+password+'"; }'
      });

      window.close();
  	}
  }
  document.addEventListener('keypress', function (event) {
  	if (event.keyCode == 13) { // Enter key
  		event.preventDefault();
  		autoFillPassword();
  	}
  });
  buttons.autoFill.addEventListener('click', function () {
    autoFillPassword();<commit_msg>Fixes autofill with passwords containing multiple special chars<commit_after>var parseUrl = require('url').parse;
var makePassword = require('passwordmaker');

var inputs = {
	domain: document.getElementById('domain'),
	masterPassword: document.getElementById('password-<PASSWORD>'),
	generatedPassword: document.getElementById('password-<PASSWORD>')
};

var buttons = {
	copy: document.getElementById('btn-copy'),
	autoFill: document.getElementById('btn-auto-fill'),
	saveMasterPassword: document.getElementById('btn-save-master')
};

var prefs = null;

function loadOptions(done) {
	chrome.storage.sync.get(defaultOptions, function (items) {
		prefs = items;
    done();
	});
}

function initUi() {
  // See https://github.com/emersion/firefox-passwordmaker/issues/1
  var updateTimeout = null;
  var delayedUpdate = function () {
  	if (typeof updateTimeout !== null) {
  		clearTimeout(updateTimeout);
  	}

  	updateTimeout = setTimeout(function () {
  		updateTimeout = null;
  		generatePassword();
  	}, 500);
  };

  var isGeneratedPasswdRevealed = function () {
  	return (inputs.generatedPassword.type == 'text');
  };
  var revealGeneratedPasswd = function () {
  	inputs.generatedPassword.type = 'text';
  	inputs.generatedPassword.select();
  };
  var hideGeneratedPasswd = function () {
  	inputs.generatedPassword.type = 'password';
  };

  // Listen for keyup events
  inputs.domain.addEventListener('keyup', function () {
  	delayedUpdate();
  });
  inputs.masterPassword.addEventListener('keyup', function () {
    buttons.saveMasterPassword.disabled = false;
  	delayedUpdate();
  });

  inputs.generatedPassword.addEventListener('mouseover', function () {
  	if (prefs && prefs.passwordVisibility == 'hover') {
  		revealGeneratedPasswd();
  	}
  });
  inputs.generatedPassword.addEventListener('mouseout', function () {
  	if (prefs && prefs.passwordVisibility == 'hover') {
  		hideGeneratedPasswd();
  	}
  });
  inputs.generatedPassword.addEventListener('focus', function () {
  	if (!inputs.generatedPassword.value.length) {
  		generatePassword();
  	}
  	if (prefs && prefs.passwordVisibility == 'click') {
  		revealGeneratedPasswd();
  	}
  });
  inputs.generatedPassword.addEventListener('blur', function () {
  	if (prefs && prefs.passwordVisibility == 'click') {
  		hideGeneratedPasswd();
  	}
  });
  inputs.generatedPassword.addEventListener('click', function () {
  	if (prefs && prefs.passwordVisibility == 'click' && !isGeneratedPasswdRevealed()) {
  		revealGeneratedPasswd();
  	}
  });

  // Listen for clicks on buttons
  buttons.copy.addEventListener('click', function () {
    inputs.generatedPassword.select();

    var success = false;
    try {
      success = document.execCommand('copy');
    } catch (err) {}

    if (success) {
      window.close();
    }
  });

  buttons.saveMasterPassword.addEventListener('click', function () {
    chrome.storage.local.set({
      masterPassword: inputs.masterPassword.value
    });

    buttons.saveMasterPassword.disabled = true;
  });

  // Auto-fill password
  function autoFillPassword() {
    var password = inputs.generatedPassword.value;

    if (password.length !== 0) {
      password = password.replace(/"/g, '\\"');
      chrome.tabs.executeScript({
        code: 'if (document.activeElement) { document.activeElement.value = "'+password+'"; }'
      });

      window.close();
  	}
  }
  document.addEventListener('keypress', function (event) {
  	if (event.keyCode == 13) { // Enter key
  		event.preventDefault();
  		autoFillPassword();
  	}
  });
  buttons.autoFill.addEventListener('click', function () {
    autoFillPassword();
{'fraction_non_alphanumeric': 0.1488359201773836, 'fraction_numerical': 0.0019401330376940134, 'mean_word_length': 3.9095238095238094, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6044113', 'n_tokens_mistral': 2149, 'n_tokens_neox': 2100, 'n_words': 366}