mirror of
https://bitbucket.org/skobkin/chrome_point_plus.git
synced 2024-11-13 22:33:05 +00:00
Refactor pleer.com embedding
This commit is contained in:
parent
068c461070
commit
21cab163d5
|
@ -972,82 +972,23 @@ function set_posts_count_label() {
|
|||
}
|
||||
|
||||
function parse_pleercom_links(current_options) {
|
||||
if (current_options.is('option_embedding_pleercom_nokita_server')) {
|
||||
parse_pleercom_links_nokita();
|
||||
} else {
|
||||
parse_pleercom_links_ajax(current_options);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @deprecated since 1.19
|
||||
*/
|
||||
function parse_pleercom_links_nokita() {
|
||||
$('.post-content a').each(function(num, obj) {
|
||||
var href = obj.href;
|
||||
var n = null;
|
||||
$('.post-content a').each(function(num, link) {
|
||||
var $link = $(link);
|
||||
var href = link.href;
|
||||
var matches = href.match(new RegExp('^https?:\\/\\/pleer\\.com\\/tracks\\/([0-9a-z]+)', 'i'));
|
||||
|
||||
if (n = href.match(new RegExp('^https?:\\/\\/pleer\\.com\\/tracks\\/([0-9a-z]+)', 'i'))) {
|
||||
var player = document.createElement('audio');
|
||||
$(player).attr({
|
||||
'src': 'https://api.kanaria.ru/point/get_pleer_file.php?id=' + n[1],
|
||||
'controls': 'controls',
|
||||
'preload': 'none'
|
||||
});
|
||||
if (matches) {
|
||||
trackHref = 'http://embed.pleer.com/normal/track?id=' + matches[1] + '&t=grey';
|
||||
|
||||
var player_div = document.createElement('div');
|
||||
$(player_div).addClass('embeded_audio').addClass('embeded_audio_' + n[1]);
|
||||
player_div.appendChild(player);
|
||||
$link.before('<object width="578" height="60"><param name="movie" value="' + trackHref + '"></param>' +
|
||||
'<embed src="' + trackHref + '" type="application/x-shockwave-flash" width="578" height="60">' +
|
||||
'</embed></object>');
|
||||
|
||||
obj.parentElement.insertBefore(player_div, obj);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function parse_pleercom_links_ajax(current_options) {
|
||||
$('.post-content a').each(function(num, obj) {
|
||||
var href = obj.href;
|
||||
var n = null;
|
||||
|
||||
if (n = href.match(new RegExp('^https?:\\/\\/pleer\\.com\\/tracks\\/([0-9a-z]+)', 'i'))) {
|
||||
var player_div = document.createElement('div');
|
||||
$(player_div).addClass('embeded_audio').addClass('embeded_audio_' + n[1]);
|
||||
$(obj).addClass('pleercom_original_link_'+n[1]);
|
||||
obj.parentElement.insertBefore(player_div, obj);
|
||||
create_pleercom_ajax(n[1], current_options);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function create_pleercom_ajax(id, current_options) {
|
||||
$ajax({
|
||||
'url': 'https://pleer.com/site_api/files/get_url',
|
||||
'type': 'post',
|
||||
'postdata': 'action=download&id=' + id,
|
||||
'dont_set_content_type': true,
|
||||
'pleer_id': id,
|
||||
'headers': [['Accept', '*'], ['Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8']],
|
||||
'success': function(a) {
|
||||
var answer = JSON.parse(a);
|
||||
var player = document.createElement('audio');
|
||||
// @todo Проверять существование track_link
|
||||
$(player).attr({
|
||||
'src': answer.track_link,
|
||||
'controls': 'controls',
|
||||
'preload': 'auto'
|
||||
});
|
||||
$('.embeded_audio_' + this.settings.pleer_id)[0].appendChild(player);
|
||||
|
||||
if (current_options.is('option_embedding_pleercom_orig_link', false)){
|
||||
$('.pleercom_original_link_'+this.settings.pleer_id).hide();
|
||||
if ( ! current_options.is('option_embedding_pleercom_orig_link')) {
|
||||
$link.remove();
|
||||
}
|
||||
},
|
||||
'error': function() {
|
||||
console.log('Can not get pleer.com url');
|
||||
setTimeout(new Function('create_pleercom_ajax("' + this.settings.pleer_id + '");'), 1000);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Проставляем теги у постов
|
||||
|
|
Loading…
Reference in a new issue