diff --git a/discordwebhookmanager/index.html b/discordwebhookmanager/index.html index 9f2a4d3..d6eef42 100644 --- a/discordwebhookmanager/index.html +++ b/discordwebhookmanager/index.html @@ -54,7 +54,14 @@ }, methods: { sendMessage: async function(webhook, message) { - if (!webhook.url || !webhook.name || !message) return; + if (!webhook.url || !webhook.name) { + alert('Invalid webhook does not have url or name property'); + return; + } + if (!message) { + alert('Message is required'); + return + } const res = await fetch(webhook.url, { method: 'POST', @@ -66,7 +73,10 @@ }) }); - console.log(await res.text()); + if (res.status !== 200) { + alert(`Request failed with status code ${res.status} and content "${await res.text()}" (POST ${webhook.url})`); + return; + } }, createWebhook: function() { const name = prompt('Webhook name'); @@ -78,14 +88,19 @@ this.webhooks.push({ name, url }); this.saveToLocalstorage(); + alert(`Webhook "${name}" successfully created`); }, deleteWebhookByIndex: function(index) { this.webhooks.splice(index, 1); }, deleteCurrentWebhook: function() { - this.selectedWebhook = -1; - this.deleteWebhookByIndex(this.selectedWebhook); - this.saveToLocalstorage(); + const yn = confirm(`Delete webhook ${this.selectedWebhookObject.name}?`); + if (yn) { + this.selectedWebhook = -1; + this.deleteWebhookByIndex(this.selectedWebhook); + this.saveToLocalstorage(); + alert(`Webhook successfully deleted`); + } }, saveToLocalstorage: function() { localStorage.setItem('webhooks', JSON.stringify(this.webhooks)); @@ -99,14 +114,14 @@ try { const webhooksJSON = JSON.parse(savedWebhooks); if (!webhooksJSON) { - console.error('Parsing localstorage data returned undefined, clearing localstorage...', e); + alert('Parsing localstorage data returned undefined, clearing localstorage...', e); this.webhooks = []; localStorage.clear(); return; } this.webhooks = webhooksJSON; } catch(e) { - console.error('Error while parsing saved localstorage data, clearing localstorage...', e); + alert('Error while parsing saved localstorage data, clearing localstorage...', e); this.webhooks = []; localStorage.clear(); return;