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

71 lines
2.2 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-04-10 21:09:37 +02:00
json[e.currentTarget.id] = e.currentTarget.value.replaceAll('\\n', '\n');
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 />' +
2022-04-08 18:10:35 +02:00
'<input id="swal-input3" class="swal2-input" placeholder="Emoji" />' +
'<select id="swal-input4" class="swal2-input" style="display: flex;"><option value="" disabled="">Select a style</option><option value="1">Primary</option><option value="2">Secondary</option><option value="3">Success</option><option value="4">Danger</option></select>',
2022-01-02 19:02:40 +01:00
preConfirm: function () {
return new Promise(function (resolve) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val(),
2022-04-08 18:10:35 +02:00
$('#swal-input3').val(),
$('#swal-input4').val()
2022-01-02 19:02:40 +01:00
]);
});
}
}).then(function (result) {
if (result.value?.[0] && result.value?.[1]) {
json.roles.push({
id: result.value[1],
label: result.value[0],
2022-04-08 18:10:35 +02:00
emoji: result.value[2] || null,
style: parseInt(result.value[3]) || 2
2022-01-02 19:02:40 +01:00
});
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;
});