1
0
mirror of https://github.com/S2-/pwgen.git synced 2025-08-03 09:10:04 +02:00

initial commit

This commit is contained in:
s2
2017-11-15 16:56:03 +01:00
commit c403ca036b
8 changed files with 104 additions and 0 deletions

1
popup/pwgen.css Normal file
View File

@@ -0,0 +1 @@

26
popup/pwgen.html Normal file
View File

@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="pwgen.css"/>
</head>
<body>
<form>
<div>
<label for"length">length</label> <input type="number" id="length" value="14" min="0">
</div>
<div>
<label for"special">include special chars</label> <input type="checkbox" id="special" checked="checked">
</div>
<div>
<label for"pw">your password</label> <input type="text" id="pw">
</div>
<div>
<button id="copy">copy to clipboard</button><button id="new">give me an other one</button>
</div>
</form>
<script src="pwgen.js"></script>
</body>
</html>

48
popup/pwgen.js Normal file
View File

@@ -0,0 +1,48 @@
function randPassword(length, includeSpecial) {
let pwdChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
if (includeSpecial) {
pwdChars += '°^!"§$%&/()=?`´\}][{²³€|<>-.,;:*+_';
}
let randPassword = Array(length).fill(pwdChars).map(function(x) {
return x[Math.floor(Math.random() * x.length)]
}).join('');
return randPassword;
}
function getParams() {
return {
length: parseInt(document.getElementById('length').value),
special: document.getElementById('special').checked
}
}
function loadOptions() {
return browser.storage.local.get({
length: 14,
special: true
});
}
function saveOptions(options) {
return browser.storage.local.set(options);
}
document.getElementById('new').addEventListener('click', (ev) => {
ev.preventDefault();
var params = getParams();
document.getElementById('pw').value = randPassword(params.length, params.special);
saveOptions(params);
});
document.getElementById('copy').addEventListener('click', (ev) => {
ev.preventDefault();
var copyText = document.getElementById('pw');
copyText.select();
document.execCommand('copy');
});
loadOptions().then((options) => {
document.getElementById('length').value = options.length;
document.getElementById('special').checked = options.special;
document.getElementById('pw').value = randPassword(getParams().length, getParams().special);
});