From 21cab163d529fe1f54714c200d55f370c5b1a537 Mon Sep 17 00:00:00 2001 From: isqua Date: Thu, 29 Jan 2015 14:46:46 +0300 Subject: [PATCH] Refactor pleer.com embedding --- chrome_point_plus/js/point-plus.js | 81 ++++-------------------------- 1 file changed, 11 insertions(+), 70 deletions(-) diff --git a/chrome_point_plus/js/point-plus.js b/chrome_point_plus/js/point-plus.js index 8cb01c6..0c5e3dd 100644 --- a/chrome_point_plus/js/point-plus.js +++ b/chrome_point_plus/js/point-plus.js @@ -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('' + + '' + + ''); - 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); } - }); - } // Проставляем теги у постов