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

move everything to src

This commit is contained in:
s2
2017-11-16 09:24:32 +01:00
parent c784e80ece
commit 710fb753b7
9 changed files with 1 additions and 0 deletions

5
src/README.md Normal file
View File

@@ -0,0 +1,5 @@
# pwgen
## What it does ##
Simply generate a password and copy it to the clipboard

BIN
src/icons/lock-32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 473 B

BIN
src/icons/lock-48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 647 B

BIN
src/icons/lock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

24
src/manifest.json Normal file
View File

@@ -0,0 +1,24 @@
{
"description": "Just a toolbar button that generates a password and copies it to your clipboard.",
"manifest_version": 2,
"name": "pwgen reloaded",
"version": "1.1.2",
"homepage_url": "https://github.com/S2-/pwgen",
"icons": {
"48": "icons/lock-48.png"
},
"browser_action": {
"default_icon": "icons/lock-32.png",
"theme_icons": [{
"light": "icons/lock-32-light.png",
"dark": "icons/lock-32.png",
"size": 32
}],
"default_title": "pwgen",
"default_popup": "popup/pwgen.html"
},
"permissions": [
"clipboardWrite",
"storage"
]
}

4
src/popup/pwgen.css Normal file
View File

@@ -0,0 +1,4 @@
body {
cursor: default;
font: caption;
}

33
src/popup/pwgen.html Normal file
View File

@@ -0,0 +1,33 @@
<!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" name="length">
</div>
<div>
<label for"special">include special chars</label>
<input type="checkbox" id="special" checked="checked" name="special">
</div>
<div>
<label for"pw">your password</label>
<input type="text" id="pw" name="pw">
</div>
<div>
<button id="copy">copy to clipboard</button><button id="new">give me an other one</button>
</div>
<div>
<label for"directcopy">direct copy</label>
<input type="checkbox" id="directcopy" name="directcopy" title="next time when i click the button, copy the new password immediately to the clipboard">
</div>
</form>
<script src="pwgen.js"></script>
</body>
</html>

65
src/popup/pwgen.js Normal file
View File

@@ -0,0 +1,65 @@
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,
directcopy: document.getElementById('directcopy').checked
}
}
function loadOptions() {
return browser.storage.local.get({
length: 14,
special: true,
directcopy: false
});
}
function saveOptions(options) {
return browser.storage.local.set(options);
}
function copypasstoclippboard() {
var copyText = document.getElementById('pw');
copyText.select();
document.execCommand('copy');
}
document.getElementById('new').addEventListener('click', (ev) => {
ev.preventDefault();
var params = getParams();
document.getElementById('pw').value = randPassword(params.length, params.special);
});
document.getElementById('copy').addEventListener('click', (ev) => {
ev.preventDefault();
copypasstoclippboard();
});
var list = document.getElementsByTagName('input');
for (var i = 0; i < list.length; i++) {
list[i].addEventListener('change', (ev) => {
saveOptions(getParams());
});
}
loadOptions().then((options) => {
document.getElementById('length').value = options.length;
document.getElementById('special').checked = options.special;
document.getElementById('directcopy').checked = options.directcopy;
document.getElementById('pw').value = randPassword(getParams().length, getParams().special);
if (options.directcopy) {
copypasstoclippboard();
}
});