add option to embed cryptojs into the generated file

pull/13/head
Robin Moisson 2017-06-15 17:48:20 +02:00
rodzic bbf47a1137
commit ff1568ed88
2 zmienionych plików z 46 dodań i 3 usunięć

Wyświetl plik

@ -15,6 +15,10 @@
body { body {
font-size: 16px; font-size: 16px;
} }
label.no-style {
font-weight: normal;
}
</style> </style>
<script> <script>
@ -107,6 +111,14 @@
</div> </div>
</div> </div>
<div class="form-group">
<label class="no-style">
<input type="checkbox" id="embed-crypto" checked>
Embed crypto-js into your file
<abbr title="Leave checked to include crypto-js into your file so you can decrypt it offline. Uncheck to load crypto-js from a CDN.">?</abbr>
</label>
</div>
<button class="btn btn-primary pull-right" type="submit">Generate passphrase protected HTML</button> <button class="btn btn-primary pull-right" type="submit">Generate passphrase protected HTML</button>
</form> </form>
</div> </div>
@ -136,6 +148,10 @@ Your encrypted string</pre>
}); });
}; };
/**
* Fill the password prompt template with data provided.
* @param data
*/
var setFileToDownload = function (data) { var setFileToDownload = function (data) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.open('GET', 'password_template.html', true); request.open('GET', 'password_template.html', true);
@ -151,6 +167,23 @@ Your encrypted string</pre>
request.send(); request.send();
}; };
/**
* Download crypto-js lib to embed it in the generated file, update the file when done.
* @param data
*/
var setFileToDownloadWithEmbeddedCrypto = function (data) {
var request = new XMLHttpRequest();
request.open('GET', 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js', true);
request.onload = function() {
data['crypto_tag'] = '<script>' + request.responseText + '</scr' + 'ipt>';
setFileToDownload(data);
};
request.send();
};
/**
* Handle form submission.
*/
document.getElementById('encrypt_form').addEventListener('submit', function (e) { document.getElementById('encrypt_form').addEventListener('submit', function (e) {
e.preventDefault(); e.preventDefault();
@ -166,12 +199,19 @@ Your encrypted string</pre>
var data = { var data = {
title: pageTitle ? pageTitle : 'Protected Page', title: pageTitle ? pageTitle : 'Protected Page',
instructions: instructions ? instructions : '', instructions: instructions ? instructions : '',
encrypted: encryptedMsg encrypted: encryptedMsg,
crypto_tag: '<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></scr' + 'ipt>'
}; };
document.getElementById('encrypted_html_display').textContent = encryptedMsg; document.getElementById('encrypted_html_display').textContent = encryptedMsg;
if (document.getElementById("embed-crypto").checked) {
setFileToDownloadWithEmbeddedCrypto(data);
}
else {
setFileToDownload(data); setFileToDownload(data);
}
}); });
document.getElementById('toggle-extra-option') document.getElementById('toggle-extra-option')
@ -187,6 +227,9 @@ Your encrypted string</pre>
}); });
/**
* Browser specific download code.
*/
document.getElementById('download-link') document.getElementById('download-link')
.addEventListener('click', function (e) { .addEventListener('click', function (e) {

Wyświetl plik

@ -134,7 +134,7 @@
</footer> </footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script> {crypto_tag}
<script> <script>
document.getElementById('staticrypt-form').addEventListener('submit', function (e) { document.getElementById('staticrypt-form').addEventListener('submit', function (e) {