From 8614f99eb3487560d60e149d3cd90c1763dd902f Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 19 Jun 2018 16:19:42 -0400 Subject: [PATCH] Prompt user to log in when necessary This checks whether user is logged in or not before displaying the uploader. --- uploader.html | 7 +++++++ uploader.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/uploader.html b/uploader.html index addf143..3742619 100644 --- a/uploader.html +++ b/uploader.html @@ -22,11 +22,18 @@ transition: all .2s ease-out; border-radius: .25em; } + #uploader { + display: none; + } + #loading { + font-size: 2em; + } +

Checking...

diff --git a/uploader.js b/uploader.js index 809fa70..99356c0 100644 --- a/uploader.js +++ b/uploader.js @@ -12,6 +12,25 @@ function copyToClipboard(str) { document.body.removeChild(el); } +var http = new XMLHttpRequest(); +http.open("GET", "https://snap.as/api/me", true); +http.onreadystatechange = function() { + if (http.readyState == 4) { + env = JSON.parse(http.responseText); + if (env.code == 200 && typeof env.data !== 'undefined' && env.data != "") { + document.getElementById('loading').style.display = 'none'; + document.getElementById('uploader').style.display = 'block'; + } else { + document.getElementById('loading').innerHTML = 'Log in to Snap.as'; + document.getElementById('login').onclick = function(e) { + e.preventDefault(); + chrome.tabs.create({ url: 'https://snap.as/login' }); + window.close(); + }; + } + } +} +http.send(); Dropzone.options.uploader = { maxFilesize: 16,