mirror of
https://github.com/Luzifer/vault-otp-ui.git
synced 2024-11-09 16:50:05 +00:00
93 lines
2.3 KiB
JavaScript
93 lines
2.3 KiB
JavaScript
// Generated by CoffeeScript 1.12.4
|
|
(function() {
|
|
var clipboard, createOTPItem, currentTimeout, delay, fetchCodes, filterChange, initializeApplication, refreshTimerProgress, tick, timeLeft, updateCodes;
|
|
|
|
currentTimeout = 0;
|
|
|
|
clipboard = void 0;
|
|
|
|
$(function() {
|
|
if ($('body').hasClass('state-signedin')) {
|
|
return initializeApplication();
|
|
}
|
|
});
|
|
|
|
createOTPItem = function(item) {
|
|
var otpItem, tpl;
|
|
tpl = $('#otp-item').html();
|
|
otpItem = $(tpl);
|
|
otpItem.find('.badge').text(item.code.replace(/^(.{3})(.{3})$/, '$1 $2'));
|
|
otpItem.find('.title').text(item.name);
|
|
otpItem.find('i.fa').addClass("fa-" + item.icon);
|
|
return otpItem.appendTo($('#keylist'));
|
|
};
|
|
|
|
delay = function(delayMSecs, fkt) {
|
|
return window.setTimeout(fkt, delayMSecs);
|
|
};
|
|
|
|
fetchCodes = function() {
|
|
return $.ajax({
|
|
url: 'codes.json',
|
|
success: updateCodes,
|
|
dataType: 'json'
|
|
});
|
|
};
|
|
|
|
filterChange = function() {
|
|
var filter;
|
|
filter = $('#filter').val().toLowerCase();
|
|
return $('.otp-item').each(function(idx, el) {
|
|
if ($(el).find('.title').text().toLowerCase().match(filter) === null) {
|
|
return $(el).hide();
|
|
} else {
|
|
return $(el).show();
|
|
}
|
|
});
|
|
};
|
|
|
|
initializeApplication = function() {
|
|
$('#keylist').empty();
|
|
$('#filter').bind('keyup', filterChange);
|
|
tick(500, refreshTimerProgress);
|
|
return fetchCodes();
|
|
};
|
|
|
|
refreshTimerProgress = function() {
|
|
var secondsLeft;
|
|
secondsLeft = timeLeft();
|
|
return $('#timer').css('width', (secondsLeft / 30 * 100) + "%");
|
|
};
|
|
|
|
tick = function(delay, fkt) {
|
|
return window.setInterval(fkt, delay);
|
|
};
|
|
|
|
timeLeft = function() {
|
|
var now;
|
|
now = new Date().getTime();
|
|
return (currentTimeout - now) / 1000;
|
|
};
|
|
|
|
updateCodes = function(data) {
|
|
var i, len, ref, token;
|
|
currentTimeout = new Date(data.next_wrap).getTime();
|
|
if (clipboard) {
|
|
clipboard.destroy();
|
|
}
|
|
$('#keylist').empty();
|
|
ref = data.tokens;
|
|
for (i = 0, len = ref.length; i < len; i++) {
|
|
token = ref[i];
|
|
createOTPItem(token);
|
|
}
|
|
clipboard = new Clipboard('.otp-item', {
|
|
text: function(trigger) {
|
|
return $(trigger).find('.badge').text().replace(' ', '');
|
|
}
|
|
});
|
|
filterChange();
|
|
return delay(timeLeft() * 1000, fetchCodes);
|
|
};
|
|
|
|
}).call(this);
|