mirror of
https://github.com/S2-/pwgen.git
synced 2025-08-02 17:00:03 +02:00
direct copy
This commit is contained in:
@@ -8,17 +8,24 @@
|
||||
<body>
|
||||
<form>
|
||||
<div>
|
||||
<label for"length">length</label> <input type="number" id="length" value="14" min="0">
|
||||
<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">
|
||||
<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">
|
||||
<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>
|
||||
|
@@ -12,14 +12,16 @@ function randPassword(length, includeSpecial) {
|
||||
function getParams() {
|
||||
return {
|
||||
length: parseInt(document.getElementById('length').value),
|
||||
special: document.getElementById('special').checked
|
||||
special: document.getElementById('special').checked,
|
||||
directcopy: document.getElementById('directcopy').checked
|
||||
}
|
||||
}
|
||||
|
||||
function loadOptions() {
|
||||
return browser.storage.local.get({
|
||||
length: 14,
|
||||
special: true
|
||||
special: true,
|
||||
directcopy: false
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,6 +29,12 @@ 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();
|
||||
@@ -36,13 +44,22 @@ document.getElementById('new').addEventListener('click', (ev) => {
|
||||
|
||||
document.getElementById('copy').addEventListener('click', (ev) => {
|
||||
ev.preventDefault();
|
||||
var copyText = document.getElementById('pw');
|
||||
copyText.select();
|
||||
document.execCommand('copy');
|
||||
copypasstoclippboard();
|
||||
});
|
||||
|
||||
document.getElementById('directcopy').addEventListener('change', (ev) => {
|
||||
console.log(getParams());
|
||||
saveOptions(getParams());
|
||||
});
|
||||
|
||||
loadOptions().then((options) => {
|
||||
console.log(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();
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user