Vkontakte session battle
This commit is contained in:
@@ -23,17 +23,16 @@ Session = (function() {
|
||||
};
|
||||
Session.prototype.query = function(url, params, callback) {
|
||||
var q_params;
|
||||
q_params = this.vk_params;
|
||||
$.each(params, function(key, val) {
|
||||
return q_params[key] = val;
|
||||
});
|
||||
q_params = $.extend({}, this.vk_params, params);
|
||||
$.post(url, q_params, callback);
|
||||
return false;
|
||||
};
|
||||
Session.prototype.reloadSession = function() {
|
||||
return _session.query('/user/auth', {}, function(ar) {
|
||||
return _session.setUser(ar.user);
|
||||
_session.query('/user/auth', {}, function(ar) {
|
||||
_session.setUser(ar.user);
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
};
|
||||
return Session;
|
||||
})();
|
||||
@@ -14,7 +14,9 @@ Vkontakte = (function() {
|
||||
VK.init({
|
||||
apiId: _vkontakte.getApiId()
|
||||
});
|
||||
return VK.Auth.getLoginStatus(_vkontakte.authInfo);
|
||||
return VK.Auth.getLoginStatus(function(response) {
|
||||
return _vkontakte.authInfo(response);
|
||||
});
|
||||
};
|
||||
return setTimeout(function() {
|
||||
return $('#vk_api_transport').append('<script async="async" src="http://vkontakte.ru/js/api/openapi.js"></script>');
|
||||
@@ -49,6 +51,12 @@ Vkontakte = (function() {
|
||||
$('.header-container .hello').show();
|
||||
return $('.header-container .hello .greating').html('Tēnā koe, <span class="settings">' + (_session.getUser().name ? _session.getUser().name : '%username%') + '</span>!');
|
||||
});
|
||||
if (response.session.expire != null) {
|
||||
setTimeout(function() {
|
||||
_vkontakte.auth();
|
||||
return false;
|
||||
}, response.session.expire * 1000 - new Date().getTime() + 1000);
|
||||
}
|
||||
} else {
|
||||
_session = new Session({});
|
||||
_session.setUser({});
|
||||
@@ -59,6 +67,13 @@ Vkontakte = (function() {
|
||||
}
|
||||
return window._session = _session;
|
||||
};
|
||||
Vkontakte.prototype.auth = function() {
|
||||
VK.Auth.login(function(response) {
|
||||
_vkontakte.authInfo(response);
|
||||
return false;
|
||||
}, 8);
|
||||
return false;
|
||||
};
|
||||
Vkontakte.prototype.loadTracksData = function(artist, track, duration, callback) {
|
||||
var query, track_prepared, url;
|
||||
track_prepared = track.replace(/\(.*\)/i, '').split('/')[0];
|
||||
@@ -69,7 +84,6 @@ Vkontakte = (function() {
|
||||
return VK.Api.call('audio.search', {
|
||||
q: query
|
||||
}, function(r) {
|
||||
r.response.splice(0, 1);
|
||||
url = _vkontakte.matchPerfectResult(r.response, artist, track, duration);
|
||||
_vkontakte.addQR(query, url);
|
||||
return callback(url);
|
||||
@@ -84,35 +98,37 @@ Vkontakte = (function() {
|
||||
best_result = null;
|
||||
for (_i = 0, _len = data.length; _i < _len; _i++) {
|
||||
item = data[_i];
|
||||
score = 0;
|
||||
item.artist = item.artist.trim();
|
||||
item.title = item.title.trim();
|
||||
if (item.artist === artist) {
|
||||
score += 10;
|
||||
} else if (item.artist.split(artist).length === 2) {
|
||||
score += 5;
|
||||
} else if (item.title.split(artist).length === 2) {
|
||||
score += 4;
|
||||
}
|
||||
if (item.title === track) {
|
||||
score += 10;
|
||||
} else if (item.title.split(track).length === 2) {
|
||||
score += 5;
|
||||
}
|
||||
if (parseInt(item.duration, 10) === duration) {
|
||||
score += 15;
|
||||
} else {
|
||||
delta = Math.abs(parseInt(item.duration, 10) - duration);
|
||||
if (delta < 10) {
|
||||
score += 10 - delta;
|
||||
if (typeof item === 'object') {
|
||||
score = 0;
|
||||
item.artist = item.artist.trim();
|
||||
item.title = item.title.trim();
|
||||
if (item.artist === artist) {
|
||||
score += 10;
|
||||
} else if (item.artist.split(artist).length === 2) {
|
||||
score += 5;
|
||||
} else if (item.title.split(artist).length === 2) {
|
||||
score += 4;
|
||||
}
|
||||
if (item.title === track) {
|
||||
score += 10;
|
||||
} else if (item.title.split(track).length === 2) {
|
||||
score += 5;
|
||||
}
|
||||
if (parseInt(item.duration, 10) === duration) {
|
||||
score += 15;
|
||||
} else {
|
||||
delta = Math.abs(parseInt(item.duration, 10) - duration);
|
||||
if (delta < 10) {
|
||||
score += 10 - delta;
|
||||
}
|
||||
}
|
||||
if (score > best_score) {
|
||||
best_score = score;
|
||||
best_result = item;
|
||||
}
|
||||
if (score === 35) {
|
||||
return best_result.url;
|
||||
}
|
||||
}
|
||||
if (score > best_score) {
|
||||
best_score = score;
|
||||
best_result = item;
|
||||
}
|
||||
if (score === 35) {
|
||||
return best_result.url;
|
||||
}
|
||||
}
|
||||
return best_result.url;
|
||||
@@ -129,14 +145,14 @@ Vkontakte = (function() {
|
||||
return Vkontakte;
|
||||
})();
|
||||
$('#vk_login').live('click', function() {
|
||||
VK.Auth.login(function(response) {
|
||||
_vkontakte.authInfo(response);
|
||||
return false;
|
||||
}, 8);
|
||||
_vkontakte.auth();
|
||||
return false;
|
||||
});
|
||||
$('#vk_logout').live('click', function() {
|
||||
_ajax.go('/search/');
|
||||
VK.Auth.logout(_vkontakte.authInfo);
|
||||
VK.Auth.logout(function(response) {
|
||||
_vkontakte.authInfo(response);
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
@@ -204,24 +204,24 @@ $icons_dir: "/images/icns/";
|
||||
&.active {
|
||||
@include opacity(0.8);
|
||||
}
|
||||
}
|
||||
|
||||
img {
|
||||
float: left;
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
.annotation {
|
||||
float: left;
|
||||
margin-left: 2px;
|
||||
}
|
||||
|
||||
&#empty-playlist {
|
||||
float: right;
|
||||
margin-right: 10px;
|
||||
|
||||
img {
|
||||
margin-top: 3px;
|
||||
float: left;
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
.annotation {
|
||||
float: left;
|
||||
margin-left: 2px;
|
||||
}
|
||||
|
||||
&#empty-playlist {
|
||||
float: right;
|
||||
margin-right: 10px;
|
||||
|
||||
img {
|
||||
margin-top: 3px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,14 +171,14 @@
|
||||
-ms-filter: ”alpha(opacity=80) ”;
|
||||
filter: alpha(opacity=80);
|
||||
opacity: 0.8; }
|
||||
.player-container .additional-controls img {
|
||||
float: left;
|
||||
margin-top: 1px; }
|
||||
.player-container .additional-controls .annotation {
|
||||
float: left;
|
||||
margin-left: 2px; }
|
||||
.player-container .additional-controls#empty-playlist {
|
||||
float: right;
|
||||
margin-right: 10px; }
|
||||
.player-container .additional-controls#empty-playlist img {
|
||||
margin-top: 3px; }
|
||||
.player-container .additional-controls .item img {
|
||||
float: left;
|
||||
margin-top: 1px; }
|
||||
.player-container .additional-controls .item .annotation {
|
||||
float: left;
|
||||
margin-left: 2px; }
|
||||
.player-container .additional-controls .item#empty-playlist {
|
||||
float: right;
|
||||
margin-right: 10px; }
|
||||
.player-container .additional-controls .item#empty-playlist img {
|
||||
margin-top: 3px; }
|
||||
|
||||
Reference in New Issue
Block a user