mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
merged
This commit is contained in:
@@ -20,8 +20,38 @@ window.addEventListener("load", function() {
|
||||
|
||||
//window.opener.callback(query);
|
||||
window.location.href = "https://accounts.google.com/o/oauth2/v2/auth?client_id=" + client_id + "&response_type=" + response + "&state=" + state + "&redirect_uri=" + redirect + "&scope=" + scope;
|
||||
} else if(query.soundcloud) {
|
||||
/*
|
||||
SC.initialize({
|
||||
client_id: api_key.soundcloud,
|
||||
redirect_uri: 'https://zoff.me/api/oauth'
|
||||
});
|
||||
|
||||
// initiate auth popup
|
||||
console.log("asd ok", api_key.soundcloud);
|
||||
SC.connect().then(function() {
|
||||
return SC.get('/me');
|
||||
}).then(function(me) {
|
||||
console.log(me);
|
||||
//alert('Hello, ' + me.username);
|
||||
}).catch(function(e) {
|
||||
console.log(e);
|
||||
});*/
|
||||
|
||||
var redirect_uri = encodeURIComponent("https://zoff.me/api/oauth");
|
||||
var response_type = "code";
|
||||
var scope = "non-expiring";
|
||||
var state = query.nonce;
|
||||
var url = "https://soundcloud.com/connect?client_id=" + api_key.soundcloud + "&redirect_uri=" + redirect_uri + "&state=" + state + "&display=page&response_type=code&scope=" + scope;
|
||||
//console.log(url);
|
||||
window.location.href = url;
|
||||
} else {
|
||||
var query_parameters = getQueryHash(window.location.hash);
|
||||
var query_parameters;
|
||||
if(window.location.search.length > 0) {
|
||||
query_parameters = getQueryHash(window.location.search);
|
||||
} else {
|
||||
query_parameters = getQueryHash(window.location.hash);
|
||||
}
|
||||
try {
|
||||
window.opener.callback(query_parameters);
|
||||
} catch(e) {}
|
||||
@@ -29,14 +59,30 @@ window.addEventListener("load", function() {
|
||||
});
|
||||
|
||||
function getQueryHash(url) {
|
||||
var temp_arr = url.substring(1).split("&");
|
||||
var done_obj = {};
|
||||
var splitted;
|
||||
for(var i in temp_arr) {
|
||||
splitted = temp_arr[i].split("=");
|
||||
if(splitted.length == 2) {
|
||||
done_obj[splitted[0]] = splitted[1];
|
||||
if(window.location.search.length > 0) {
|
||||
if(url.substring(url.length - 1) == "#") {
|
||||
url = url.substring(0, url.length - 1);
|
||||
}
|
||||
var temp_arr = url.substring(1).split("&");
|
||||
var done_obj = {};
|
||||
var splitted;
|
||||
for(var i in temp_arr) {
|
||||
splitted = temp_arr[i].split("=");
|
||||
if(splitted.length == 2) {
|
||||
done_obj[splitted[0]] = splitted[1];
|
||||
}
|
||||
}
|
||||
return done_obj;
|
||||
} else {
|
||||
var temp_arr = url.substring(1).split("&");
|
||||
var done_obj = {};
|
||||
var splitted;
|
||||
for(var i in temp_arr) {
|
||||
splitted = temp_arr[i].split("=");
|
||||
if(splitted.length == 2) {
|
||||
done_obj[splitted[0]] = splitted[1];
|
||||
}
|
||||
}
|
||||
return done_obj;
|
||||
}
|
||||
return done_obj;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,8 @@ var chat_active = false;
|
||||
var chat_unseen = false;
|
||||
var blinking = false;
|
||||
var from_frontpage = false;
|
||||
var access_token_data_soundcloud = {};
|
||||
var soundcloud_window;
|
||||
var access_token_data = {};
|
||||
var spotify_authenticated = false;
|
||||
var not_import_html = "";
|
||||
@@ -950,6 +952,29 @@ function addDynamicListeners() {
|
||||
}
|
||||
});
|
||||
|
||||
addListener("click", ".export-soundcloud", function(event) {
|
||||
this.preventDefault();
|
||||
var nonce = Helper.randomString(29);
|
||||
Helper.removeClass("#playlist_loader_export", "hide");
|
||||
Helper.addClass(".soundcloud_export_button", "hide");
|
||||
window.callback = function(data) {
|
||||
access_token_data_soundcloud = data;
|
||||
if(access_token_data_soundcloud.state == nonce){
|
||||
soundcloud_authenticated = true;
|
||||
Helper.removeClass("#playlist_loader_export", "hide");
|
||||
Helper.addClass(".soundcloud_export_button", "hide");
|
||||
} else {
|
||||
access_token_data_soundcloud = {};
|
||||
console.error("States doesn't match");
|
||||
Helper.addClass("#playlist_loader_export", "hide");
|
||||
Helper.removeClass(".soundcloud_export_button", "hide");
|
||||
}
|
||||
soundcloud_window.close();
|
||||
window.callback = "";
|
||||
};
|
||||
soundcloud_window = window.open("/api/oauth#soundcloud=true&nonce=" + nonce, "", "width=600, height=600");
|
||||
})
|
||||
|
||||
addListener("click", ".export-spotify-auth", function(event){
|
||||
this.preventDefault();
|
||||
var nonce = Helper.randomString(29);
|
||||
@@ -1017,7 +1042,7 @@ function addDynamicListeners() {
|
||||
document.querySelector("#import_soundcloud").focus();
|
||||
});
|
||||
|
||||
addListener("submit", "#listImportSoundCloud", function(event) {
|
||||
/*addListener("submit", "#listImportSoundCloud", function(event) {
|
||||
this.preventDefault();
|
||||
Helper.removeClass(".playlist_loader_soundcloud", "hide");
|
||||
Helper.addClass("#listImportSoundCloud", "hide");
|
||||
@@ -1081,9 +1106,12 @@ function addDynamicListeners() {
|
||||
},
|
||||
error: function(data) {
|
||||
console.log(data);
|
||||
Helper.addClass(".playlist_loader_soundcloud", "hide");
|
||||
Helper.removeClass("#listImportSoundCloud", "hide");
|
||||
toast("If the list is private, you have to add the secret code at the end");
|
||||
}
|
||||
});
|
||||
});
|
||||
});*/
|
||||
|
||||
addListener("submit", "#listImportSpotify", function(event){
|
||||
this.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user