Browse Source

Prompt user to log in when necessary

This checks whether user is logged in or not before displaying the
uploader.
tags/v1.0
Matt Baer 5 years ago
parent
commit
8614f99eb3
2 changed files with 26 additions and 0 deletions
  1. +7
    -0
      uploader.html
  2. +19
    -0
      uploader.js

+ 7
- 0
uploader.html View File

@@ -22,11 +22,18 @@
transition: all .2s ease-out;
border-radius: .25em;
}
#uploader {
display: none;
}
#loading {
font-size: 2em;
}
</style>

<script src="dropzone.min.js"></script>
</head>
<body>
<p id="loading">Checking...</p>
<form action="https://snap.as/upload" method="post" class="dropzone" id="uploader">
<div class="fallback">
<input name="file" type="file" />


+ 19
- 0
uploader.js View File

@@ -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 = '<a href="https://snap.as/login" id="login">Log in to Snap.as</a>';
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,


Loading…
Cancel
Save