Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (61 sloc) 2.34 KB
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<?!= include('styles'); ?>
</head>
<body>
<form id="showPasswordForm">
<table>
<tr>
<td>Shared Secret:</td>
<td><input type='password' name='sharedsecret' id='sharedsecret'></td>
</tr>
<tr>
<td>Decrypted password:</td>
<td><input type='text' name='password' id='password'></td>
</tr>
<tr>
<td><input type="button" value="Decrypt" name="submit" id="submitButton" onclick="submitForm()"/></td>
<td><input type="button" value="Copy password" name="copy" id="copyButton" onclick="copyPassword()" /></td>
</tr>
</table>
</form>
<span id='errorMsg'></span>
<script src='https://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.7/sjcl.min.js'></script>
<script>
function submitForm() {
document.getElementById('errorMsg').innerHTML = ''
document.getElementById('submitButton').value = "Decrypting...";
console.log('running...');
google.script.run.withSuccessHandler(function(password){
console.log('success');
sharedsecret = document.getElementById('sharedsecret').value
decryptedPassword = sjcl.decrypt(sharedsecret, password)
document.getElementById('password').value = decryptedPassword;
document.getElementById('submitButton').value = "Done";
}).withFailureHandler(function(error){
console.log('error');
document.getElementById('submitButton').value = "Failed";
document.getElementById('errorMsg').innerHTML = error;
}).getPassword();
}
function copyPassword() {
document.getElementById('copyButton').value = "Copying...";
password = document.getElementById('password').value
var textArea = document.getElementById('password');
textArea.select();
try {
var successful = document.execCommand( 'copy' );
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
document.getElementById('copyButton').value = "Copied to clipboard!";
} catch (err) {
console.log('Oops, unable to copy');
document.getElementById('copyButton').value = "Copy failed!";
document.getElementById('errorMsg').innerHTML = error;
}
}
</script>
</body>
</html>