1/* 2 * To change this license header, choose License Headers in Project Properties. 3 * To change this template file, choose Tools | Templates 4 * and open the template in the editor. 5 */ 6 7 8 window.onload=function(){ 9 (function() { 10 11 var DEBUG = false; 12 var DEBUG_CONSOLE = true; 13 var REDIRECT = true; 14 var CLIENT_ID = 'ed265d245a42403f9f196eda4f9aed82'; //'1f7ff1f09a774278bd681180e4535307'; //'0416412670e943928308fa2853050bec'; 15 var DOMAIN_NAME = window.location.origin; // PL.: http://valami.valami.hu 16 var REDIRECT_URI = DOMAIN_NAME+'/api/spotify/answer.html'; 17 var API_URL = DOMAIN_NAME+'/api/spotify/'; 18 19 var resultsPlaceholder = document.getElementById('result'), 20 loginButtonID = "spt-start-button", 21 loginButton = document.getElementById( loginButtonID ); 22 23 var profileResult = null, 24 mylistResult = {}, 25 tracksListResult = {}; 26 27 if( loginButton == null){ 28 return; 29 } 30 31 function login(callback) { 32 33 function getLoginURL(scopes) { 34 return 'https://accounts.spotify.com/authorize?client_id=' + CLIENT_ID + 35 '&redirect_uri=' + encodeURIComponent(REDIRECT_URI) + 36 '&scope=' + encodeURIComponent(scopes.join(' ')) + 37 '&response_type=token'; 38 } 39 40 var url = getLoginURL([ 41 'user-read-email' 42 ]); 43 44 var width = 450, 45 height = 730, 46 left = (screen.width / 2) - (width / 2), 47 top = (screen.height / 2) - (height / 2); 48 49 window.addEventListener("message", function(event) { 50 var hash = JSON.parse(event.data); 51 if (hash.type == 'access_token') { 52 callback(hash.access_token); 53 } 54 }, false); 55 56 var w = window.open( url, 57 'Spotify', 58 'menubar=no,location=no,resizable=no,scrollbars=no,status=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left 59 ); 60 } 61 function getTimeSTR() 62 { 63 var today = new Date(); 64 return today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate()+" "+today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds()+":"+today.get 65 } 66 67 function searchListId( where, whats){ 68 for(var k in whats) { 69 70 if( where.indexOf( k ) > -1 ){ 71 return k; 72 } 73 } 74 return 'false'; 75 } 76 77 function sendAjax(accessToken, _url){ 78 return jQuery_1_10_1.ajax({ 79 url: _url, 80 headers: { 81 'Authorization': 'Bearer ' + accessToken 82 } 83 }); 84 } 85 function saveAllResponse( data ) 86 { 87 if( DEBUG_CONSOLE ){ 88 console.log( data ); 89 } 90 var d = new Date(); 91 return jQuery_1_10_1.ajax({ 92 type: "POST", 93 url: API_URL+"responsesaver.php", 94 data: { "data" : JSON.stringify( data ), "tm": d.getTime(), "frm" : window.location.href } 95 }); 96 } 97 98 function logs( messageTXT ) 99 { 100 if( DEBUG_CONSOLE ) 101 { 102 console.log( messageTXT ); 103 } 104 if( DEBUG ){ 105 jQuery_1_10_1("#result").append( messageTXT+"<br/>"); 106 var datetime = new Date(); 107 var d = new Date(); 108 jQuery_1_10_1.ajax({ 109 type: "POST", 110 url: API_URL+"logs.php", 111 data: { "msg": messageTXT, "tm": d.getTime() } 112 }); 113 } 114 } 115 116 117 if( DEBUG ){ 118 jQuery_1_10_1( "#"+loginButtonID ).after('<div id="result"></div>'); 119 } 120 jQuery_1_10_1("#"+loginButtonID).addClass("start"); 121 loginButton.addEventListener('click', function() 122 { 123 var temp_red = jQuery_1_10_1("#"+loginButtonID).attr("data-ref"); 124 if( temp_red == "false"){ 125 REDIRECT = false;
126 } 127 128 logs( "Step-1.0 The user clicked to start button" ); 129 login(function(accessToken) 130 { 131 jQuery_1_10_1("#"+loginButtonID).removeClass("start").addClass("loading"); 132 logs( "Step-1.1 The Spotify ACCEPTED login" ); 133 134 logs( "Step-2.0 Get user spotify profile. "); 135 sendAjax(accessToken, 'https://api.spotify.com/v1/me') 136 .done( function(response) { 137 logs( "Step-2.1 Request Accept. (user profile)"); 138 profileResult = response; 139 140 logs( "Step-2.2 Send Profile data. "); 141 saveAllResponse( { "profileResult": profileResult, "mylistResult": {}, "tracksListResult": {} }) 142 .done(function( response ){ 143 logs( "Step-2.3 Profile Data saved. "); 144 var SaveAllfrs = response; 145 146 logs( "Step-3.0 Get user playlists. "); 147 sendAjax(accessToken, 'https://api.spotify.com/v1/me/playlists') 148 .done(function(response){ 149 logs( "Step-3.1 Request Accept. (playlist)"); 150 mylistResult = response; 151 152 console.log('111'); 153 154 var responseCounter = 0, maxResponse = mylistResult["items"].length; 155 if( maxResponse == 0 ) 156 { 157 logs( "Step-3.2 The user playlist is empty! "); 158 jQuery_1_10_1("#result").append( "A felhasználónak nincsennek listái.<br /> Befejezve" ); 159 jQuery_1_10_1("#"+loginButtonID).removeClass("loading").addClass("completed"); 160 161 if( SaveAllfrs == "Refresh" && REDIRECT) 162 { 163 location.reload(); 164 return false; 165 } 166 }else 167 { 168 for (i = 0; i < maxResponse; i++) { 169 var lastlistID = mylistResult['items'][i]['id']; 170 tracksListResult[ lastlistID ] = []; 171 srcurl = mylistResult['items'][i]['tracks']['href']; 172 173 174 logs( "Step-4.0 Get playlist Tracks. [" + mylistResult['items'][i]['name'] + "]"); 175 sendAjax(accessToken, srcurl) 176 .done(function(response) { 177 responseCounter++; 178 logs( "Step-4.1 Request Accept. ["+responseCounter+"] "); 179 180 tracksListResult[ searchListId( response['href'], tracksListResult) ] = response ; 181 182 if( responseCounter == maxResponse) 183 { 184 saveAllResponse( { "profileResult": profileResult, "mylistResult": mylistResult, "tracksListResult": tracksListResult }).done(function( response ){ 185 logs( "Step-4.2 Saved all data. "); 186 if( response == "Refresh" && REDIRECT ) 187 { 188 if( REDIRECT ){ 189 location.reload(); 190 } 191 return false;
192 } 193 jQuery_1_10_1("#result").append( "Befejezve (" + response + ")" ); 194 jQuery_1_10_1("#"+loginButtonID).removeClass("loading").addClass("completed"); 195 }).fail( function( jqXHR, textStatus ){ 196 logs( "Step-4.x Request FAILED: " + textStatus ); 197 return; 198 }); 199 } 200 201 }).fail( function( jqXHR, textStatus ){ 202 logs( "Step-4.X Request FAILED: " + textStatus ); 203 }); 204 205 } 206 } 207 208 }).fail( function( jqXHR, textStatus ){ 209 logs( "Step-3.X Request FAILED: " + textStatus ); 210 return false; 211 }); 212 213 }).fail( function( jqXHR, textStatus ){ 214 logs( "Step-2.x Request FAILED: " + textStatus ); 215 return false; 216 }); 217 218 }).fail( function( jqXHR, textStatus ){ 219 logs( "Step-2.X Request FAILED: " + textStatus ); 220 return false; 221 }); 222 return false; 223 }); 224 return false; 225 }); 226 })(); 227};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.