2020-10-13 21:52:02 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>hippoz</title>
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="https://hippoz.xyz/res/style.css">
|
|
|
|
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="app">
|
|
|
|
<div class="card navigation-card">
|
|
|
|
<div class="navigation-buttons">
|
2020-10-13 22:10:01 +03:00
|
|
|
<a v-for="(webhook, webhookIndex) in webhooks" @click="selectedWebhook = webhookIndex" :class="getWebhookButtonClass(webhookIndex)">{{ webhook.name }}</a>
|
2020-10-13 21:52:02 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="card" id="content-container">
|
|
|
|
<h2>Selected webhook: {{ selectedWebhookObject.name }}</h2>
|
|
|
|
<p>i think</p>
|
|
|
|
<br>
|
|
|
|
<div id="contols" v-if="selectedWebhookObject.url && selectedWebhookObject.name">
|
2020-10-13 22:39:38 +03:00
|
|
|
<input class="input" placeholder="message" type="text" v-model="message" v-on:keyup.enter="sendMessage(selectedWebhookObject, message)"> </br>
|
2020-10-13 21:52:02 +03:00
|
|
|
<button class="button-default button-selected" @click="sendMessage(selectedWebhookObject, message)">Send</button>
|
|
|
|
<br>
|
|
|
|
<button class="button-default button-selected" @click="deleteCurrentWebhook()">Delete</button>
|
|
|
|
</div>
|
|
|
|
<br>
|
|
|
|
<div>
|
|
|
|
<button class="button-default button-selected" @click="createWebhook()">New webhook</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
const app = new Vue({
|
|
|
|
el: '#app',
|
|
|
|
data: {
|
|
|
|
webhooks: [
|
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
url: 'https://discordapp.com/api/webhooks/765640620327829525/Qe9525MFu14-K_t7Fq3PitanumcF-gLf_NZ9ncG0RD2yPye9JEkuC3L7vkDqxRtvvQMD'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
selectedWebhook: -1,
|
|
|
|
message: ''
|
|
|
|
},
|
|
|
|
mounted: function() {
|
|
|
|
this.loadFromLocalstorage();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
sendMessage: async function(webhook, message) {
|
2020-10-13 22:17:09 +03:00
|
|
|
if (!webhook.url || !webhook.name) {
|
|
|
|
alert('Invalid webhook does not have url or name property');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!message) {
|
|
|
|
alert('Message is required');
|
|
|
|
return
|
|
|
|
}
|
2020-10-13 21:52:02 +03:00
|
|
|
|
|
|
|
const res = await fetch(webhook.url, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
content: message
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2020-10-13 22:20:05 +03:00
|
|
|
if (res.status !== 204) {
|
2020-10-13 22:17:09 +03:00
|
|
|
alert(`Request failed with status code ${res.status} and content "${await res.text()}" (POST ${webhook.url})`);
|
|
|
|
return;
|
|
|
|
}
|
2020-10-13 21:52:02 +03:00
|
|
|
},
|
|
|
|
createWebhook: function() {
|
|
|
|
const name = prompt('Webhook name');
|
|
|
|
const url = prompt('Webhook url');
|
|
|
|
if (!url || !name || url === '' || name === '') {
|
|
|
|
alert('Invalid input');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.webhooks.push({ name, url });
|
|
|
|
this.saveToLocalstorage();
|
2020-10-13 22:17:09 +03:00
|
|
|
alert(`Webhook "${name}" successfully created`);
|
2020-10-13 21:52:02 +03:00
|
|
|
},
|
|
|
|
deleteWebhookByIndex: function(index) {
|
|
|
|
this.webhooks.splice(index, 1);
|
|
|
|
},
|
|
|
|
deleteCurrentWebhook: function() {
|
2020-10-13 22:17:09 +03:00
|
|
|
const yn = confirm(`Delete webhook ${this.selectedWebhookObject.name}?`);
|
|
|
|
if (yn) {
|
|
|
|
this.deleteWebhookByIndex(this.selectedWebhook);
|
2020-10-14 16:00:00 +03:00
|
|
|
this.selectedWebhook = -1;
|
2020-10-13 22:17:09 +03:00
|
|
|
this.saveToLocalstorage();
|
|
|
|
alert(`Webhook successfully deleted`);
|
|
|
|
}
|
2020-10-13 21:52:02 +03:00
|
|
|
},
|
|
|
|
saveToLocalstorage: function() {
|
|
|
|
localStorage.setItem('webhooks', JSON.stringify(this.webhooks));
|
|
|
|
},
|
|
|
|
loadFromLocalstorage: function() {
|
|
|
|
const savedWebhooks = localStorage.getItem('webhooks');
|
|
|
|
if (!savedWebhooks) {
|
|
|
|
this.webhooks = [];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const webhooksJSON = JSON.parse(savedWebhooks);
|
|
|
|
if (!webhooksJSON) {
|
2020-10-13 22:17:09 +03:00
|
|
|
alert('Parsing localstorage data returned undefined, clearing localstorage...', e);
|
2020-10-13 21:52:02 +03:00
|
|
|
this.webhooks = [];
|
|
|
|
localStorage.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.webhooks = webhooksJSON;
|
|
|
|
} catch(e) {
|
2020-10-13 22:17:09 +03:00
|
|
|
alert('Error while parsing saved localstorage data, clearing localstorage...', e);
|
2020-10-13 21:52:02 +03:00
|
|
|
this.webhooks = [];
|
|
|
|
localStorage.clear();
|
|
|
|
return;
|
|
|
|
}
|
2020-10-13 22:10:01 +03:00
|
|
|
},
|
|
|
|
getWebhookButtonClass: function(webhookIndex) {
|
|
|
|
if (this.selectedWebhook === webhookIndex) {
|
|
|
|
return 'button-default button-selected';
|
|
|
|
}
|
|
|
|
return 'button-default';
|
2020-10-13 21:52:02 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
selectedWebhookObject: function() {
|
|
|
|
return this.webhooks[this.selectedWebhook] || { name: 'none' };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|