
When clicked, the message notifying Tonda about the lack of coffee is sent to the Slack. --- templates/hello.html | 1 + templates/main.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/templates/hello.html b/templates/hello.html index 0e709ce..e8f985d 100644 --- a/templates/hello.html +++ b/templates/hello.html @@ -1,5 +1,6 @@ <center> <div id="user"></div> +<p id="pLastCovfefe"><input type="button" value="The last covfefe pack opened!" onclick="tellCoffeebot('Yay, <@U539N17JL|Tonda>, buy me a new covfefe pack! Thanks!')" /></p> <p>Hack me: <tt>https://rtime.felk.cvut.cz/gitweb/coffee/main.git</tt></p> <p>Debug: <span id="log"></span></p> </center> diff --git a/templates/main.js b/templates/main.js index 8135983..3d42820 100644 --- a/templates/main.js +++ b/templates/main.js @@ -205,3 +205,21 @@ function addCoffee(flavor, time = new Date()) { function sendLog(json) { ajax("POST", "log", json, "log"); } + +function tellCoffeebot(what) +{ + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (this.readyState == 4) { + if (this.status == 200) { + document.getElementById("pLastCovfefe").innerHTML = "Don't worry now! There is a NEW HOPE Tonda is buying NEW PACK!"; + } else { + document.getElementById("pLastCovfefe").innerHTML = "No connection! No covfefe! We all die here!"; + } + } + }; + xhr.open("POST", "https://hooks.slack.com/services/T53CK6RB3/BC7J3TE94/dDlbPHNVaPILB8LyLHRjAAY...", true); + xhr.setRequestHeader("Content-type", "application/json"); + xhr.send(JSON.stringify({text: what})); + console.log(JSON.stringify({text: what})); +} -- 2.11.0