diff --git a/chrome_point_plus/css/point-plus.css b/chrome_point_plus/css/point-plus.css
index 2364601..edb1010 100644
--- a/chrome_point_plus/css/point-plus.css
+++ b/chrome_point_plus/css/point-plus.css
@@ -124,7 +124,7 @@ div#markItUpText-input {
right: 5px;
top: 5px;
display: none;
- background-image: url("//point.im/img/btn-edit.png");
+ background-image: url('//point.im/img/btn-edit.png');
background-size: 100% 100%;
width: 16px;
height: 16px;
@@ -220,5 +220,40 @@ div#markItUpText-input {
/* "All" link in left menu */
#pp-left-menu-all {
/* Opened Lock icon from default point.im icon set */
- background-image: url("/img/icon-private-inactive.png") !important;
+ background-image: url('/img/icon-private-inactive.png') !important;
+}
+
+/* Highlight post with new comments */
+.pp-post-unread {
+ background-color: #EEFFEE;
+}
+
+/* Video from direct links */
+.pp-video-player {
+ display: block;
+ max-width: 95%;
+}
+
+/* Audio from direct links */
+.pp-audio-player {
+ display: block;
+
+}
+
+/* Coub embedded video */
+.pp-video-player-coub {
+ max-width: 640px;
+ border: none;
+}
+
+/* New posts and comments auto refresh in left menu by @NokitaKaze */
+.pp-left-menu-refreshed {
+ background-color: #f2ebee;
+ color: #7c3558;
+}
+
+#pp-iframe-unread-refresh {
+ width: 600px;
+ height: 300px;
+ display: none;
}
\ No newline at end of file
diff --git a/chrome_point_plus/js/point-plus.js b/chrome_point_plus/js/point-plus.js
index 5693dad..46e3ccc 100644
--- a/chrome_point_plus/js/point-plus.js
+++ b/chrome_point_plus/js/point-plus.js
@@ -23,7 +23,7 @@ function PointPlus(ppVersion) {
console.info('Point+ %s', ppVersion);
// Getting username
- var point_username = $('#name h1').text();
+ var point_username = $('#name').find('h1').text();
// Getting post id
var postId = $('#top-post').attr('data-id');
console.debug('Current post id detected as #%s', postId);
@@ -46,13 +46,15 @@ function PointPlus(ppVersion) {
// Options debug
try {
console.debug('Options loaded: %O', options.getOptions());
- } catch(e){}
+ } catch(e) {
+ console.error('Options load error: %O', e);
+ }
create_tag_system();
// Move "all posts" to left menu
if (options.is('option_other_move_all_to_menu')) {
- $('div.secret a').insertAfter('a#menu-recent').attr({'id': 'pp-left-menu-all'});
+ $('div.secret a').insertAfter('#left-menu #menu-recent').attr({'id': 'pp-left-menu-all'});
}
// Side panel
@@ -71,7 +73,7 @@ function PointPlus(ppVersion) {
$go_to_unread_block = $('
').attr({
id: 'pp-go-to-unread',
}).click(function() {
- var $unread_comment = $('#comments div.post.unread').first();
+ var $unread_comment = $('#comments').find('div.post.unread').first();
if ($unread_comment.length > 0) {
$('html body').animate({ scrollTop: $unread_comment.offset().top }, 500);
@@ -118,9 +120,9 @@ function PointPlus(ppVersion) {
// Parse webm-links and create video instead
if (options.is('option_videos_parse_links')) {
if (options.is('option_videos_parse_links_type', 'all')) {
- parse_all_videos(options);
+ parse_video_links(options, true);
} else {
- parse_webm(options);
+ parse_video_links(options);
}
}
@@ -260,10 +262,12 @@ function PointPlus(ppVersion) {
if (options.is('option_nsfw')) {
$('.post-tag-nsfw,.post-tag-сиськи').find('a.postimg:not(.youtube)').attr('data-fancybox-group', 'hidden-images');
+ $post = $('div.post');
+
if (options.is('option_nsfw_hide_posts')) {
if ($('#comments').length == 0) {
- console.log('Hide NSFW posts in feed, %i hidden', $('div.post').length);
- $('div.post').addClass('hide-nsfw-posts');
+ console.log('Hide NSFW posts in feed, %i hidden', $post.length);
+ $post.addClass('hide-nsfw-posts');
}
}
@@ -277,7 +281,7 @@ function PointPlus(ppVersion) {
}
// Blurred comments
- if ($('div.post').hasClass('post-tag-nsfw') || $('div.post').hasClass('post-tag-сиськи')) {
+ if ($post.hasClass('post-tag-nsfw') || $post.hasClass('post-tag-сиськи')) {
if (options.is('option_nsfw_blur_comments_entire')) {
console.log('Bluring comments');
$('#comments').addClass('blur-nsfw-entire');
@@ -377,7 +381,7 @@ function PointPlus(ppVersion) {
}
// Google search
if (options.is('option_search_with_google')) {
- $('#search-form input[type="text"]').attr('placeholder', 'Google').keydown(function(e) {
+ $('#search-form').find('input[type="text"]').attr('placeholder', 'Google').keydown(function(e) {
if (e.keyCode == 10 || e.keyCode == 13) {
e.preventDefault();
document.location.href = '//www.google.ru/search?q=site%3Apoint.im+' + $(this).val();
@@ -391,7 +395,7 @@ function PointPlus(ppVersion) {
console.log('WebSocket created: %O', ws);
// Detecting view mode
- treeSwitch = $('#tree-switch a.active').attr('href');
+ treeSwitch = $('#tree-switch').children('a.active').attr('href');
console.debug('Comments view mode: %s', treeSwitch);
// Error handler
@@ -469,7 +473,7 @@ function PointPlus(ppVersion) {
author: wsMessage.author,
html: wsMessage.html,
fadeOut: options.is('option_ws_comments_color_fadeout'),
- isRec: (wsMessage.a === 'ok') ? true : false,
+ isRec: (wsMessage.a === 'ok'),
unread: (point_username && point_username !== wsMessage.author) ? true : false,
}, function($comment) {
// It's time to DOM
@@ -480,7 +484,7 @@ function PointPlus(ppVersion) {
console.log('Parent comment: %O', $parentComment || null);
// If list mode or not addressed to other comment
- if ($('#comments #tree-switch a').eq(0).hasClass('active') || (wsMessage.to_comment_id === null) || (!$parentComment.length)) {
+ if (treeSwitch === '?tree=0' || !wsMessage.to_comment_id || !$parentComment.length) {
// Adding to the end of the list
$('.content-wrap #comments #post-reply').before($comment);
} else {
@@ -560,7 +564,6 @@ function PointPlus(ppVersion) {
console.log(e);
console.log(evt.data);
}
- ;
};
}
// Font size
@@ -707,7 +710,7 @@ function create_comment_elements(commentData, onCommentCreated) {
$commentTemplate.find('.action-labels .more-label').attr('for', 'action-' + commentData.postId + '_' + commentData.id);
$commentTemplate.find('.post-content input[name="action-radio"]').attr('id', 'action-' + commentData.postId + '_' + commentData.id);
// Bookmark link
- $commentTemplate.find('.action-buttons a.bookmark').attr('href', $('#top-post .info a').attr('href') + commentData.postId + '/b?comment_id=' + commentData.id + '&csrf_token=' + csRfToken);
+ $commentTemplate.find('.action-buttons a.bookmark').attr('href', $('#top-post').find('.info a').attr('href') + commentData.postId + '/b?comment_id=' + commentData.id + '&csrf_token=' + csRfToken);
// Reply form
$commentTemplate.find('.post-content input.reply-radio').attr('id', 'reply-' + commentData.postId + '_' + commentData.id);
$commentTemplate.find('.post-content form.reply-form').attr('action', '/' + commentData.postId);
@@ -738,7 +741,7 @@ function create_comment_elements(commentData, onCommentCreated) {
* @param {?object} $span jQuery object of unread count
*/
function update_right_panel_unread_count($span) {
- var unread_count = $('#comments div.post.unread').length;
+ var unread_count = $('#comments').children('div.post.unread').length;
if (typeof $span === 'undefined') {
$span = $('#pp-unread-count');
@@ -750,123 +753,139 @@ function update_right_panel_unread_count($span) {
}
// Помечаем непрочитанные посты более видимо чем каким-то баджем
-// Эта часть написана @RainbowSpike
+// Эта часть изначально была написана @RainbowSpike
function mark_unread_post() {
- var divs = $(".content-wrap > div.post").css({'padding-left':'2px'}); // массив постов
- for (var i = 0; i < divs.length; i++) { // обыск постов
- var spans = $(divs[i]).find(".unread"); // поиск метки непрочитанных комментов
- if (spans.length > 0) { // если в посте есть непрочитанные комменты...
- $(divs[i]).css({//...залить пост зеленоватым и скруглить
- 'background-color': '#EEFFEE',
- 'border-radius': '10px'
- });
+ var $posts = $('.content-wrap').children('div.post');
+ $posts.css({'padding-left':'2px'});
+
+ $posts.each(function() {
+ if ($(this).find('.post-id .unread').length > 0) {
+ $(this).addClass('pp-post-unread');
}
+ });
+}
+
+/**
+ * Parse video links in posts
+ *
+ * @param {object} current_options
+ * @param {boolean} all
+ */
+function parse_video_links(current_options, all) {
+ if (typeof all === 'undefined') {
+ all = false;
}
-}
+ var regex;
+
+ if (all) {
+ regex = new RegExp('\\.(webm|avi|mp4|mpg|mpeg)(\\?.+)?$', 'i');
+ } else {
+ regex = new RegExp('\\.(webm)(\\?.+)?$', 'i');
+ }
-// Webm
-function parse_webm(current_options) {
$('.post-content a:not(.booru_pic)').each(function(num, obj) {
-
var href = obj.href;
- var n = null;
+ var matches;
- if (n = href.match(new RegExp('\\.webm(\\?.+)?$', 'i'))) {
+ if (matches = href.match(regex)) {
var player = document.createElement('video');
+ var mime = video_extension_to_mime(matches[1]);
// Там может быть не vp8+vorbis, но мы этого никак не узнаем
- $(player).html('').attr('controls', 'controls').css({
- 'display': 'block',
- 'max-width': '95%'
- }).addClass('parsed-webm-link');
+ $(player)
+ .html('')
+ .attr('controls', 'controls')
+ .addClass('pp-video-player')
+ ;
obj.parentElement.insertBefore(player, obj);
if (current_options.is('option_embedding_remove_original_link')) {
- $(obj).hide();
- }
- }
- });
-}
-
-// Видео
-function parse_all_videos(current_options) {
- $('.post-content a:not(.booru_pic)').each(function(num, obj) {
-
- var href = obj.href;
- var n = null;
-
- if (n = href.match(new RegExp('\\.(webm|avi|mp4|mpg|mpeg)(\\?.+)?$', 'i'))) {
- var player = document.createElement('video');
- var mime = video_extension_to_mime(n[1]);
- $(player).html('').attr('controls', 'controls').css({
- 'display': 'block',
- 'max-width': '95%'
- }).addClass('parsed-webm-link');
-
- obj.parentElement.insertBefore(player, obj);
-
- if (current_options.is('option_embedding_remove_original_link')) {
- $(obj).hide();
+ $(obj).remove();
}
}
});
}
+/**
+ * Detects mime and codecs by file extension
+ *
+ * @param {string} extension
+ * @returns {string}
+ */
function video_extension_to_mime(extension) {
switch (extension) {
- case 'webm':return 'video/webm; codecs="vp8, vorbis';
- case 'avi' :return 'video/avi;';
- case 'mp4' :return 'video/mp4;';
- case 'mpg' :return 'video/mp4;';
- case 'mpeg':return 'video/mp4;';
+ case 'webm':
+ return 'video/webm; codecs="vp8, vorbis"';
+ case 'avi':
+ return 'video/avi;';
+ case 'mp4':
+ return 'video/mp4;';
+ case 'mpg':
+ return 'video/mp4;';
+ case 'mpeg':
+ return 'video/mp4;';
}
}
// Аудио
-function parse_all_audios(current_options){
+function parse_all_audios(current_options) {
+ var regex_all = new RegExp('^https?:\\/\\/([a-z0-9.-]+)\\/[a-z0-9_\\/.%-]+\\.(mp3|ogg|wav)(\\?.+)?$', 'i');
+ var regex_vk = new RegExp('\\.vk\\.me$', 'i');
+
$('.post-content a').each(function(num, obj) {
if ($(obj).hasClass('booru_pic')) {
return;
}
var href = obj.href;
- var n = null;
+ var n;
- if (n = href.match(new RegExp('^https?:\\/\\/([a-z0-9.-]+)\\/[a-z0-9_\\/.%-]+\\.(mp3|ogg|wav)(\\?.+)?$', 'i'))) {
+ if (n = href.match(regex_all)) {
var domain = n[1];
// Проверяем откуда мы грузимся
- if (domain.match(new RegExp('\\.vk\\.me$', 'i'))){
+ if (domain.match(regex_vk)) {
// Так то ж Контакт!
- if (typeof(n[3])=='undefined'){
+ if (typeof(n[3])=='undefined') {
return;
}
- if (!n[3].match('extra\\=', 'i')){
+ if (!n[3].match('extra\\=', 'i')) {
return;
}
}
var player = document.createElement('audio');
var mime = audio_extension_to_mime(n[2]);
- $(player).html('').attr('controls', 'controls').css({
- 'display': 'block',
- 'max-width': '350px'
- }).addClass('parsed-audio-link');
+
+ $(player)
+ .html('')
+ .attr('controls', 'controls')
+ .addClass('pp-audio-player')
+ ;
obj.parentElement.insertBefore(player, obj);
if (current_options.is('option_embedding_remove_original_link')) {
- $(obj).hide();
+ $(obj).remove();
}
}
});
}
+/**
+ * Detects mime and codecs by audio file extension
+ *
+ * @param extension
+ * @returns {*}
+ */
function audio_extension_to_mime(extension) {
switch (extension) {
- case 'mp3': return 'audio/mpeg';
- case 'ogg': return 'audio/ogg; codecs=vorbis';
- case 'wav': return 'audio/vnd.wave';
+ case 'mp3':
+ return 'audio/mpeg';
+ case 'ogg':
+ return 'audio/ogg; codecs="vorbis"';
+ case 'wav':
+ return 'audio/vnd.wave';
}
}
@@ -874,19 +893,21 @@ function audio_extension_to_mime(extension) {
* Показывает количество рекомендаций и комментаторов у постов
*/
function set_posts_count_label() {
- var posts = {};
+ $posts = $('.content-wrap').children('div.post');
+
+ var posts_hash = {};
var ids;
-
- $('.content-wrap > div.post').each(function(n, post) {
+
+ $posts.each(function(n, post) {
var $post = $(post);
var postId = $post.data('id');
- posts[postId] = $post;
+ posts_hash[postId] = $post;
});
- ids = Object.keys(posts);
+ ids = Object.keys(posts_hash);
- $('.content-wrap > div.post .post-id a .cn').addClass('changed_background');
+ $posts.find('.post-id .cn').addClass('changed_background');
$.ajax('https://api.kanaria.ru/point/get_post_info.php?list=' + encodeURIComponent(ids.join(',')), {
dataType: 'json',
@@ -895,15 +916,15 @@ function set_posts_count_label() {
var postInfo = data.list[id];
if (postInfo) {
- posts[id].find('.post-id').after(
+ posts_hash[id].find('.post-id').after(
'' +
' ' +
' ' +
'
'
- )
+ );
- posts[id].find('.pp-unique-comments').text(postInfo.count_comment_unique);
- posts[id].find('.pp-recommendation-count').text(postInfo.count_recommendation);
+ posts_hash[id].find('.pp-unique-comments').text(postInfo.count_comment_unique);
+ posts_hash[id].find('.pp-recommendation-count').text(postInfo.count_recommendation);
}
});
}
@@ -911,10 +932,12 @@ function set_posts_count_label() {
}
function parse_pleercom_links(current_options) {
+ var regex = new RegExp('^https?:\\/\\/pleer\\.com\\/tracks\\/([0-9a-z]+)', 'i');
+
$('.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'));
+ var matches = href.match(regex);
if (matches) {
trackHref = 'http://embed.pleer.com/normal/track?id=' + matches[1] + '&t=grey';
@@ -931,9 +954,11 @@ function parse_pleercom_links(current_options) {
}
// Проставляем теги у постов
+// @todo Переписать блокировку тегов и убрать подобное выставление тегов в виде классов
// @hint В данный момент эта фича используются для NSFW, потом выборку по тегам можно будет использовать много где
function create_tag_system() {
- $('.content-wrap > div.post').each(function() {
+ $('.content-wrap').children('div.post').each(function() {
+ // @todo refactor
var tags = $(this).find('div.tags a.tag');
for (var i = 0; i < tags.length; i++) {
var tag_name = $(tags[i]).html().toLowerCase();
@@ -956,8 +981,7 @@ function set_space_key_skip_handler() {
return;
}
- var k = event.keyCode;
- if (k == 32) {
+ if (32 == event.keyCode) {
space_key_event();
return false;
}
@@ -1013,13 +1037,17 @@ var draft_waiting = false;
* Restore draft from localStorage
*/
function draft_restore() {
+ var $post_form = $('#new-post-form');
+ var $text_input = $post_form.find('#text-input');
+ var $tags_input = $post_form.find('#tags-input');
+
chrome.storage.local.get(['point_draft_text', 'point_draft_tags'], function(items) {
- if ($('#new-post-form #text-input').val() === '') {
- $('#new-post-form #text-input').val(items.point_draft_text);
+ if ($text_input.val() === '') {
+ $text_input.val(items.point_draft_text);
draft_last_text = items.point_draft_text;
}
- if ($('#new-post-form #tags-input').val() === '') {
- $('#new-post-form #tags-input').val(items.point_draft_tags);
+ if ($tags_input.val() === '') {
+ $tags_input.val(items.point_draft_tags);
draft_last_tags = items.point_draft_tags;
}
});
@@ -1038,7 +1066,7 @@ function draft_set_save_handler() {
}
});
// Adding span indicator
- $('#new-post-wrap .footnote').append($(''));
+ $('#new-post-wrap').find('.footnote').append($(''));
}
/**
@@ -1055,8 +1083,10 @@ function draft_save_check() {
}
}
- var current_text = $('#new-post-form #text-input').val();
- var current_tags = $('#new-post-form #tags-input').val();
+ var $post_form = $('#new-post-form');
+
+ var current_text = $post_form.find('#text-input').val();
+ var current_tags = $post_form.find('#tags-input').val();
if ((draft_last_text === current_text) && (draft_last_tags === current_tags)) {
draft_save_busy = false;
@@ -1065,7 +1095,7 @@ function draft_save_check() {
draft_save_busy = true;
draft_save_last_time = new Date();
-
+
// @todo i18n
$('#draft-save-status').text(chrome.i18n.getMessage('msg_saving_post_draft')).show();
@@ -1091,34 +1121,40 @@ function draft_save_check() {
// Парсим ссылки на coub
function parse_coub_links(current_options) {
+ var regex = new RegExp('^https?:\\/\\/coub\\.com\\/view\\/([0-9a-z]+)', 'i');
+
$('.post-content a').each(function(num, obj) {
var href = obj.href;
- var n = null;
+ var matches;
- if (n = href.match(new RegExp('^https?:\\/\\/coub\\.com\\/view\\/([0-9a-z]+)', 'i'))) {
+ if (matches = href.match(regex)) {
var player = document.createElement('iframe');
var parent_width = $(obj.parentElement).width();
- $(player).attr({
- 'src': 'https://coub.com/embed/' + n[1] + '?muted=false&autostart=false&originalSize=false&hideTopBar=false&startWithHD=true',
- 'allowfullscreen': 'true'
- }).css({
- 'max-width': '640px',
- 'border': 'none',
- 'width': Math.floor(parent_width * 0.9),
- 'height': Math.ceil(parent_width * 0.9 * 480 / 640)
- }).addClass('embeded_video').addClass('embeded_video_' + n[1]);
+ $(player)
+ .attr({
+ 'src': 'https://coub.com/embed/' + matches[1] + '?muted=false&autostart=false&originalSize=false&hideTopBar=false&startWithHD=true',
+ 'allowfullscreen': 'true'
+ })
+ .css({
+ 'width': Math.floor(parent_width * 0.9),
+ 'height': Math.ceil(parent_width * 0.9 * 480 / 640)
+ })
+ .addClass('pp-video-player-coub')
+ .addClass('embeded_video')
+ .addClass('embeded_video_' + matches[1])
+ ;
obj.parentElement.insertBefore(player, obj);
if (current_options.is('option_embedding_remove_original_link')) {
- $(obj).hide();
+ $(obj).remove();
}
}
});
}
// Правим хинт в FancyBox
-function fancybox_set_smart_hints(){
+function fancybox_set_smart_hints() {
$('div.post').each(function() {
var all_post_images = $(this).find('.postimg');
if (all_post_images.length == 0) {
@@ -1209,8 +1245,8 @@ function hints_draw_main_user_hint(items) {
}
var current_user_hint_block = document.createElement('div');
- $('.aside .aside-content #counters')[0].parentElement.
- insertBefore(current_user_hint_block, $('.aside .aside-content #counters')[0]);
+ var $counters = $('.aside-content #counters');
+ $counters[0].parentElement.insertBefore(current_user_hint_block, $counters[0]);
$(current_user_hint_block).addClass('current-user-hint');
// Рисуем кнопки управления
@@ -1270,17 +1306,19 @@ function safe_saned_text(text, object) {
// Рисуем title'ы на всех доступных пользователях, точнее на их аватарках
function hints_set_titles_on_users(items) {
+ var regex = new RegExp('^https?\\://([0-9a-z-]+)\\.point\\.im/$', 'i');
+
$('a').each(function() {
var href = $(this).attr('href');
if (typeof(href) == 'undefined') {
return;
}
- var n = href.match(new RegExp('^https?\\://([0-9a-z-]+)\\.point\\.im/$', 'i'));
- if (n == null) {
+ var matches = href.match(regex);
+ if (matches == null) {
return;
}
- var this_user_name = n[1].toLowerCase();
+ var this_user_name = matches[1].toLowerCase();
if (typeof(items[this_user_name]) == 'undefined') {
return;
}
@@ -1304,11 +1342,15 @@ function hints_save_new_hint(username, new_hint) {
*/
function set_comments_refresh_tick(current_options) {
// Проверяем, чтобы были баджи
- if ($('#main #left-menu #menu-recent .unread').length == 0) {
- $('#main #left-menu #menu-recent').append('0');
+ var $left_menu = $('#left-menu');
+ var $menu_recent_posts = $left_menu.find('#menu-recent');
+ var $menu_recent_comments = $left_menu.find('#menu-comments');
+
+ if ($menu_recent_posts.children('.unread').length == 0) {
+ $menu_recent_posts.append('0');
}
- if ($('#main #left-menu #menu-comments .unread').length == 0) {
- $('#main #left-menu #menu-comments').append('0');
+ if ($menu_recent_comments.children('.unread').length == 0) {
+ $menu_recent_comments.append('0');
}
// Ставим тик
@@ -1338,78 +1380,72 @@ var window_focused = true;
// Очищаем [0; 0]
function set_comments_refresh_clear_title_marks() {
- var new_title = document.title.replace(new RegExp('^\\[[0-9]+\\; [0-9]+\\] '), '');
- document.title = new_title;
+ document.title = document.title.replace(new RegExp('^\\[[0-9]+\\; [0-9]+\\] '), '');
window_focused = true;
}
// Проверка обновления комментариев, обновляется по крону
function comments_count_refresh_tick(current_options) {
- $('#debug_iframe').remove();
+ $('#pp-iframe-unread-refresh').remove();
+
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
- $(iframe).on('load', function() {
- var a = $(iframe.contentDocument.body).find('#main #left-menu #menu-recent .unread');
- var b = $(iframe.contentDocument.body).find('#main #left-menu #menu-comments .unread');
- var count_recent = (a.length == 0) ? 0 : parseInt(a.text());
- var count_comments = (b.length == 0) ? 0 : parseInt(b.text());
+ $(iframe)
+ .on('load', function() {
+ var a = $(iframe.contentDocument.body).find('#main #left-menu #menu-recent .unread');
+ var b = $(iframe.contentDocument.body).find('#main #left-menu #menu-comments .unread');
+ var count_recent = (a.length == 0) ? 0 : parseInt(a.text());
+ var count_comments = (b.length == 0) ? 0 : parseInt(b.text());
- console.log('Comments: %d, Recent: %d', count_comments, count_recent);
- if (count_recent > 0) {
- if (parseInt($('#main #left-menu #menu-recent .unread').text()) != count_recent) {
- $('#main #left-menu #menu-recent .unread').text(count_recent).show().css({
- 'background-color': '#f2ebee',
- 'color': '#7c3558'
- });
- setTimeout(function() {
- $('#main #left-menu #menu-recent .unread').css({
- 'background-color': '',
- 'color': ''
- });
- }, 15000);
+ console.log('Comments: %d, Recent: %d', count_comments, count_recent);
+
+ var $menu = $('#left-menu');
+ var $menu_posts = $menu.children('#menu-recent');
+ var $menu_posts_unread = $menu_posts.children('span.unread');
+ var $menu_comments = $menu.children('#menu-comments');
+ var $menu_comments_unread = $menu_comments.children('span.unread');
+
+ if (count_recent > 0) {
+ if (parseInt($menu_posts_unread.text()) != count_recent) {
+ $menu_posts_unread.text(count_recent).show().addClass('pp-left-menu-refreshed');
+ setTimeout(function() {
+ $menu_posts_unread.removeClass('pp-left-menu-refreshed');
+ }, 15000);
+ }
+ } else {
+ $menu_posts_unread.text('0').hide();
}
- } else {
- $('#main #left-menu #menu-recent .unread').text('0').hide();
- }
- if (count_comments > 0) {
- if (parseInt($('#main #left-menu #menu-comments .unread').text()) != count_comments) {
- $('#main #left-menu #menu-comments .unread').text(count_comments).show().css({
- 'background-color': '#f2ebee',
- 'color': '#7c3558'
- });
- setTimeout(function() {
- $('#main #left-menu #menu-comments .unread').css({
- 'background-color': '',
- 'color': ''
- });
- }, 15000);
+ if (count_comments > 0) {
+ if (parseInt($menu_comments_unread.text()) != count_comments) {
+ $menu_comments_unread.text(count_comments).show().addClass('pp-left-menu-refreshed');
+ setTimeout(function() {
+ $menu_comments_unread.removeClass('pp-left-menu-refreshed');
+ }, 15000);
+ }
+ } else {
+ $menu_comments_unread.text('0').hide();
}
- } else {
- $('#main #left-menu #menu-comments .unread').text('0').hide();
- }
- if ((current_options.is('option_other_comments_count_refresh_title')) &&
- (!window_focused)) {
- var new_title = document.title.replace(new RegExp('^\\[[0-9]+\\; [0-9]+\\] '), '');
- if ((count_recent > 0) || (count_comments > 0)) {
- new_title = '[' + count_recent + '; ' + count_comments + '] ' + new_title;
+ if ((current_options.is('option_other_comments_count_refresh_title')) && (!window_focused)) {
+ var new_title = document.title.replace(new RegExp('^\\[[0-9]+\\; [0-9]+\\] '), '');
+ if ((count_recent > 0) || (count_comments > 0)) {
+ new_title = '[' + count_recent + '; ' + count_comments + '] ' + new_title;
+ }
+ document.title = new_title;
}
- document.title = new_title;
- }
- $('#debug_iframe').remove();
- }).attr({
- // Из-за Same Origin'а я дёргаю несуществующую страницу на том же домене, чтобы получить баджи и,
- // в то же время не прочитать новые сообщения в ленте, которые могли появиться, если их написал
- // этот пользователь
- 'src': '//' + document.domain + '/?tag=' + Math.random(),
- 'id': 'debug_iframe'
- }).css({
- 'width': '600px',
- 'height': '300px'
- }).hide();
+ $('#pp-iframe-unread-refresh').remove();
+ })
+ .attr({
+ // Из-за Same Origin'а я дёргаю несуществующую страницу на том же домене, чтобы получить баджи и,
+ // в то же время не прочитать новые сообщения в ленте, которые могли появиться, если их написал
+ // этот пользователь
+ 'src': '//' + document.domain + '/?tag=' + Math.random(),
+ 'id': 'pp-iframe-unread-refresh'
+ })
+ ;
}
/**
@@ -1458,13 +1494,15 @@ function twitter_tweet_embedding_wait_for_ready_injected() {
* Парсим все ссылки. Эта функция запускается из page scope
*/
function twitter_tweet_embedding_parse_links() {
+ var regex = new RegExp('^https?://(www\\.)?twitter\\.com/[^/]+/status/([0-9]+)', 'i');
+
// Обрабатываем все твиты
var twitter_tweet_count = 0;
$('.post-content a:not(.booru_pic)').each(function(num, obj) {
var href = obj.href;
var n;
- if (n = href.match(new RegExp('^https?://(www\\.)?twitter\\.com/[^/]+/status/([0-9]+)', 'i'))) {
+ if (n = href.match(regex)) {
var tweet = document.createElement('div');
$(tweet).attr({
'id': 'tweet-' + twitter_tweet_count,