mirror of
https://github.com/greenshot/greenshot.git
synced 2025-01-08 23:03:03 -08:00
81 lines
2.2 KiB
HTML
81 lines
2.2 KiB
HTML
<script language="JavaScript">
|
|
// Build the search query by using the hash (anchor) too
|
|
var search = window.location.search;
|
|
var searchQuery = "";
|
|
if (search.length > 1) {
|
|
search = search.split('?')[1];
|
|
searchQuery = search;
|
|
}
|
|
var anchor = window.location.hash;
|
|
if (anchor.length > 1) {
|
|
anchor = anchor.split('#')[1];
|
|
}
|
|
if (anchor.length > 0) {
|
|
if (search.length > 0) {
|
|
searchQuery = search + "&" + anchor;
|
|
} else {
|
|
searchQuery = anchor;
|
|
}
|
|
}
|
|
|
|
function getQueryVariable(query, variable) {
|
|
var vars = query.split('&');
|
|
for (var i = 0; i < vars.length; i++) {
|
|
var pair = vars[i].split('=');
|
|
if (decodeURIComponent(pair[0]) == variable) {
|
|
return decodeURIComponent(pair[1]);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
var error = getQueryVariable(searchQuery, "error");
|
|
if (error != null) {
|
|
// Handle error?
|
|
window.console.error("Error: " + error);
|
|
jQuery('#authFailed').slideUp();
|
|
}
|
|
var port = getQueryVariable(searchQuery, "state");
|
|
|
|
// Build json object from the values provided by the oauth redirect
|
|
var jsonObject = {};
|
|
|
|
var vars = searchQuery.split('&');
|
|
for (var i = 0; i < vars.length; i++) {
|
|
var pair = vars[i].split('=');
|
|
var propertyName = decodeURIComponent(pair[0]);
|
|
var propertyValue = decodeURIComponent(pair[1]);
|
|
if (propertyName == "state") {
|
|
continue;
|
|
}
|
|
jsonObject[propertyName] = propertyValue;
|
|
}
|
|
|
|
// Send the data to the server, uses JQuery
|
|
$.ajax({
|
|
url: 'http://localhost:' + port + '/authorize',
|
|
contentType: 'application/json',
|
|
method: 'POST',
|
|
data: JSON.stringify(jsonObject),
|
|
dataType: 'json'
|
|
}).done(function(data) {
|
|
jQuery('#doingAuth').slideUp();
|
|
if (data.hasOwnProperty('version')) {
|
|
// Process used version to show any hints about newer versions, this is in the included "version-check.html"
|
|
checkVersion(data.version);
|
|
}
|
|
if (data.hasOwnProperty('error')) {
|
|
jQuery('#authFailed').slideDown();
|
|
} else {
|
|
jQuery('#authFailed').slideUp();
|
|
jQuery('#authOkay').slideDown();
|
|
jQuery('#donation').slideDown();
|
|
}
|
|
}).fail(function( jqXHR, textStatus, errorThrown) {
|
|
jQuery('#doingAuth').slideUp();
|
|
jQuery('#authFailed').slideDown();
|
|
jQuery('#authOkay').slideUp();
|
|
window.console.error("Error: " + textStatus);
|
|
});
|
|
|
|
</script> |