Shit-like code style mostly dropped out.

This commit is contained in:
Alexey Skobkin 2014-11-23 13:10:35 +04:00
parent dcf7346078
commit 282314d9d6
1 changed files with 64 additions and 62 deletions

View File

@ -1,15 +1,15 @@
$(document).ready(function () { $(document).ready(function() {
// Grouping console log // Grouping console log
console.group('point-plus'); console.group('point-plus');
console.info('Point+ %s', getVersion()); console.info('Point+ %s', getVersion());
// Проверяем, загрузились ли мы // Проверяем, загрузились ли мы
var point_plus_debug=$('.point-plus-debug'); var point_plus_debug=$('.point-plus-debug');
if (point_plus_debug.length>0){ if (point_plus_debug.length > 0){
console.info('Point+ already loaded, version: %s', point_plus_debug.attr('data-point-plus-version')); console.info('Point+ already loaded, version: %s', point_plus_debug.attr('data-point-plus-version'));
return; return;
} }
point_plus_debug=null; point_plus_debug = null;
var new_div=document.createElement('div'); var new_div=document.createElement('div');
document.body.appendChild(new_div); document.body.appendChild(new_div);
$(new_div).attr({ $(new_div).attr({
@ -54,11 +54,11 @@ $(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="//player.soundcloud.com/player.swf?url=' + encodeURIComponent($(this).prop('href')) <param name="movie" value="//player.soundcloud.com/player.swf?url=' + encodeURIComponent($(this).prop('href'))
+ '&enable_api=true&object_id=pp-soundcloud-' + index + '">\ + '&enable_api=true&object_id=pp-soundcloud-' + index + '">\
<param name="allowscriptaccess" value="always">\ <param name="allowscriptaccess" value="always">\
<embed allowscriptaccess="always" height="81" src="//player.soundcloud.com/player.swf?url=' <embed allowscriptaccess="always" height="81" src="//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>\
</object>\ </object>\
</div>'); </div>');
@ -232,7 +232,7 @@ $(document).ready(function () {
// Image resizing // Image resizing
if (options.option_images_load_original == true) { if (options.option_images_load_original == true) {
// Setting new image source // Setting new image source
$('.postimg:not(.youtube) img').each(function () { $('.postimg:not(.youtube) img').each(function() {
console.log($(this).parent('.postimg').attr('href')); console.log($(this).parent('.postimg').attr('href'));
$(this).attr('src', $(this).parent('.postimg').attr('href')); $(this).attr('src', $(this).parent('.postimg').attr('href'));
}); });
@ -254,7 +254,7 @@ $(document).ready(function () {
// Send by CTRL+Enter // Send by CTRL+Enter
if (options.option_ctrl_enter == true) { if (options.option_ctrl_enter == true) {
// New post // New post
$('#new-post-form #text-input, .post-content #text-input').on('keydown.point_plus', function (e) { $('#new-post-form #text-input, .post-content #text-input').on('keydown.point_plus', function(e) {
if (e.ctrlKey && (e.keyCode == 10 || e.keyCode == 13)) { if (e.ctrlKey && (e.keyCode == 10 || e.keyCode == 13)) {
e.preventDefault(); e.preventDefault();
$(this).parents('#new-post-form,#post-edit-form').submit(); $(this).parents('#new-post-form,#post-edit-form').submit();
@ -264,7 +264,7 @@ $(document).ready(function () {
} }
// Google search // Google search
if (options.option_search_with_google == true) { if (options.option_search_with_google == true) {
$('#search-form input[type="text"]').attr('placeholder', 'Google').keydown(function (e) { $('#search-form input[type="text"]').attr('placeholder', 'Google').keydown(function(e) {
if (e.keyCode == 10 || e.keyCode == 13) { if (e.keyCode == 10 || e.keyCode == 13) {
e.preventDefault(); e.preventDefault();
document.location.href = '//www.google.ru/search?q=site%3Apoint.im+' + $(this).val(); document.location.href = '//www.google.ru/search?q=site%3Apoint.im+' + $(this).val();
@ -290,7 +290,7 @@ $(document).ready(function () {
}; };
// Message handler // Message handler
ws.onmessage = function (evt) { ws.onmessage = function(evt) {
try { try {
// ping :) // ping :)
if (evt.data == 'ping') { if (evt.data == 'ping') {
@ -337,7 +337,7 @@ $(document).ready(function () {
}); });
// Loading HTML template // Loading HTML template
$commentTemplate.load(chrome.extension.getURL('includes/comment.html'), function () { $commentTemplate.load(chrome.extension.getURL('includes/comment.html'), function() {
// Load complete // Load complete
console.info('comment.html loaded'); console.info('comment.html loaded');
@ -508,7 +508,9 @@ $(document).ready(function () {
}); });
// Showing page action // Showing page action
chrome.extension.sendMessage({type: 'showPageAction'}); chrome.extension.sendMessage({
type: 'showPageAction'
});
}); });
function escapeHtml(text) { function escapeHtml(text) {
@ -531,7 +533,7 @@ var months = [
// Картинки с бурятников // Картинки с бурятников
var booru_picture_count = 0; var booru_picture_count = 0;
function load_all_booru_images() { function load_all_booru_images() {
$('a').each(function (num, obj) { $('a').each(function(num, obj) {
if ($(obj).hasClass('booru_pic')) { if ($(obj).hasClass('booru_pic')) {
return; return;
} }
@ -568,11 +570,11 @@ function load_all_booru_images() {
obj.parentElement.insertBefore(image, obj); obj.parentElement.insertBefore(image, obj);
booru_picture_count++; booru_picture_count++;
/* /*
}else if (n=href.match(new RegExp('^https?\\://(www\\.)?konachan\\.net\\/post\\/show\\/([0-9]+)\\/', 'i'))){ } else if (n = href.match(new RegExp('^https?\\://(www\\.)?konachan\\.net\\/post\\/show\\/([0-9]+)\\/', 'i'))) {
var image=create_image('konachannet', n[2]); var image = create_image('konachannet', n[2]);
obj.parentElement.insertBefore(image, obj); obj.parentElement.insertBefore(image, obj);
booru_picture_count++; booru_picture_count++;
}else if (n=href.match(new RegExp('^https?\\://(www\\.)?konachan\\.com\\/post\\/show\\/([0-9]+)\\/', 'i'))){ } else if (n = href.match(new RegExp('^https?\\://(www\\.)?konachan\\.com\\/post\\/show\\/([0-9]+)\\/', 'i'))) {
var image=create_image('konachancom', n[2]); var image=create_image('konachancom', n[2]);
obj.parentElement.insertBefore(image, obj); obj.parentElement.insertBefore(image, obj);
booru_picture_count++; booru_picture_count++;
@ -634,7 +636,7 @@ function mark_unread_post() {
// Webm // Webm
function parse_webm() { function parse_webm() {
$('a').each(function (num, obj) { $('a').each(function(num, obj) {
if ($(obj).hasClass('booru_pic')) { if ($(obj).hasClass('booru_pic')) {
return; return;
} }
@ -656,7 +658,7 @@ function parse_webm() {
} }
function parse_all_videos() { function parse_all_videos() {
$('a').each(function (num, obj) { $('a').each(function(num, obj) {
if ($(obj).hasClass('booru_pic')) { if ($(obj).hasClass('booru_pic')) {
return; return;
} }
@ -678,7 +680,7 @@ function parse_all_videos() {
} }
function video_extension_to_mime(extension) { function video_extension_to_mime(extension) {
switch(extension){ switch (extension) {
case 'webm':return 'video/webm; codecs="vp8, vorbis'; case 'webm':return 'video/webm; codecs="vp8, vorbis';
case 'avi' :return 'video/avi;'; case 'avi' :return 'video/avi;';
case 'mp4' :return 'video/mp4;'; case 'mp4' :return 'video/mp4;';
@ -693,7 +695,7 @@ function set_posts_count_label() {
var ids = []; var ids = [];
$('.post .post-id a .cn').addClass('changed_background'); $('.post .post-id a .cn').addClass('changed_background');
$('div.post').each(function (num, obj) { $('div.post').each(function(num, obj) {
var t = $(obj).attr('data-comment-id'); var t = $(obj).attr('data-comment-id');
if (typeof(t) !== 'undefined') { if (typeof(t) !== 'undefined') {
return; return;
@ -704,10 +706,10 @@ function set_posts_count_label() {
$ajax({ $ajax({
'url': 'https://api.kanaria.ru/point/get_post_info.php?list=' + urlencode(ids.join(',')), 'url': 'https://api.kanaria.ru/point/get_post_info.php?list=' + urlencode(ids.join(',')),
'success': function (a) { 'success': function(a) {
var answer = JSON.parse(a); var answer = JSON.parse(a);
$('div.post').each(function (num, obj) { $('div.post').each(function(num, obj) {
var id = $(obj).attr('data-id'); var id = $(obj).attr('data-id');
var postid = $(obj).find('.post-id a')[0]; var postid = $(obj).find('.post-id a')[0];
var t = $(obj).attr('data-comment-id'); var t = $(obj).attr('data-comment-id');
@ -733,7 +735,7 @@ function set_posts_count_label() {
} }
function parse_pleercom_links() { function parse_pleercom_links() {
chrome.storage.sync.get(ppOptions, function (options) { chrome.storage.sync.get(ppOptions, function(options) {
if (options.option_embedding_pleercom_nokita_server) { if (options.option_embedding_pleercom_nokita_server) {
parse_pleercom_links_nokita(); parse_pleercom_links_nokita();
} else { } else {
@ -743,7 +745,7 @@ function parse_pleercom_links() {
} }
function parse_pleercom_links_nokita() { function parse_pleercom_links_nokita() {
$('a').each(function (num, obj) { $('a').each(function(num, obj) {
var href = obj.href; var href = obj.href;
var n = null; var n = null;
@ -765,7 +767,7 @@ function parse_pleercom_links_nokita() {
} }
function parse_pleercom_links_ajax() { function parse_pleercom_links_ajax() {
$('a').each(function (num, obj) { $('a').each(function(num, obj) {
var href = obj.href; var href = obj.href;
var n = null; var n = null;
@ -786,7 +788,7 @@ function create_pleercom_ajax(id) {
'dont_set_content_type': true, 'dont_set_content_type': true,
'pleer_id': id, 'pleer_id': id,
'headers': [['Accept', '*'], ['Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8']], 'headers': [['Accept', '*'], ['Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8']],
'success': function (a) { 'success': function(a) {
var answer = JSON.parse(a); var answer = JSON.parse(a);
var player = document.createElement('audio'); var player = document.createElement('audio');
// @todo Проверять существование track_link // @todo Проверять существование track_link
@ -797,7 +799,7 @@ function create_pleercom_ajax(id) {
}); });
$('.embeded_audio_' + this.settings.pleer_id)[0].appendChild(player); $('.embeded_audio_' + this.settings.pleer_id)[0].appendChild(player);
}, },
'error': function () { 'error': function() {
console.log('Can not get url'); console.log('Can not get url');
setTimeout(new Function('create_pleercom_ajax("' + this.settings.pleer_id + '");'), 1000); setTimeout(new Function('create_pleercom_ajax("' + this.settings.pleer_id + '");'), 1000);
} }
@ -808,40 +810,7 @@ function create_pleercom_ajax(id) {
// Проставляем теги у постов // Проставляем теги у постов
function create_tag_system() { function create_tag_system() {
$('.post').each(function () { $('.post').each(function() {
var tags = $(this).find('div.tags a.tag');
for (var i = 0; i < tags.length; i++) {
var tag_name = $(tags[i]).html().toLowerCase();
$(this).addClass('post-tag-' + tag_name);
}
});
}
// Скролл по пробелу
function set_space_key_skip_handler(){
if ($('#comments').length>0){
return;
}
// @todo Свериться с Best-practice биндинга функций. Мб там on или bind
$(document.body).keydown(function(e){
// @todo Я хотел по отпусканию кнопки, но там уже скролл срабатывает
// проверяем фокус
if ($(':focus').length>0) {
return;
}
var k=event.keyCode;
if (k==32){
space_key_event();
return false;
}
});
}
// Проставляем теги у постов
function create_tag_system() {
$('.post').each(function () {
var tags = $(this).find('div.tags a.tag'); var tags = $(this).find('div.tags a.tag');
for (var i = 0; i < tags.length; i++) { for (var i = 0; i < tags.length; i++) {
var tag_name = $(tags[i]).html().toLowerCase(); var tag_name = $(tags[i]).html().toLowerCase();
@ -857,7 +826,40 @@ function set_space_key_skip_handler() {
} }
// @todo Свериться с Best-practice биндинга функций. Мб там on или bind // @todo Свериться с Best-practice биндинга функций. Мб там on или bind
$(document.body).keydown(function (e) { $(document.body).keydown(function(e) {
// @todo Я хотел по отпусканию кнопки, но там уже скролл срабатывает
// проверяем фокус
if ($(':focus').length > 0) {
return;
}
var k = event.keyCode;
if (k == 32){
space_key_event();
return false;
}
});
}
// Проставляем теги у постов
function create_tag_system() {
$('.post').each(function() {
var tags = $(this).find('div.tags a.tag');
for (var i = 0; i < tags.length; i++) {
var tag_name = $(tags[i]).html().toLowerCase();
$(this).addClass('post-tag-' + tag_name);
}
});
}
// Скролл по пробелу
function set_space_key_skip_handler() {
if ($('#comments').length > 0) {
return;
}
// @todo Свериться с Best-practice биндинга функций. Мб там on или bind
$(document.body).keydown(function(e) {
// @todo Я хотел по отпусканию кнопки, но там уже скролл срабатывает // @todo Я хотел по отпусканию кнопки, но там уже скролл срабатывает
// проверяем фокус // проверяем фокус
if ($(':focus').length > 0) { if ($(':focus').length > 0) {