Skip to content

Commit

Permalink
store key data in hash
Browse files Browse the repository at this point in the history
  • Loading branch information
ervanalb committed Jun 24, 2017
1 parent 9990bce commit d9313f7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion web/js/keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function populate_types() {
if(key_metadata.length > 0) {
$("#key_type").val(key_metadata[0].filename);
populate_outlines_wardings();
handle_hash();
}
});
}
Expand Down Expand Up @@ -54,6 +55,9 @@ function generate_key() {
"bitting": $("#key_bitting").val(),
});

var encoded = btoa([$("#key_type").val(), $("#key_outline").val(), $("#key_warding").val(), $("#key_bitting").val()].join("|"));
window.location.href = "#" + encoded;

var xhr = new XMLHttpRequest();
xhr.open("GET", keygen_endpoint + "?" + get_data, true);
xhr.responseType = "arraybuffer";
Expand Down Expand Up @@ -90,6 +94,23 @@ function handle_hash() {
$("#about").hide();
$("#generator").show();
$("#about_link").show();


$("#key_type").val(), $("#key_outline").val(), $("#key_warding").val(), $("#key_bitting").val()
var decoded = atob(window.location.hash.substr(1)).split("|");
if(decoded.length == 4) {
if($("#key_type").val() != decoded[0]
|| $("#key_outline").val() != decoded[1]
|| $("#key_warding").val() != decoded[2]
|| $("#key_bitting").val() != decoded[3]) {
$("#key_type").val(decoded[0]);
populate_outlines_wardings();
$("#key_outline").val(decoded[1]);
$("#key_warding").val(decoded[2]);
$("#key_bitting").val(decoded[3]);
generate_key();
}
}
}
}

Expand All @@ -100,5 +121,4 @@ $(document).ready(function() {

populate_types();
preview_init();
handle_hash();
});

0 comments on commit d9313f7

Please sign in to comment.