Skip to content

Instantly share code, notes, and snippets.

Created February 10, 2018 00:37
Show Gist options
  • Save anonymous/837e1d23343445cb59b9f5e2f0687ad3 to your computer and use it in GitHub Desktop.
Save anonymous/837e1d23343445cb59b9f5e2f0687ad3 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/lefenejeko
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<title>JS Bin</title>
</head>
<body style="margin:20px">
<div class="form-group row">
<label for="webhookurl" class="col-sm-2 col-form-label">Webhook URL</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="webhookurl" placeholder="Webhook URL">
</div>
</div>
<div class="form-group row">
<label for="username" class="col-sm-2 col-form-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="username" placeholder="Username">
</div>
</div>
<div class="form-group row">
<label for="avatarurl" class="col-sm-2 col-form-label">Avatar URL</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="avatarurl" placeholder="Avatar URL">
</div>
</div>
<div class="form-group row">
<label for="thumbnail" class="col-sm-2 col-form-label">Thumbnail</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="thumbnail" placeholder="Thumbnail">
</div>
</div>
<div class="form-group row">
<label for="title" class="col-sm-2 col-form-label">Title</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="title" placeholder="Title">
</div>
</div>
<div class="form-group row">
<label for="description" class="col-sm-2 col-form-label">Description</label>
<div class="col-sm-10">
<textarea class="form-control" rows="5" id="description" placeholder="Description"></textarea>
</div>
</div>
<div class="well"><p><b>Fields</b></p>
<div id="fields">
<div class="well">
<div class="form-group row">
<label for="" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" placeholder="">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Value</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="value" placeholder="">
</div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10">
<button type="submit" id="newfield" class="btn btn-primary">New Field</button>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10">
<button type="submit" id="send" class="btn btn-primary">Send</button>
</div>
</div>
<div style="display:none">
<div class="well" id="copy">
<div class="form-group row">
<label for="" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" placeholder="">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Value</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="value" placeholder="">
</div>
</div>
</div>
</div>
<script id="jsbin-javascript">
$("#newfield").click(function() {
$("#copy").clone().removeAttr("id").appendTo("#fields");
});
$("#send").click(function() {
var webhook = $('#webhookurl').val();
var username = $('#username').val();
var avatarurl = $('#avatarurl').val();
var thumbnail = $('#thumbnail').val();
var title = $('#title').val();
var description = $('#description').val();
var fieldsnumber = $('#fields > div').length;
var fields = [];
$('#fields').children().each(function () {
var name = $(this).children().find('#name').val();
var value = $(this).children().find('#value').val();
fields.push({name:name, value:value});
});
var send = {
username: username,
avatar_url: avatarurl,
embeds: [{
title: title,
description:description,
fields:fields,
}],
thumbnail:{url:thumbnail},
};
var settings = {
"async": true,
"crossDomain": true,
"url": webhook,
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"data": JSON.stringify(send)
}
console.log(send);
$.ajax(settings).done(function (response) {
console.log(response);
});
});
</script>
<script id="jsbin-source-javascript" type="text/javascript">$("#newfield").click(function() {
$("#copy").clone().removeAttr("id").appendTo("#fields");
});
$("#send").click(function() {
var webhook = $('#webhookurl').val();
var username = $('#username').val();
var avatarurl = $('#avatarurl').val();
var thumbnail = $('#thumbnail').val();
var title = $('#title').val();
var description = $('#description').val();
var fieldsnumber = $('#fields > div').length;
var fields = [];
$('#fields').children().each(function () {
var name = $(this).children().find('#name').val();
var value = $(this).children().find('#value').val();
fields.push({name:name, value:value});
});
var send = {
username: username,
avatar_url: avatarurl,
embeds: [{
title: title,
description:description,
fields:fields,
}],
thumbnail:{url:thumbnail},
};
var settings = {
"async": true,
"crossDomain": true,
"url": webhook,
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"data": JSON.stringify(send)
}
console.log(send);
$.ajax(settings).done(function (response) {
console.log(response);
});
});</script></body>
</html>
$("#newfield").click(function() {
$("#copy").clone().removeAttr("id").appendTo("#fields");
});
$("#send").click(function() {
var webhook = $('#webhookurl').val();
var username = $('#username').val();
var avatarurl = $('#avatarurl').val();
var thumbnail = $('#thumbnail').val();
var title = $('#title').val();
var description = $('#description').val();
var fieldsnumber = $('#fields > div').length;
var fields = [];
$('#fields').children().each(function () {
var name = $(this).children().find('#name').val();
var value = $(this).children().find('#value').val();
fields.push({name:name, value:value});
});
var send = {
username: username,
avatar_url: avatarurl,
embeds: [{
title: title,
description:description,
fields:fields,
}],
thumbnail:{url:thumbnail},
};
var settings = {
"async": true,
"crossDomain": true,
"url": webhook,
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"data": JSON.stringify(send)
}
console.log(send);
$.ajax(settings).done(function (response) {
console.log(response);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment