Remove alert() after password copy. Replace it by button name update (2 seconds)

This commit is contained in:
Gregory Soutade 2022-06-18 14:31:10 +02:00
parent 42142cbca9
commit 54565f90b6

View File

@ -548,6 +548,7 @@ async function change_master_key(warning_unciphered)
clipboard_button = document.createElement("input"); clipboard_button = document.createElement("input");
clipboard_button.setAttribute("type", "button"); clipboard_button.setAttribute("type", "button");
clipboard_button.setAttribute("name", "copy_button");
clipboard_button.setAttribute("value", "Copy password"); clipboard_button.setAttribute("value", "Copy password");
clipboard_button.setAttribute("onclick", "copy_clipboard(\"unciph_entry_" + i + "\");"); clipboard_button.setAttribute("onclick", "copy_clipboard(\"unciph_entry_" + i + "\");");
div.appendChild(clipboard_button); div.appendChild(clipboard_button);
@ -1015,6 +1016,11 @@ async function update_masterkey()
} }
} }
function reset_copy_button_name(button)
{
button.value = "Copy password";
}
function copy_clipboard(entry_number) function copy_clipboard(entry_number)
{ {
var password = ""; var password = "";
@ -1028,6 +1034,16 @@ function copy_clipboard(entry_number)
inputs = entry.getElementsByTagName("input"); inputs = entry.getElementsByTagName("input");
var button = null;
for(i=0; i<inputs.length; i++)
{
if (inputs[i].getAttribute("name") == "copy_button")
{
button = inputs[i];
break;
}
}
for(i=0; i<inputs.length; i++) for(i=0; i<inputs.length; i++)
{ {
if (inputs[i].getAttribute("name") == "password") if (inputs[i].getAttribute("name") == "password")
@ -1035,6 +1051,12 @@ function copy_clipboard(entry_number)
inputs[i].select(); inputs[i].select();
document.execCommand('copy'); document.execCommand('copy');
inputs[i].setSelectionRange(0,0); // Unselect inputs[i].setSelectionRange(0,0); // Unselect
if (button !== null)
{
button.value = "Copied";
window.setTimeout(reset_copy_button_name.bind(null, button), 2000);
}
else
alert('Password copied into clipboard'); alert('Password copied into clipboard');
break; break;
} }