mirror of
https://github.com/S2-/pwgen.git
synced 2025-08-04 01:30:04 +02:00
direct copy
This commit is contained in:
@@ -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