|
|
|
<script>
|
|
|
|
const http = {
|
|
|
|
request: function(method, path, payload, callbk) {
|
|
|
|
payload = payload || null;
|
|
|
|
callbk = callbk || null;
|
|
|
|
const oReq = new XMLHttpRequest();
|
|
|
|
document.getElementById('loader').style = '';
|
|
|
|
oReq.addEventListener("load", function() {
|
|
|
|
document.getElementById('loader').style = 'display: none';
|
|
|
|
if (callbk)
|
|
|
|
callbk(this.responseText);
|
|
|
|
});
|
|
|
|
oReq.open(method, path);
|
|
|
|
oReq.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
oReq.send(payload);
|
|
|
|
},
|
|
|
|
get: function(path, payload, callbk) {
|
|
|
|
return http.request('GET', path, payload, callbk);
|
|
|
|
},
|
|
|
|
post: function(path, payload, callbk) {
|
|
|
|
return http.request('POST', path, payload, callbk);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const API = {
|
|
|
|
mastodon: {
|
|
|
|
registerInstance: function(instance) {
|
|
|
|
if (instance === null)
|
|
|
|
instance = document.getElementById('instanceURL').value;
|
|
|
|
http.get('/api/login/mastodon/get_client.php?instance='+encodeURIComponent(instance), {}, function(data)
|
|
|
|
{
|
|
|
|
data = JSON.parse(data);
|
|
|
|
if (data.status === 'err') {
|
|
|
|
alert(data.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const res = data.message;
|
|
|
|
const oauthUrl = res.instance+'/oauth/authorize?client_id='+encodeURIComponent(res.result.client_id)+'&redirect_uri='+encodeURIComponent(res.result.redirect_uri+'?id='+res.id)+'&response_type='+encodeURIComponent(res.response_type)+'&scope='+encodeURIComponent(res.scope);
|
|
|
|
localStorage['auth_data'] = JSON.stringify(res);
|
|
|
|
document.location.href = oauthUrl;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|