From ad5145fe3a4a52976fa965bfd4dc57f957d55161 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 28 Sep 2019 15:34:54 -0400 Subject: nfsw/static/io.js: Add handling barf intro. --- nfsw/static/io.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/nfsw/static/io.js b/nfsw/static/io.js index f9f907d..c141903 100644 --- a/nfsw/static/io.js +++ b/nfsw/static/io.js @@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', function() { */ window.qip = false; // query in prograss flag. function query(q) { - if (window.qip) { + if (window.qip || window.iip) { return window.setTimeout(query, 10, q); } window.qip = true; @@ -56,6 +56,64 @@ document.addEventListener('DOMContentLoaded', function() { xhr.send(q); } + window.iip = false; + function intro() { + if (window.qip) { + return window.setTimeout(intro, 10); + } + window.iip = true; + + var iipoff = function() { + window.iip = false; + }; + var spit = function(response, status) { + var r; + try { + r = JSON.parse(response); + } catch (e) { + return barfslow('💥God is busy sodomizing the waitress.' + + '\nTry refreshing the page.', 'error', iipoff); + } + + if (!('intro' in r)) { + return barfslow( + '💥Too bad Dr. Gonad Dick is ' + + '\ntoo busy whipping his eggplant.' + + '\nTry refreshing the page.', + 'error', + iipoff + ); + } + + if (status == 200) { + barfslow(r.intro, 'concierge', iipoff); + } else { + barfslow(r.intro, 'error', iipoff); + } + }; + + var xhr = new XMLHttpRequest(); + xhr.open('POST', '/io/intro', true); + + xhr.onreadystatechange = function() { + if (this.readyState != 4) { + return; + } + + if ([200, 500].indexOf(this.status) >= 0) { + return spit(this.responseText, this.status); + } else { + return barfslow( + '💥God just fucked a skunk.' + + '\nTry refreshing the page.', + 'error', + iipoff + ); + } + }; + xhr.send(); + } + /** * Handling for console. */ @@ -143,4 +201,5 @@ document.addEventListener('DOMContentLoaded', function() { var form = document.querySelector('form'); form.onsubmit = submit; + intro(); }); -- cgit v1.2.3