roles-bot/packages/website/public/script.js

68 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-01-02 19:02:40 +01:00
const json = {
roles: []
};
2021-12-22 18:40:46 +01:00
$('input').change((e) => {
2022-01-02 19:02:40 +01:00
json[e.currentTarget.id] = e.currentTarget.value;
2021-12-22 18:40:46 +01:00
2022-01-02 19:02:40 +01:00
document.getElementById('json').innerHTML = hljs.highlight(JSON.stringify(json), { language: 'json' }).value;
});
2021-12-22 18:40:46 +01:00
$('button[id=addRole]').click((e) => {
2022-01-02 19:02:40 +01:00
Swal.fire({
title: 'Add Role',
html:
2021-12-22 18:40:46 +01:00
'<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" />',
2022-01-02 19:02:40 +01:00
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-22 18:40:46 +01:00
2022-01-02 19:02:40 +01:00
document.getElementById('json').innerHTML = hljs.highlight(JSON.stringify(json), { language: 'json' }).value;
} else Swal.fire('Missing parameters');
}).catch(swal.noop);
});
2021-12-22 18:40:46 +01:00
$('pre[id=jsonPre].copy').click((e) => {
2022-01-02 19:02:40 +01:00
navigator.clipboard.writeText(e?.currentTarget?.textContent || e.textContent);
2021-12-22 18:40:46 +01:00
2022-01-02 19:02:40 +01:00
Swal.fire({
position: 'top-end',
icon: 'success',
title: 'Copied!',
showConfirmButton: false,
timer: 1500
});
});
2021-12-22 18:40:46 +01:00
$('button[id=buttonCopy]').click((e) => {
2022-01-02 19:02:40 +01:00
const element = $('pre[id=jsonPre].copy')[0];
navigator.clipboard.writeText(element?.currentTarget?.textContent || element.textContent);
2021-12-22 18:40:46 +01:00
2022-01-02 19:02:40 +01:00
Swal.fire({
position: 'top-end',
icon: 'success',
title: 'Copied!',
showConfirmButton: false,
timer: 1500
});
});
2021-12-22 18:40:46 +01:00
$(window).on('load', () => {
2022-01-02 19:02:40 +01:00
$('input').toArray().forEach((i) => i.value = '');
document.getElementById('json').innerHTML = hljs.highlight(JSON.stringify(json), { language: 'json' }).value;
});