roles-bot/src/web/app/js/script.js

55 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-12-21 14:12:09 +01:00
let json = {
roles: []
}
$('input').change((e) => {
json[e.currentTarget.id] = e.currentTarget.value;
2021-12-21 14:27:41 +01:00
document.getElementById('json').innerHTML = hljs.highlight(JSON.stringify(json), { language: 'json' }).value;
2021-12-21 14:12:09 +01:00
})
$('button[id=addRole]').click((e) => {
Swal.fire({
title: 'Add Role',
html:
'<input id="swal-input1" class="swal2-input" placeholder="Button Label*" required>' +
'<input id="swal-input2" class="swal2-input" placeholder="Role Id*" required>' +
'<input id="swal-input3" class="swal2-input" placeholder="Emoji">',
preConfirm: function () {
return new Promise(function (resolve) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val(),
$('#swal-input3').val()
])
})
},
}).then(function (result) {
if (result.value?.[0] && result.value?.[1]) {
json.roles.push({
id: result.value[1],
label: result.value[0],
emoji: result.value[2] || null
})
2021-12-21 14:27:41 +01:00
document.getElementById('json').innerHTML = hljs.highlight(JSON.stringify(json), { language: 'json' }).value;
2021-12-21 14:12:09 +01:00
} else Swal.fire('Missing parameters')
}).catch(swal.noop)
})
2021-12-21 16:02:14 +01:00
$('pre[id=jsonPre].copy').click((e) => {
2021-12-21 15:59:51 +01:00
navigator.clipboard.writeText(e?.currentTarget?.textContent || e.textContent);
Swal.fire({
position: 'top-end',
icon: 'success',
title: 'Copied!',
showConfirmButton: false,
timer: 1500
})
})
2021-12-21 14:12:09 +01:00
$(window).on('load', () => {
$('input').toArray().forEach((i) => i.value = '');
2021-12-21 14:27:41 +01:00
document.getElementById('json').innerHTML = hljs.highlight(JSON.stringify(json), { language: 'json' }).value;
2021-12-21 14:12:09 +01:00
})