2017-08-03 12:32:30 -04:00
|
|
|
// Generated by CoffeeScript 1.12.4
|
|
|
|
(function() {
|
|
|
|
var createSecret, dataNotFound, hashLoad, initBinds, newSecret, secretCreated, securePassword, showData, somethingWrong;
|
|
|
|
|
|
|
|
securePassword = null;
|
|
|
|
|
|
|
|
createSecret = function() {
|
|
|
|
var secret;
|
|
|
|
secret = $('#formCreateSecret').find('textarea').val();
|
|
|
|
if ($('#extra').prop('checked')) {
|
|
|
|
securePassword = Math.random().toString(36).substring(2);
|
|
|
|
secret = GibberishAES.enc(secret, securePassword);
|
|
|
|
}
|
|
|
|
$.ajax('api/create', {
|
|
|
|
data: {
|
|
|
|
secret: secret
|
|
|
|
},
|
|
|
|
dataType: "json",
|
|
|
|
statusCode: {
|
|
|
|
201: secretCreated,
|
|
|
|
400: somethingWrong,
|
|
|
|
500: somethingWrong,
|
|
|
|
404: function() {
|
|
|
|
return secretCreated({
|
|
|
|
secret_id: 'foobar'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
dataNotFound = function() {
|
|
|
|
return $('#notfound').show();
|
|
|
|
};
|
|
|
|
|
|
|
|
hashLoad = function() {
|
|
|
|
var hash, id, parts;
|
|
|
|
hash = window.location.hash;
|
|
|
|
if (hash.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-03 15:43:37 -04:00
|
|
|
hash = decodeURIComponent(hash);
|
2017-08-03 12:32:30 -04:00
|
|
|
parts = hash.split('|');
|
|
|
|
if (parts.length === 2) {
|
|
|
|
hash = parts[0];
|
|
|
|
securePassword = parts[1];
|
|
|
|
}
|
|
|
|
id = hash.substring(1);
|
|
|
|
return $.ajax("api/get/" + id, {
|
|
|
|
dataType: "json",
|
|
|
|
statusCode: {
|
|
|
|
404: dataNotFound,
|
|
|
|
200: showData
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
initBinds = function() {
|
|
|
|
$('#formCreateSecret').bind('submit', createSecret);
|
2017-08-03 14:01:22 -04:00
|
|
|
$('#newSecret, .navbar-brand').bind('click', newSecret);
|
2017-08-03 13:44:13 -04:00
|
|
|
return $(window).bind('hashchange', hashLoad);
|
2017-08-03 12:32:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
newSecret = function() {
|
|
|
|
location.href = location.href.split('#')[0];
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
secretCreated = function(data) {
|
|
|
|
var secretHash, url;
|
|
|
|
secretHash = data.secret_id;
|
|
|
|
if (securePassword !== null) {
|
|
|
|
secretHash = secretHash + "|" + securePassword;
|
|
|
|
}
|
|
|
|
url = (location.href.split('#')[0]) + "#" + secretHash;
|
|
|
|
$('#panelNewSecret').hide();
|
|
|
|
$('#panelSecretURL').show();
|
|
|
|
$('#panelSecretURL').find('input').val(url);
|
|
|
|
$('#panelSecretURL').find('input').focus();
|
2017-08-03 14:01:22 -04:00
|
|
|
$('#panelSecretURL').find('input').select();
|
|
|
|
return securePassword = null;
|
2017-08-03 12:32:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
showData = function(data) {
|
|
|
|
var secret;
|
|
|
|
secret = data.secret;
|
|
|
|
if (securePassword !== null) {
|
|
|
|
secret = GibberishAES.dec(secret, securePassword);
|
|
|
|
}
|
|
|
|
$('#panelNewSecret').hide();
|
2017-08-03 13:44:13 -04:00
|
|
|
$('#panelSecretURL').hide();
|
2017-08-03 14:01:22 -04:00
|
|
|
$('#notfound').hide();
|
|
|
|
$('#somethingwrong').hide();
|
2017-08-03 12:32:30 -04:00
|
|
|
$('#panelReadSecret').show();
|
|
|
|
return $('#panelReadSecret').find('textarea').val(secret);
|
|
|
|
};
|
|
|
|
|
|
|
|
somethingWrong = function() {
|
|
|
|
return $('#somethingwrong').show();
|
|
|
|
};
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
initBinds();
|
|
|
|
return hashLoad();
|
|
|
|
});
|
|
|
|
|
|
|
|
}).call(this);
|