Skip to content

Instantly share code, notes, and snippets.

@bathtimefish
Last active December 1, 2018 09:25
Show Gist options
  • Save bathtimefish/c405c22c9eebb5fb1f534b8ba59fcea9 to your computer and use it in GitHub Desktop.
Save bathtimefish/c405c22c9eebb5fb1f534b8ba59fcea9 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF8">
<title>Send mail when webpage opened</title>
</head>
<body>
<script>
window.onload = function() {
var event_name = 'webpage_opened';
var webhook_key = '[webhook key]';
var webhook_url = 'https://maker.ifttt.com/trigger/' + event_name + '/with/key/' + webhook_key;
var json = JSON.stringify({"value1":"a","value2":"b","value3":"c"});
console.info('Try to request to webhook...', json);
var options = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: json
};
fetch(webhook_url, options).then(function(res) {
return res.text();
}).then(function(text) {
console.log('SUCCESS:', text);
}).catch(function(e) {
console.error('ERROR:', e);
});
// setInterval(function() {
// fetch(webhook_url, options).then(function() {
// console.info('Triggered webhook');
// }).catch(function(e) {
// console.error('ERROR:', e);
// });
// }, 5000);
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment