Merged in NokitaKaze/chrome_point_plus-nokita-version (pull request #6)

Pleer.com
This commit is contained in:
Alexey Skobkin 2014-11-16 21:16:28 +03:00
commit 320869316e
6 changed files with 119 additions and 21 deletions

View file

@ -180,4 +180,3 @@ div#markItUpText-input {
margin-left: 0.2em; margin-left: 0.2em;
background: #f2eceb; background: #f2eceb;
} }

View file

@ -4,6 +4,9 @@ function $ajax_prot(settings){
if (settings['async'] !==undefined){this.async =settings['async'];} if (settings['async'] !==undefined){this.async =settings['async'];}
if (settings['type'] !==undefined){this.type =settings['type'];} if (settings['type'] !==undefined){this.type =settings['type'];}
if (settings['postdata']!==undefined){this.postdata=settings['postdata'];} if (settings['postdata']!==undefined){this.postdata=settings['postdata'];}
if (settings['dont_set_content_type']!==undefined){
this.dont_set_content_type=settings['dont_set_content_type'];
}
this.xhr=new XMLHttpRequest(); this.xhr=new XMLHttpRequest();
this.xhr.parent =this; this.xhr.parent =this;
@ -12,7 +15,9 @@ function $ajax_prot(settings){
this.xhr.error =settings['error']; this.xhr.error =settings['error'];
this.xhr.onreadystatechange=this.change; this.xhr.onreadystatechange=this.change;
this.xhr.open(this.type, this.url, this.async); this.xhr.open(this.type, this.url, this.async);
if (this.type=='POST'){this.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');} if ((this.type=='POST')&& !this.dont_set_content_type){
this.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
if (settings.headers!==undefined){ if (settings.headers!==undefined){
for (var i=0;i<settings.headers.length;i++){ for (var i=0;i<settings.headers.length;i++){
this.xhr.setRequestHeader(settings.headers[i][0], settings.headers[i][1]); this.xhr.setRequestHeader(settings.headers[i][0], settings.headers[i][1]);
@ -22,12 +27,13 @@ function $ajax_prot(settings){
} }
$ajax_prot.prototype={ $ajax_prot.prototype={
version: '0.0.4a', version: '0.0.5a',
url: '', url: '',
type: 'GET', type: 'GET',
async: true, async: true,
postdata:null, postdata:null,
xhr: null, xhr: null,
dont_set_content_type: false,
change:function(){ change:function(){
if (this.readyState!==4){return;} if (this.readyState!==4){return;}
if (this.status==200){ if (this.status==200){

View file

@ -22,6 +22,9 @@ var ppOptions = [
// SoundCloud // SoundCloud
'option_embedding_soundcloud', 'option_embedding_soundcloud',
'option_embedding_soundcloud_orig_link', 'option_embedding_soundcloud_orig_link',
// Pleer.com
'option_embedding_pleercom',
'option_embedding_pleercom_nokita_server',
// Fluid layout // Fluid layout
'option_fluid_layout', 'option_fluid_layout',
// Visual editor for posts // Visual editor for posts
@ -60,6 +63,8 @@ function pp_save_options() {
ppOptions.option_videos_parse_webm = $('#option-videos-parse-webm').prop('checked'); ppOptions.option_videos_parse_webm = $('#option-videos-parse-webm').prop('checked');
ppOptions.option_embedding_soundcloud = $('#option-embedding-soundcloud').prop('checked'); ppOptions.option_embedding_soundcloud = $('#option-embedding-soundcloud').prop('checked');
ppOptions.option_embedding_soundcloud_orig_link = $('#option-embedding-soundcloud-orig-link').prop('checked'); ppOptions.option_embedding_soundcloud_orig_link = $('#option-embedding-soundcloud-orig-link').prop('checked');
ppOptions.option_embedding_pleercom = $('#option-embedding-pleercom').prop('checked');
ppOptions.option_embedding_pleercom_nokita_server = $('#option-embedding-pleercom-nokita-server').prop('checked');
ppOptions.option_visual_editor_post = $('#option-visual-editor-post').prop('checked'); ppOptions.option_visual_editor_post = $('#option-visual-editor-post').prop('checked');
ppOptions.checkbox_search_with_google = $('#option-search-with-google').prop('checked'); ppOptions.checkbox_search_with_google = $('#option-search-with-google').prop('checked');
ppOptions.option_ws = $('#option-ws').prop('checked'); ppOptions.option_ws = $('#option-ws').prop('checked');
@ -75,7 +80,6 @@ function pp_save_options() {
ppOptions.option_other_hightlight_post_comments = $('#option-other-hightlight-post-comments').prop('checked'); ppOptions.option_other_hightlight_post_comments = $('#option-other-hightlight-post-comments').prop('checked');
ppOptions.option_other_show_recommendation_count = $('#option-other-show-recommendation-count').prop('checked'); ppOptions.option_other_show_recommendation_count = $('#option-other-show-recommendation-count').prop('checked');
// Saving parameters // Saving parameters
chrome.storage.sync.set(ppOptions, function() { chrome.storage.sync.set(ppOptions, function() {
// Update status to let user know options were saved. // Update status to let user know options were saved.
@ -97,8 +101,8 @@ function pp_restore_options() {
// Detecting option type // Detecting option type
if (typeof(value) == 'boolean') { if (typeof(value) == 'boolean') {
// Checkbox // Checkbox
optionId = '#' + key.replace(/_/g, '-');
if (value === true) { if (value === true) {
optionId = '#' + key.replace(/_/g, '-');
$(optionId).first().prop('checked', true); $(optionId).first().prop('checked', true);
} }
} else if (typeof(value) == 'number') { } else if (typeof(value) == 'number') {

View file

@ -19,6 +19,7 @@ $(document).ready(function() {
if (options.option_videos_parse_webm == true) { if (options.option_videos_parse_webm == true) {
parse_webm(); parse_webm();
} }
// Soundcloud // Soundcloud
if (options.option_embedding_soundcloud == true) { if (options.option_embedding_soundcloud == true) {
// Injecting JS API // Injecting JS API
@ -34,8 +35,8 @@ $(document).ready(function() {
$player = $('<div class="pp-soundcloud">\ $player = $('<div class="pp-soundcloud">\
<object height="81" width="100%" id="pp-soundcloud-' + index + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">\ <object height="81" width="100%" id="pp-soundcloud-' + index + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">\
<param name="movie" value="http://player.soundcloud.com/player.swf?url=' + encodeURIComponent($(this).prop('href')) <param name="movie" value="http://player.soundcloud.com/player.swf?url=' + encodeURIComponent($(this).prop('href'))
+ '&enable_api=true&object_id=pp-soundcloud-' + index + '"></param>\ + '&enable_api=true&object_id=pp-soundcloud-' + index + '">\
<param name="allowscriptaccess" value="always"></param>\ <param name="allowscriptaccess" value="always">\
<embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=' <embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url='
+ encodeURIComponent($(this).prop('href')) + '&enable_api=true&object_id=pp-soundcloud-' + index + encodeURIComponent($(this).prop('href')) + '&enable_api=true&object_id=pp-soundcloud-' + index
+ '" type="application/x-shockwave-flash" width="100%" name="pp-soundcloud-' + index + '"></embed>\ + '" type="application/x-shockwave-flash" width="100%" name="pp-soundcloud-' + index + '"></embed>\
@ -51,6 +52,11 @@ $(document).ready(function() {
$(this).replaceWith($player); $(this).replaceWith($player);
} }
}); });
}
// Parse webm-links and create video instead
if (options.option_embedding_pleercom == true) {
parse_pleercom_links();
} }
} }
@ -514,7 +520,6 @@ function create_image(domain, id, additional) {
/* point */ /* point */
// Эта часть написана @RainbowSpike // Эта часть написана @RainbowSpike
function mark_unread_post() { function mark_unread_post() {
// @todo Проверить работает ли
var divs = $(".post"); // массив постов var divs = $(".post"); // массив постов
for (var i = 0; i < divs.length; i++) { // обыск постов for (var i = 0; i < divs.length; i++) { // обыск постов
var spans = $(divs[i]).find(".unread"); // поиск метки непрочитанных комментов var spans = $(divs[i]).find(".unread"); // поиск метки непрочитанных комментов
@ -577,6 +582,7 @@ function set_posts_count_label() {
} }
var e1 = document.createElement('span'); var e1 = document.createElement('span');
if (typeof(answer.list[id])=='undefined'){return;}
$(e1).addClass('authors_unique_count').html(answer.list[id].count_comment_unique).attr('title', 'Количество комментаторов'); $(e1).addClass('authors_unique_count').html(answer.list[id].count_comment_unique).attr('title', 'Количество комментаторов');
postid.appendChild(e1); postid.appendChild(e1);
@ -589,3 +595,77 @@ function set_posts_count_label() {
}) })
} }
function parse_pleercom_links(){
chrome.storage.sync.get(ppOptions, function(options) {
if (options.option_embedding_pleercom_nokita_server){
parse_pleercom_links_nokita();
}else{
parse_pleercom_links_ajax();
}
});
}
function parse_pleercom_links_nokita() {
$('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 = document.createElement('audio');
$(player).attr({
'src': 'https://api.kanaria.ru/point/get_pleer_file.php?id=' + n[1],
'controls': 'controls',
'preload': 'none'
});
var player_div=document.createElement('div');
$(player_div).addClass('embeded_audio').addClass('embeded_audio_'+n[1]);
player_div.appendChild(player);
obj.parentElement.insertBefore(player_div, obj);
}
});
}
function parse_pleercom_links_ajax(){
$('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.parentElement.insertBefore(player_div, obj);
create_pleercom_ajax(n[1]);
}
});
}
function create_pleercom_ajax(id){
$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);
},
'error':function(){
console.log('Can not get url');
setTimeout(new Function('create_pleercom_ajax("'+this.settings.pleer_id+'");'), 1000);
}
});
}

View file

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Point+", "name": "Point+",
"version": "1.10.0", "version": "1.10.2",
"author": "Alexey Skobkin", "author": "Alexey Skobkin",
"homepage_url": "https://bitbucket.org/skobkin/chrome_point_plus", "homepage_url": "https://bitbucket.org/skobkin/chrome_point_plus",
"description": "More features for point.im", "description": "More features for point.im",
@ -52,6 +52,7 @@
"permissions": [ "permissions": [
"http://*.point.im/*", "http://*.point.im/*",
"https://*.point.im/*", "https://*.point.im/*",
"https://pleer.com/*",
"storage", "storage",
"notifications", "notifications",
"tabs" "tabs"

View file

@ -60,6 +60,14 @@
<input type="checkbox" id="option-embedding-soundcloud-orig-link"><label for="option-embedding-soundcloud-orig-link">Leave original link</label> <input type="checkbox" id="option-embedding-soundcloud-orig-link"><label for="option-embedding-soundcloud-orig-link">Leave original link</label>
</div> </div>
</div> </div>
<div class="option">
<input type="checkbox" id="option-embedding-pleercom"><label for="option-embedding-pleercom">Pleer.com &#9660;</label>
<div class="option">
<input type="checkbox" id="option-embedding-pleercom-nokita-server"><label for="option-embedding-pleercom-nokita-server">Use Nokita's server</label>
</div>
</div>
</div> </div>
</div> </div>