You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paste/public/main.js

72 lines
1.8 KiB
JavaScript

4 years ago
$(() => {
if (localStorage.getItem('expire-value') !== null) $('input#expire').val(localStorage.getItem('expire-value'));
if (localStorage.getItem('expire-multiplier') !== null) $('#multiplier').val(localStorage.getItem('expire-multiplier'));
$.fn.selectpicker.Constructor.BootstrapVersion = '4';
autosize($('textarea'));
$('select#highlight').removeClass('custom-select');
$('input#expire').removeClass('mr-3');
$('select#highlight').selectpicker();
$('input#expire').TouchSpin({
min: 1,
max: 999,
buttondown_class: 'btn text-dark border-gray',
buttonup_class: 'btn text-dark border-gray'
});
$('textarea').on('keydown', function(e) {
4 years ago
if ((e.keyCode === 10 || e.keyCode === 13) && e.ctrlKey && $(this).val()) {
$(this).closest('form').submit();
}
});
4 years ago
$('input#expire').on('change', (e) => {
var value = $(e.target).val();
4 years ago
$('#multiplier option').text((_, t) => {
var plural = t.slice(Math.max(0, t.length - 1)) === 's';
if (value > 1) {
if (!plural) {
return t + 's';
}
4 years ago
} else if (plural) {
return t.slice(0, -1);
}
return t;
});
localStorage.setItem('expire-value', value);
});
4 years ago
$('#multiplier').on('change', (e) => {
localStorage.setItem('expire-multiplier', $(e.target).val());
});
$('select#highlight').on('change', function() {
4 years ago
if ($(this).val() === '') {
history.pushState({}, '', '/');
} else {
location.hash = $(this).val();
}
});
4 years ago
$(window).on('hashchange', () => {
var value = location.hash.slice(1);
4 years ago
if (value && $('select#highlight option[value=' + value + ']').length > 0) {
4 years ago
$('select#highlight').selectpicker('val', value);
} else {
4 years ago
$('select#highlight').selectpicker('val', '');
}
});
$(window).trigger('hashchange');
$('input#expire').trigger('change');
});