2014-11-26 19:00:32 +00:00
// Showing page action
chrome . extension . sendMessage ( {
type : 'showPageAction'
} ) ;
2014-11-23 09:10:35 +00:00
$ ( document ) . ready ( function ( ) {
2014-04-01 20:37:30 +00:00
// Grouping console log
console . group ( 'point-plus' ) ;
2014-04-04 21:12:11 +00:00
console . info ( 'Point+ %s' , getVersion ( ) ) ;
2014-11-26 19:00:32 +00:00
2014-11-22 12:15:22 +00:00
// Проверяем, загрузились ли мы
2014-11-26 20:24:34 +00:00
var point _plus _debug = $ ( '#point-plus-debug' ) ;
if ( point _plus _debug . length > 0 ) {
console . error ( 'Point+ %s already loaded.' , point _plus _debug . data ( 'point-plus-version' ) ) ;
2014-11-22 12:15:22 +00:00
return ;
}
2014-11-26 20:24:34 +00:00
$ ( '<div id="point-plus-debug">' ) . attr ( {
2014-11-24 13:20:19 +00:00
'data-point-plus-version' : getVersion ( )
2014-11-26 20:24:34 +00:00
} ) . text ( 'Point+ ' + getVersion ( ) + ' loading...' )
. insertBefore ( '#user-menu-cb' ) ;
2014-11-24 13:20:19 +00:00
// Черновики. Ставим хандлер и восстанавливаем предыдущее состояние
draft _set _save _handler ( ) ;
draft _restore ( ) ;
2014-11-22 12:15:22 +00:00
2014-03-11 14:48:26 +00:00
// Loading options
2014-11-26 19:00:32 +00:00
chrome . storage . sync . get ( 'options' , function ( sync _data ) {
var options = sync _data . options ;
2014-11-15 10:08:53 +00:00
2014-04-04 00:21:01 +00:00
// Options debug
2014-11-25 13:43:21 +00:00
try {
2014-11-26 20:52:47 +00:00
console . debug ( 'Options loaded: %O' , options ) ;
} catch ( e ) { }
2014-11-21 15:49:12 +00:00
create _tag _system ( ) ;
2014-11-15 10:08:53 +00:00
// Embedding
2014-11-23 21:01:33 +00:00
if ( options . option _embedding . value == true ) {
2014-11-15 10:08:53 +00:00
// Load pictures from Booru, Tumblr and some other sites
2014-11-23 21:01:33 +00:00
if ( options . option _images _load _booru . value == true ) {
2014-11-15 10:08:53 +00:00
load _all _booru _images ( ) ;
}
2014-11-25 13:02:39 +00:00
2014-11-15 10:08:53 +00:00
// Parse webm-links and create video instead
2014-11-26 20:48:08 +00:00
if ( options . option _videos _parse _links . value == true ) {
if ( options . option _videos _parse _links _type . value == "all" ) {
2014-11-26 20:52:47 +00:00
parse _all _videos ( options ) ;
2014-11-21 15:49:12 +00:00
} else {
2014-11-26 20:52:47 +00:00
parse _webm ( options ) ;
2014-11-21 15:49:12 +00:00
}
2014-11-15 10:08:53 +00:00
}
2014-11-16 10:27:54 +00:00
2014-11-25 13:02:39 +00:00
// Parse audio links
if ( options . option _audios _parse _links . value == true ) {
2014-11-26 20:52:47 +00:00
parse _all _audios ( options ) ;
2014-11-25 13:02:39 +00:00
}
2014-11-16 02:01:31 +00:00
// Soundcloud
2014-11-23 21:01:33 +00:00
if ( options . option _embedding _soundcloud . value == true ) {
2014-11-16 02:01:31 +00:00
// Injecting JS API
chrome . extension . sendMessage ( {
type : 'injectJSFile' ,
file : 'js/soundcloud/soundcloud.player.api.js'
} ) ;
2014-11-16 10:27:54 +00:00
2014-11-16 02:01:31 +00:00
// Processing links
2014-11-23 21:01:33 +00:00
$ ( '.post .post-content a[href*="\\:\\/\\/soundcloud\\.com\\/"]' ) . each ( function ( index ) {
2014-11-16 02:01:31 +00:00
console . log ( $ ( this ) ) ;
2014-11-16 10:27:54 +00:00
2014-11-26 21:39:45 +00:00
// @todo: вынести в отдельный шаблон
2014-11-16 02:01:31 +00:00
$player = $ ( ' < div class = "pp-soundcloud" > \
< object height = "81" width = "100%" id = "pp-soundcloud-' + index + '" classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" > \
2014-11-16 18:32:47 +00:00
< param name = "movie" value = " //player.soundcloud.com/player.swf?url=' + encodeURIComponent($(this).prop('href'))
2014-11-23 09:10:35 +00:00
+ '&enable_api=true&object_id=pp-soundcloud-' + index + ' " > \
2014-11-16 10:27:54 +00:00
< param name = "allowscriptaccess" value = "always" > \
2014-11-16 18:32:47 +00:00
< embed allowscriptaccess = "always" height = "81" src = " //player.soundcloud.com/player.swf?url='
2014-11-23 09:10:35 +00:00
+ encodeURIComponent ( $ ( this ) . prop ( 'href' ) ) + '&enable_api=true&object_id=pp-soundcloud-' + index
+ '" type="application/x-shockwave-flash" width="100%" name="pp-soundcloud-' + index + ' " > < / e m b e d > \
2014-11-16 02:01:31 +00:00
< / o b j e c t > \
< / d i v > ' ) ;
2014-11-16 10:27:54 +00:00
2014-11-16 02:01:31 +00:00
// Replace or prepend
2014-11-23 21:01:33 +00:00
if ( options . option _embedding _soundcloud _orig _link . value == true ) {
2014-11-16 02:01:31 +00:00
// Before
$ ( this ) . before ( $player ) ;
} else {
// Replace
$ ( this ) . replaceWith ( $player ) ;
}
} ) ;
2014-11-16 10:27:54 +00:00
}
2014-11-26 20:48:08 +00:00
// Parse pleer.com links and create audio instead
2014-11-23 21:01:33 +00:00
if ( options . option _embedding _pleercom . value == true ) {
2014-11-26 20:52:47 +00:00
parse _pleercom _links ( options ) ;
2014-11-16 02:01:31 +00:00
}
2014-11-25 13:43:21 +00:00
// Parse coub.com links and create iframe instead
if ( options . option _embedding _coubcom . value == true ) {
2014-11-26 20:52:47 +00:00
parse _coub _links ( options ) ;
2014-11-16 02:01:31 +00:00
}
2014-11-15 10:08:53 +00:00
}
2014-03-14 12:16:06 +00:00
// Fancybox
2014-11-23 21:01:33 +00:00
if ( options . option _fancybox . value == true ) {
if ( options . option _fancybox _bind _images _to _one _flow . value == true ) {
2014-04-03 21:48:37 +00:00
// Linking images in posts to the galleries
2014-11-23 21:01:33 +00:00
$ ( '.post-content .text' ) . each ( function ( ) {
2014-11-21 16:56:28 +00:00
$ ( this ) . find ( 'a.postimg:not(.youtube)' ) . attr ( 'data-fancybox-group' , 'one_flow_gallery' ) ;
2014-04-03 21:48:37 +00:00
} ) ;
2014-12-30 13:59:26 +00:00
} else {
2014-12-26 06:45:36 +00:00
$ ( '.post-content .text' ) . each ( function ( idxPost ) {
$ ( this ) . find ( 'a.postimg:not(.youtube)' ) . attr ( 'data-fancybox-group' , 'post' + idxPost ) ;
} ) ;
2014-11-15 10:08:53 +00:00
}
// Images
2014-11-23 21:01:33 +00:00
if ( options . option _fancybox _images . value == true ) {
2014-04-03 21:48:37 +00:00
// Init fancybox
2014-11-15 10:08:53 +00:00
$ ( '.postimg:not(.youtube)' ) . fancybox ( {
type : 'image'
} ) ;
2014-04-03 21:48:37 +00:00
}
2014-11-22 12:15:22 +00:00
2014-12-26 06:45:36 +00:00
// Правим хинты у фансибокса
if ( options . option _fancybox _smart _hints . value == true ) {
fancybox _set _smart _hints ( ) ;
} else {
$ ( '.post .postimg' ) . attr ( 'data-fancybox-title' , ' ' ) ;
}
2014-11-21 16:56:28 +00:00
2014-04-03 21:48:37 +00:00
// Videos
2014-11-23 21:01:33 +00:00
if ( options . option _fancybox _videos . value == true ) {
2014-04-03 21:48:37 +00:00
$ ( '.postimg.youtube' ) . addClass ( 'fancybox-media' ) . fancybox ( {
helpers : {
media : {
youtube : {
params : {
autoplay : 1
}
2014-03-11 14:48:26 +00:00
}
}
}
2014-04-03 21:48:37 +00:00
} ) ;
}
// Posts
2014-11-23 21:01:33 +00:00
if ( options . option _fancybox _posts . value == true ) {
2014-11-15 01:49:53 +00:00
// Excluding some sort of piece-of-shit makeup
$ ( '.post-id a' ) . not ( '#comments .post-id a, #top-post .post-id a' ) . attr ( 'data-fancybox-type' , 'iframe' ) . fancybox ( {
2014-04-03 21:48:37 +00:00
maxWidth : 780
} ) ;
}
2014-03-14 12:16:06 +00:00
}
2014-11-21 15:49:12 +00:00
2014-11-20 16:47:47 +00:00
// NSFW Filtering
2014-11-23 21:01:33 +00:00
if ( options . option _nsfw . value == true ) {
2014-11-21 16:56:28 +00:00
$ ( '.post-tag-nsfw,.post-tag-сиськи' ) . find ( 'a.postimg:not(.youtube)' ) . attr ( 'data-fancybox-group' , 'hidden-images' ) ;
2014-11-23 21:01:33 +00:00
if ( options . option _nsfw _hide _posts . value == true ) {
2014-11-22 12:15:22 +00:00
if ( $ ( '#comments' ) . length == 0 ) {
2014-12-30 13:59:26 +00:00
console . log ( 'Hide NSFW posts in feed, %i hidden' , $ ( '.post' ) . length ) ;
2014-11-21 15:49:12 +00:00
$ ( '.post' ) . addClass ( 'hide-nsfw-posts' ) ;
}
2014-11-26 20:52:47 +00:00
}
// Blurred posts
if ( options . option _nsfw _blur _posts _entire . value == true ) {
console . log ( 'Bluring NSFW posts' ) ;
$ ( '.post' ) . addClass ( 'blur-nsfw-entire' ) ;
} else if ( options . option _nsfw _blur _posts _images . value == true ) {
console . log ( 'Bluring images in NSFW posts' ) ;
$ ( '.post' ) . addClass ( 'blur-nsfw-images' ) ;
2014-11-22 12:15:22 +00:00
}
2014-11-21 15:49:12 +00:00
2014-11-22 12:15:22 +00:00
// Blurred comments
if ( $ ( '.post' ) . hasClass ( 'post-tag-nsfw' ) || $ ( '.post' ) . hasClass ( 'post-tag-сиськи' ) ) {
2014-11-23 21:01:33 +00:00
if ( options . option _nsfw _blur _comments _entire . value == true ) {
2014-11-22 12:15:22 +00:00
console . log ( 'Bluring comments' ) ;
$ ( '#comments' ) . addClass ( 'blur-nsfw-entire' ) ;
2014-11-23 21:01:33 +00:00
} else if ( options . option _nsfw _blur _comments _images . value == true ) {
2014-11-22 12:15:22 +00:00
// @hint Никита Ветров официально складывает с себя все претензии, если у кого-то от этого говна упадёт драйвер видео-карты
console . log ( 'Bluring images in comments' ) ;
$ ( '#comments' ) . addClass ( 'blur-nsfw-images' ) ;
2014-11-21 15:49:12 +00:00
}
2014-11-20 16:47:47 +00:00
}
}
2014-11-21 15:49:12 +00:00
2014-03-19 17:43:04 +00:00
// Hotkeys
2014-03-11 14:48:26 +00:00
// Send by CTRL+Enter
2014-11-23 21:01:33 +00:00
if ( options . option _ctrl _enter . value == true ) {
2014-03-20 01:55:21 +00:00
// Reply
2014-04-04 21:12:11 +00:00
// Delegated event for all comments
2014-11-23 21:01:33 +00:00
$ ( '.content-wrap #comments' ) . on ( 'keydown.point_plus' , '.reply-form textarea' , function ( e ) {
2014-03-11 14:48:26 +00:00
if ( e . ctrlKey && ( e . keyCode == 10 || e . keyCode == 13 ) ) {
e . preventDefault ( ) ;
$ ( this ) . parent ( '.reply-form' ) . submit ( ) ;
2014-03-20 01:55:21 +00:00
}
} ) ;
// New post
2014-11-23 21:01:33 +00:00
$ ( '#new-post-form #text-input,#new-post-form #tags-input' ) . on ( 'keydown.point_plus' , function ( e ) {
2014-03-20 01:55:21 +00:00
if ( e . ctrlKey && ( e . keyCode == 10 || e . keyCode == 13 ) ) {
e . preventDefault ( ) ;
$ ( this ) . parent ( '#new-post-form' ) . submit ( ) ;
2014-03-11 14:48:26 +00:00
}
} ) ;
}
2014-03-19 17:43:04 +00:00
// Look and feel
// Fluid #main layout
2014-11-23 21:01:33 +00:00
if ( options . option _fluid _layout . value == true ) {
2014-03-20 04:36:40 +00:00
$ ( '#main, #header, #subheader, #footer' ) . css ( {
2014-03-19 17:43:04 +00:00
'width' : '95%' ,
'max-width' : '95%'
} ) ;
2014-03-20 04:36:40 +00:00
// TODO: fix #main #left-menu #top-link position
2014-03-19 17:43:04 +00:00
}
// Image resizing
2014-11-23 21:01:33 +00:00
if ( options . option _images _load _original . value == true ) {
2014-03-19 17:43:04 +00:00
// Setting new image source
2014-11-23 09:10:35 +00:00
$ ( '.postimg:not(.youtube) img' ) . each ( function ( ) {
2014-03-19 17:43:04 +00:00
console . log ( $ ( this ) . parent ( '.postimg' ) . attr ( 'href' ) ) ;
$ ( this ) . attr ( 'src' , $ ( this ) . parent ( '.postimg' ) . attr ( 'href' ) ) ;
} ) ;
// Resizing
2014-03-20 01:22:28 +00:00
$ ( '.postimg:not(.youtube), .postimg:not(.youtube) img' ) . css ( {
2014-03-19 17:43:04 +00:00
'width' : 'auto' ,
'height' : 'auto' ,
'max-width' : '100%' ,
'max-height' : '100%'
} ) ;
}
2014-03-20 21:05:11 +00:00
// Visual editor
2014-11-23 21:01:33 +00:00
if ( options . option _visual _editor _post . value == true ) {
2014-03-20 04:36:40 +00:00
// Add classes
$ ( '#new-post-form #text-input, .post-content #text-input' ) . addClass ( 'markitup' ) . css ( 'height' , '20em' ) ;
// Init
$ ( '.markitup' ) . markItUp ( mySettings ) ;
2014-04-04 00:21:01 +00:00
2014-03-20 21:05:11 +00:00
// Send by CTRL+Enter
2014-11-23 21:01:33 +00:00
if ( options . option _ctrl _enter . value == true ) {
2014-03-20 21:05:11 +00:00
// New post
2014-11-23 09:10:35 +00:00
$ ( '#new-post-form #text-input, .post-content #text-input' ) . on ( 'keydown.point_plus' , function ( e ) {
2014-03-20 21:05:11 +00:00
if ( e . ctrlKey && ( e . keyCode == 10 || e . keyCode == 13 ) ) {
e . preventDefault ( ) ;
$ ( this ) . parents ( '#new-post-form,#post-edit-form' ) . submit ( ) ;
}
} ) ;
}
2014-03-20 04:36:40 +00:00
}
// Google search
2014-11-23 21:01:33 +00:00
if ( options . option _search _with _google . value == true ) {
2014-11-23 09:10:35 +00:00
$ ( '#search-form input[type="text"]' ) . attr ( 'placeholder' , 'Google' ) . keydown ( function ( e ) {
2014-03-20 04:36:40 +00:00
if ( e . keyCode == 10 || e . keyCode == 13 ) {
e . preventDefault ( ) ;
document . location . href = '//www.google.ru/search?q=site%3Apoint.im+' + $ ( this ) . val ( ) ;
}
} ) ;
}
2014-04-01 20:37:30 +00:00
// WebSocket
2014-11-23 21:01:33 +00:00
if ( options . option _ws . value == true ) {
2014-04-04 00:21:01 +00:00
// SSL or plain
ws = new WebSocket ( ( ( location . protocol == 'https:' ) ? 'wss' : 'ws' ) + '://point.im/ws' ) ;
console . log ( 'WebSocket created: %O' , ws ) ;
2014-11-24 14:57:34 +00:00
// @todo: унести в опцию
// Adding event listener for notification click
chrome . extension . sendMessage ( {
type : 'listenNotificationClicks' ,
protocol : getProtocol ( )
} ) ;
2014-11-21 15:49:12 +00:00
2014-04-04 00:21:01 +00:00
// Detecting post id if presented
var postId = $ ( '#top-post' ) . attr ( 'data-id' ) ;
console . debug ( 'Current post id detected as #%s' , postId ) ;
// Detecting view mode
treeSwitch = $ ( '#tree-switch a.active' ) . attr ( 'href' ) ;
console . debug ( 'Comments view mode: %s' , treeSwitch ) ;
2014-11-21 15:49:12 +00:00
2014-04-04 00:21:01 +00:00
// Error handler
2014-11-23 21:01:33 +00:00
ws . onerror = function ( err ) {
2014-04-04 00:21:01 +00:00
console . error ( 'WebSocket error: %O' , err ) ;
} ;
2014-11-21 15:49:12 +00:00
2014-04-04 00:21:01 +00:00
// Message handler
2014-11-23 09:10:35 +00:00
ws . onmessage = function ( evt ) {
2014-04-04 00:21:01 +00:00
try {
// ping :)
if ( evt . data == 'ping' ) {
console . debug ( 'ws-ping' ) ;
} else {
var wsMessage = JSON . parse ( evt . data ) ;
if ( wsMessage . hasOwnProperty ( 'a' ) && wsMessage . a != '' ) {
switch ( wsMessage . a ) {
// Comments
case 'comment' :
console . groupCollapsed ( 'ws-comment #%s/%s' , wsMessage . post _id , wsMessage . comment _id ) ;
console . debug ( wsMessage ) ;
// Check option
2014-11-23 21:01:33 +00:00
if ( options . option _ws _comments . value != true ) {
2014-04-04 00:21:01 +00:00
console . log ( 'Comments processing disabled' ) ;
console . groupEnd ( ) ;
break ;
}
// Check we are in the post
if ( $ ( '#top-post' ) . length < 1 ) {
console . log ( 'Not in the post, skipping' ) ;
console . groupEnd ( ) ;
break ;
}
2014-11-21 15:49:12 +00:00
2014-04-04 00:21:01 +00:00
// Check we are in specified post
if ( wsMessage . post _id != postId ) {
console . log ( 'The comment is for #%s but current page is for #%s' , wsMessage . post _id , postId ) ;
console . groupEnd ( ) ;
break ;
}
2014-11-21 15:49:12 +00:00
2014-04-03 21:48:37 +00:00
var $anchor = $ ( '<a>' ) . attr ( 'name' , wsMessage . comment _id ) ;
// Initializing comment element
var $commentTemplate = $ ( '<div>' ) . attr ( {
'class' : 'post' ,
'data-id' : postId ,
2014-04-04 00:21:01 +00:00
'data-comment-id' : wsMessage . comment _id ,
'data-to-comment-id' : ( wsMessage . to _comment _id != null ) ? wsMessage . to _comment _id : ''
2014-04-03 21:48:37 +00:00
} ) ;
2014-11-24 14:57:34 +00:00
// @todo: Вынести в отдельную функцию
2014-04-03 21:48:37 +00:00
// Loading HTML template
2014-11-23 09:10:35 +00:00
$commentTemplate . load ( chrome . extension . getURL ( 'includes/comment.html' ) , function ( ) {
2014-04-03 21:48:37 +00:00
// Load complete
2014-04-04 00:21:01 +00:00
console . info ( 'comment.html loaded' ) ;
2014-04-03 21:48:37 +00:00
// Date and time of comment
var date = new Date ( ) ;
2014-11-24 14:57:34 +00:00
// @todo: унести наверх
2014-04-03 21:48:37 +00:00
// Data for template
2014-04-03 21:57:37 +00:00
var userLink = '//' + wsMessage . author + '.point.im/' ;
2014-04-03 21:48:37 +00:00
var postAuthorLink = $ ( '#top-post .info a' ) . attr ( 'href' ) ;
var postLink = postAuthorLink + wsMessage . post _id ;
2014-04-03 21:57:37 +00:00
var userAvatar = '//point.im/avatar/' + wsMessage . author ;
var commentLink = '//point.im/' + wsMessage . post _id + '#' + wsMessage . comment _id ;
2014-04-03 21:48:37 +00:00
var csRfToken = $ ( '.reply-form input[name="csrf_token"' ) . val ( ) ;
2014-11-24 14:57:34 +00:00
2014-04-03 21:48:37 +00:00
// Filling template
2014-04-04 00:21:01 +00:00
console . info ( 'Changing data in the comment element' ) ;
2014-04-03 21:48:37 +00:00
// Date and time
$commentTemplate . find ( '.info .created' )
2014-11-21 15:49:12 +00:00
. append ( $ ( '<span>' ) . html ( ( ( date . getDate ( ) . toString . length < 2 ) ? ( '0' + date . getDate ( ) . toString ( ) ) : ( date . getDate ( ) . toString ( ) ) ) + ' ' + months [ date . getMonth ( ) ] ) )
// Crutchy fix
. append ( $ ( '<br>' ) )
///Crutchy fix
. append ( $ ( '<span>' ) . html ( date . getHours ( ) + ':' + ( ( date . getMinutes ( ) . toString ( ) . length < 2 ) ? ( '0' + date . getMinutes ( ) . toString ( ) ) : ( date . getMinutes ( ) . toString ( ) ) ) ) ) ;
2014-04-03 21:48:37 +00:00
// Comment text
$commentTemplate . find ( '.text' ) . append ( $ ( '<p>' ) . html ( escapeHtml ( wsMessage . text ) ) ) ;
// Author
$commentTemplate . find ( '.author a.user' ) . attr ( 'href' , userLink ) . html ( wsMessage . author ) ;
// Avatar and link
$commentTemplate . find ( '.info a' ) . attr ( 'href' , userLink ) . children ( 'img.avatar' ) . attr ( 'src' , userAvatar + '/24' ) ;
// Post and comment ID's link
$commentTemplate . find ( '.clearfix .post-id a' ) . attr ( 'href' , commentLink ) . html ( '#' + wsMessage . post _id + '/' + wsMessage . comment _id )
2014-11-21 15:49:12 +00:00
// Adding answer label
. after ( ( wsMessage . to _comment _id !== null ) ? ( ' в ответ на <a href="#' + wsMessage . to _comment _id + '">/' + wsMessage . to _comment _id + '</a>' ) : ( '' ) ) ;
2014-04-03 21:48:37 +00:00
// Setting action labels and other attributes
$commentTemplate . find ( '.action-labels .reply-label' ) . attr ( 'for' , 'reply-' + wsMessage . post _id + '_' + wsMessage . comment _id ) ;
$commentTemplate . find ( '.action-labels .more-label' ) . attr ( 'for' , 'action-' + wsMessage . post _id + '_' + wsMessage . comment _id ) ;
$commentTemplate . find ( '.post-content input[name="action-radio"]' ) . attr ( 'id' , 'action-' + wsMessage . post _id + '_' + wsMessage . comment _id ) ;
// Bookmark link
$commentTemplate . find ( '.action-buttons a.bookmark' ) . attr ( 'href' , postLink + '/b?comment_id=' + wsMessage . comment _id + '&csrf_token=' + csRfToken ) ;
// Reply form
$commentTemplate . find ( '.post-content input.reply-radio' ) . attr ( 'id' , 'reply-' + wsMessage . post _id + '_' + wsMessage . comment _id ) ;
$commentTemplate . find ( '.post-content form.reply-form' ) . attr ( 'action' , '/' + wsMessage . post _id ) ;
$commentTemplate . find ( '.post-content form.reply-form textarea[name="text"]' ) . html ( '@' + wsMessage . author + ', ' ) ;
$commentTemplate . find ( '.post-content form.reply-form input[name="comment_id"]' ) . val ( wsMessage . comment _id ) ;
$commentTemplate . find ( '.post-content form.reply-form input[name="csrf_token"]' ) . val ( csRfToken ) ;
///Filling template
2014-04-04 00:21:01 +00:00
// It's time to DOM
console . info ( 'Inserting comment' ) ;
// If list mode or not addressed to other comment
if ( ( treeSwitch == '?tree=0' ) || ( wsMessage . to _comment _id == null ) ) {
// List mode
2014-04-04 01:35:09 +00:00
$ ( '.content-wrap #comments #post-reply' ) . before ( $commentTemplate . hide ( ) . fadeIn ( 2000 ) ) ;
2014-04-04 00:21:01 +00:00
} else {
// Tree mode
// Search parent comment
$parentComment = $ ( '.post[data-comment-id="' + wsMessage . to _comment _id + '"]' ) ;
if ( $parentComment . length > 0 ) {
console . log ( 'Parent comment: %O' , $parentComment ) ;
// Check for children
$parentCommentChildren = $parentComment . next ( '.comments' ) ;
// If child comment already exist
if ( $parentCommentChildren . length > 0 ) {
console . log ( 'Child comments found. Appending...' ) ;
2014-04-04 01:35:09 +00:00
$parentCommentChildren . append ( $commentTemplate . hide ( ) . fadeIn ( 2000 ) ) ;
2014-04-04 00:21:01 +00:00
} else {
console . log ( 'No child comments found. Creating...' ) ;
2014-04-04 01:35:09 +00:00
$parentComment . after ( $ ( '<div>' ) . addClass ( 'comments' ) . append ( $commentTemplate . hide ( ) . fadeIn ( 2000 ) ) ) ;
2014-04-04 00:21:01 +00:00
}
} else {
console . log ( 'Parent comment not found' ) ;
// FIXME: Double code
2014-04-04 01:35:09 +00:00
$ ( '.content-wrap #comments #post-reply' ) . before ( $commentTemplate . hide ( ) . fadeIn ( 2000 ) ) ;
2014-04-04 00:21:01 +00:00
}
}
2014-04-03 21:48:37 +00:00
// Adding anchor
$commentTemplate . before ( $anchor ) ;
2014-11-21 15:49:12 +00:00
2014-04-04 01:35:09 +00:00
// Fading out highlight if needed
2014-11-23 21:01:33 +00:00
if ( options . option _ws _comments _color _fadeout . value == true ) {
2014-04-04 01:35:09 +00:00
console . log ( 'Fading out the highlight' ) ;
$commentTemplate . children ( '.pp-highlight' ) . fadeOut ( 20000 ) ;
}
2014-11-21 15:49:12 +00:00
2014-04-04 23:57:26 +00:00
// Desktop notifications
2014-11-23 21:01:33 +00:00
if ( options . option _ws _comments _notifications . value == true ) {
2014-04-04 23:57:26 +00:00
console . log ( 'Showing desktop notification' ) ;
chrome . extension . sendMessage ( {
type : 'showNotification' ,
2014-11-24 14:57:34 +00:00
notificationId : 'comment_' + wsMessage . post _id + '#' + wsMessage . comment _id ,
avatarUrl : getProtocol ( ) + userAvatar + '/80' ,
title : '@' + wsMessage . author + ' #' + wsMessage . post _id + '(/' + wsMessage . comment _id + ')' ,
2014-04-04 23:57:26 +00:00
text : wsMessage . text
} ) ;
}
2014-11-21 15:49:12 +00:00
2014-04-04 00:21:01 +00:00
console . groupEnd ( ) ;
2014-04-03 21:48:37 +00:00
} ) ;
2014-11-21 15:49:12 +00:00
break ;
// Posts
case 'post' :
console . group ( 'ws-post #%s' , wsMessage . post _id ) ;
console . debug ( wsMessage ) ;
console . groupEnd ( ) ;
break ;
// Recommendation
case 'ok' :
console . group ( 'ws-recommendation #%s/%s' , wsMessage . post _id , wsMessage . comment _id ) ;
console . debug ( wsMessage ) ;
console . groupEnd ( ) ;
break ;
default :
console . group ( 'ws-other' ) ;
console . log ( wsMessage ) ;
console . groupEnd ( ) ;
2014-04-04 00:21:01 +00:00
break ;
2014-04-01 20:37:30 +00:00
}
2014-04-04 00:21:01 +00:00
}
2014-04-01 20:37:30 +00:00
2014-04-04 00:21:01 +00:00
}
} catch ( e ) {
console . log ( 'WebSocket exception:' )
console . log ( e ) ;
console . log ( evt . data ) ;
2014-04-03 21:48:37 +00:00
}
2014-04-04 00:21:01 +00:00
;
} ;
2014-11-21 15:49:12 +00:00
}
2014-04-21 19:40:08 +00:00
// Font size
2014-11-23 21:01:33 +00:00
if ( ( options . option _enlarge _font . value == true ) && ( options . option _enlarge _font _size . value !== undefined ) ) {
$ ( 'body' ) . css ( 'font-size' , ( options . option _enlarge _font _size . value / 100 ) + 'em' ) ;
2014-04-01 20:37:30 +00:00
}
2014-04-21 20:42:53 +00:00
// @ before username
2014-11-23 21:01:33 +00:00
if ( options . option _at _before _username . value == true ) {
2014-04-21 20:42:53 +00:00
chrome . extension . sendMessage ( {
type : 'injectCSSFile' ,
file : 'css/modules/at_before_username.css'
} ) ;
}
2014-11-14 23:36:50 +00:00
// Hightlight post with new comments
2014-11-23 21:01:33 +00:00
if ( options . option _other _hightlight _post _comments . value == true ) {
2014-11-14 23:36:50 +00:00
mark _unread _post ( ) ;
}
// Show recommendation count and unique commentators count
2014-11-23 21:01:33 +00:00
if ( options . option _other _show _recommendation _count . value == true ) {
2014-11-14 23:36:50 +00:00
set _posts _count _label ( ) ;
}
2014-11-22 12:15:22 +00:00
// `Space` key scroll handler
2014-11-23 21:01:33 +00:00
if ( options . option _other _scroll _space _key . value == true ) {
2014-11-21 15:49:12 +00:00
set _space _key _skip _handler ( ) ;
}
2014-11-14 23:36:50 +00:00
2014-12-26 08:42:48 +00:00
// Система комментариев у пользователей
2014-12-30 13:59:26 +00:00
if ( options . option _other _comments _user _system . value == true ) {
hints _init _user _system ( ) ;
}
2014-12-26 08:42:48 +00:00
2014-12-26 10:14:21 +00:00
// Nesting level indicator
if ( options . option _other _comments _nesting _level . value == true ) {
draw _nesting _level _indicator ( ) ;
}
2014-12-29 07:27:24 +00:00
// Обновляем кол-во постов и непрочитанных комментариев
if ( options . option _other _comments _count _refresh . value == true ) {
2015-01-02 19:10:02 +00:00
set _comments _refresh _tick ( options ) ;
2014-12-29 07:27:24 +00:00
}
2015-01-05 16:17:00 +00:00
// Твиты из Твиттера
if ( options . option _embedding _twitter _tweets . value == true ) {
twitter _tweet _embedding _init ( ) ;
}
2014-11-26 20:24:34 +00:00
$ ( '#point-plus-debug' ) . fadeOut ( 1000 ) ;
2014-03-11 14:48:26 +00:00
} ) ;
2014-04-01 20:37:30 +00:00
} ) ;
2014-11-24 14:57:34 +00:00
function getProtocol ( ) {
return ( ( location . protocol == 'http:' ) ? 'http:' : 'https:' )
}
2014-04-01 20:37:30 +00:00
function escapeHtml ( text ) {
2014-04-04 00:21:01 +00:00
return text
2014-11-21 15:49:12 +00:00
. replace ( /&/g , "&" )
. replace ( /</g , "<" )
//.replace(/>/g, ">")
. replace ( /"/g , """ )
. replace ( /'/g , "'" )
. replace ( /\n/g , "<br>" ) ;
2014-04-01 20:37:30 +00:00
}
// Monts for Date.getMonth()
var months = [
'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' ,
'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec'
2014-11-14 23:36:50 +00:00
] ;
// Картинки с бурятников
var booru _picture _count = 0 ;
function load _all _booru _images ( ) {
2014-11-26 20:48:08 +00:00
$ ( '.post-content a' ) . each ( function ( num , obj ) {
2014-11-14 23:36:50 +00:00
if ( $ ( obj ) . hasClass ( 'booru_pic' ) ) {
return ;
}
var href = obj . href ;
var n = null ;
if ( n = href . match ( new RegExp ( '^https?://danbooru\\.donmai\\.us/posts/([0-9]+)' , 'i' ) ) ) {
var image = create _image ( 'danbooru' , n [ 1 ] ) ;
obj . parentElement . insertBefore ( image , obj ) ;
booru _picture _count ++ ;
} else if ( n = href . match ( new RegExp ( '^https?\\://(www\\.)?gelbooru\\.com\\/index\\.php\\?page\\=post&s\\=view&id=([0-9]+)' , 'i' ) ) ) {
var image = create _image ( 'gelbooru' , n [ 2 ] ) ;
obj . parentElement . insertBefore ( image , obj ) ;
booru _picture _count ++ ;
} else if ( n = href . match ( new RegExp ( '^https?\\://(www\\.)?safebooru\\.org\\/index\\.php\\?page\\=post&s\\=view&id=([0-9]+)' , 'i' ) ) ) {
var image = create _image ( 'safebooru' , n [ 2 ] ) ;
obj . parentElement . insertBefore ( image , obj ) ;
booru _picture _count ++ ;
} else if ( n = href . match ( new RegExp ( '^https?\\://(www\\.)?([a-z0-9-]+\\.)?deviantart\\.com\\/art/[0-9a-z-]+?\\-([0-9]+)(\\?.+)?$' , 'i' ) ) ) {
var image = create _image ( 'deviantart' , n [ 3 ] ) ;
obj . parentElement . insertBefore ( image , obj ) ;
booru _picture _count ++ ;
} else if ( n = href . match ( new RegExp ( '^https?\\://(www\\.)?e621\\.net\\/post\\/show\\/([0-9]+)\\/' , 'i' ) ) ) {
var image = create _image ( 'e621' , n [ 2 ] ) ;
obj . parentElement . insertBefore ( image , obj ) ;
booru _picture _count ++ ;
} else if ( n = href . match ( new RegExp ( '^https?\\://derpiboo\\.ru\\/([0-9]+)' , 'i' ) ) ) {
var image = create _image ( 'derpibooru' , n [ 1 ] ) ;
obj . parentElement . insertBefore ( image , obj ) ;
booru _picture _count ++ ;
} else if ( n = href . match ( new RegExp ( '^https?\\://([0-9a-z-]+)\\.tumblr\\.com\\/post\\/([0-9]+)' , 'i' ) ) ) {
var image = create _image ( 'tumblr' , n [ 2 ] , { 'username' : n [ 1 ] } ) ;
obj . parentElement . insertBefore ( image , obj ) ;
booru _picture _count ++ ;
/ *
2014-11-23 09:10:35 +00:00
} else if ( n = href . match ( new RegExp ( '^https?\\://(www\\.)?konachan\\.net\\/post\\/show\\/([0-9]+)\\/' , 'i' ) ) ) {
var image = create _image ( 'konachannet' , n [ 2 ] ) ;
2014-11-14 23:36:50 +00:00
obj . parentElement . insertBefore ( image , obj ) ;
booru _picture _count ++ ;
2014-11-23 09:10:35 +00:00
} else if ( n = href . match ( new RegExp ( '^https?\\://(www\\.)?konachan\\.com\\/post\\/show\\/([0-9]+)\\/' , 'i' ) ) ) {
2014-11-14 23:36:50 +00:00
var image = create _image ( 'konachancom' , n [ 2 ] ) ;
obj . parentElement . insertBefore ( image , obj ) ;
booru _picture _count ++ ;
* /
} else if ( n = href . match ( new RegExp ( '^https?://(www\\.)?pixiv\\.net\\/member_illust\\.php\\?mode\\=medium\\&illust_id\\=([0-9]+)' , 'i' ) ) ) {
var image = create _image ( 'pixiv' , n [ 2 ] ) ;
obj . parentElement . insertBefore ( image , obj ) ;
booru _picture _count ++ ;
} else if ( n = href . match ( new RegExp ( '^http\\:\\/\\/anime\\-pictures\\.net\\/pictures\\/view_post\\/([0-9]+)' , 'i' ) ) ) {
var image = create _image ( 'animepicturesnet' , n [ 1 ] ) ;
obj . parentElement . insertBefore ( image , obj ) ;
booru _picture _count ++ ;
} else if ( false ) {
}
} ) ;
}
function create _image ( domain , id , additional ) {
var a = document . createElement ( 'a' ) ;
a . href = 'https://api.kanaria.ru/point/get_booru_picture.php?domain=' + domain + '&id=' + id ;
if ( typeof ( additional ) != 'undefined' ) {
for ( var index in additional ) {
a . href += '&add_' + encodeURIComponent ( index ) + '=' + encodeURIComponent ( additional [ index ] ) ;
}
}
2014-11-15 10:08:53 +00:00
$ ( a ) . addClass ( 'booru_pic' ) . addClass ( 'booru-' + domain + '-' + id ) . addClass ( 'postimg' ) . attr ( {
'id' : 'booru_pic_' + booru _picture _count ,
'title' : domain + ' image #' + id ,
'target' : '_blank'
} ) ;
2014-11-14 23:36:50 +00:00
var image = document . createElement ( 'img' ) ;
image . alt = a . title ;
image . src = a . href ;
a . appendChild ( image ) ;
return a ;
}
2014-11-22 12:15:22 +00:00
// Помечаем непрочитанные посты более видимо чем каким-то баджем
2014-11-14 23:36:50 +00:00
// Эта часть написана @RainbowSpike
function mark _unread _post ( ) {
2014-12-26 10:14:21 +00:00
var divs = $ ( ".content-wrap > .post" ) . css ( { 'padding-left' : '2px' } ) ; // массив постов
2014-11-14 23:36:50 +00:00
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'
} ) ;
}
}
}
// Webm
2014-11-26 20:52:47 +00:00
function parse _webm ( current _options ) {
2014-11-26 20:48:08 +00:00
$ ( '.post-content a' ) . each ( function ( num , obj ) {
2014-11-14 23:36:50 +00:00
if ( $ ( obj ) . hasClass ( 'booru_pic' ) ) {
return ;
}
var href = obj . href ;
var n = null ;
if ( n = href . match ( new RegExp ( '\\.webm(\\?.+)?$' , 'i' ) ) ) {
var player = document . createElement ( 'video' ) ;
2014-12-26 06:45:36 +00:00
// Там может быть не vp8+vorbis, но мы этого никак не узнаем
2014-11-14 23:36:50 +00:00
$ ( player ) . html ( '<source src="' + href + '" type=\'video/webm; codecs="vp8, vorbis"\' />' ) . attr ( 'controls' , 'controls' ) . css ( {
'display' : 'block' ,
'max-width' : '95%'
} ) . addClass ( 'parsed-webm-link' ) ;
obj . parentElement . insertBefore ( player , obj ) ;
2014-11-26 20:48:08 +00:00
if ( current _options . option _videos _parse _leave _links . value == false ) {
$ ( obj ) . hide ( ) ;
}
2014-11-14 23:36:50 +00:00
}
} ) ;
}
2014-11-25 13:02:39 +00:00
// Видео
2014-11-26 20:52:47 +00:00
function parse _all _videos ( current _options ) {
2014-11-26 20:48:08 +00:00
$ ( '.post-content a' ) . each ( function ( num , obj ) {
2014-11-21 15:49:12 +00:00
if ( $ ( obj ) . hasClass ( 'booru_pic' ) ) {
return ;
}
var href = obj . href ;
var n = null ;
2014-11-22 12:15:22 +00:00
if ( n = href . match ( new RegExp ( '\\.(webm|avi|mp4|mpg|mpeg)(\\?.+)?$' , 'i' ) ) ) {
2014-11-21 15:49:12 +00:00
var player = document . createElement ( 'video' ) ;
var mime = video _extension _to _mime ( n [ 1 ] ) ;
2014-11-25 13:02:39 +00:00
$ ( player ) . html ( '<source src="' + href + '" type=\'' + mime + '\' />' ) . attr ( 'controls' , 'controls' ) . css ( {
2014-11-21 15:49:12 +00:00
'display' : 'block' ,
'max-width' : '95%'
} ) . addClass ( 'parsed-webm-link' ) ;
obj . parentElement . insertBefore ( player , obj ) ;
2014-11-26 20:48:08 +00:00
if ( current _options . option _videos _parse _leave _links . value == false ) {
$ ( obj ) . hide ( ) ;
}
2014-11-21 15:49:12 +00:00
}
} ) ;
}
function video _extension _to _mime ( extension ) {
2014-11-23 09:10:35 +00:00
switch ( extension ) {
2014-11-21 15:49:12 +00:00
case 'webm' : return 'video/webm; codecs="vp8, vorbis' ;
2014-11-22 12:15:22 +00:00
case 'avi' : return 'video/avi;' ;
2014-11-21 15:49:12 +00:00
case 'mp4' : return 'video/mp4;' ;
2014-11-22 12:15:22 +00:00
case 'mpg' : return 'video/mp4;' ;
case 'mpeg' : return 'video/mp4;' ;
2014-11-21 15:49:12 +00:00
}
}
2014-11-25 13:02:39 +00:00
// Аудио
2014-11-26 20:52:47 +00:00
function parse _all _audios ( current _options ) {
2014-11-25 13:02:39 +00:00
$ ( '.post-content a' ) . each ( function ( num , obj ) {
if ( $ ( obj ) . hasClass ( 'booru_pic' ) ) {
return ;
}
var href = obj . href ;
var n = null ;
2014-11-25 13:10:38 +00:00
if ( n = href . match ( new RegExp ( '^https?:\\/\\/([a-z0-9.-]+)\\/[a-z0-9_\\/.%-]+\\.(mp3|ogg|wav)(\\?.+)?$' , 'i' ) ) ) {
2014-11-25 13:02:39 +00:00
var domain = n [ 1 ] ;
// Проверяем откуда мы грузимся
if ( domain . match ( new RegExp ( '\\.vk\\.me$' , 'i' ) ) ) {
// Так то ж Контакт!
2014-11-25 13:10:38 +00:00
if ( typeof ( n [ 3 ] ) == 'undefined' ) {
return ;
}
2014-11-25 13:02:39 +00:00
if ( ! n [ 3 ] . match ( 'extra\\=' , 'i' ) ) {
return ;
}
}
2014-11-21 15:49:12 +00:00
2014-11-25 13:02:39 +00:00
var player = document . createElement ( 'audio' ) ;
var mime = audio _extension _to _mime ( n [ 2 ] ) ;
$ ( player ) . html ( '<source src="' + href + '" type=\'' + mime + '\' />' ) . attr ( 'controls' , 'controls' ) . css ( {
'display' : 'block' ,
'max-width' : '350px'
} ) . addClass ( 'parsed-audio-link' ) ;
obj . parentElement . insertBefore ( player , obj ) ;
if ( current _options . option _audios _parse _leave _links . value == false ) {
$ ( obj ) . hide ( ) ;
}
}
} ) ;
}
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' ;
}
2014-11-21 15:49:12 +00:00
}
2014-12-26 10:14:21 +00:00
// Плашки с кол-вом уникальных пользователей и рекомендаций у постов
2014-11-14 23:36:50 +00:00
function set _posts _count _label ( ) {
var ids = [ ] ;
2014-12-26 10:14:21 +00:00
$ ( '.content-wrap > .post .post-id a .cn' ) . addClass ( 'changed_background' ) ;
2014-11-21 16:56:28 +00:00
2014-12-26 10:14:21 +00:00
$ ( '.content-wrap > .post' ) . each ( function ( num , obj ) {
2014-11-14 23:36:50 +00:00
var t = $ ( obj ) . attr ( 'data-comment-id' ) ;
if ( typeof ( t ) !== 'undefined' ) {
return ;
}
var id = $ ( obj ) . attr ( 'data-id' ) ;
ids . push ( id ) ;
} ) ;
$ajax ( {
'url' : 'https://api.kanaria.ru/point/get_post_info.php?list=' + urlencode ( ids . join ( ',' ) ) ,
2014-11-23 09:10:35 +00:00
'success' : function ( a ) {
2014-11-14 23:36:50 +00:00
var answer = JSON . parse ( a ) ;
2014-12-26 10:14:21 +00:00
$ ( '.content-wrap > .post' ) . each ( function ( num , obj ) {
2014-11-14 23:36:50 +00:00
var id = $ ( obj ) . attr ( 'data-id' ) ;
var postid = $ ( obj ) . find ( '.post-id a' ) [ 0 ] ;
var t = $ ( obj ) . attr ( 'data-comment-id' ) ;
if ( typeof ( t ) !== 'undefined' ) {
return ;
}
var e1 = document . createElement ( 'span' ) ;
2014-11-21 15:49:12 +00:00
if ( typeof ( answer . list [ id ] ) == 'undefined' ) {
return ;
}
2014-11-24 13:40:59 +00:00
$ ( e1 ) . addClass ( 'authors_unique_count' ) . text ( answer . list [ id ] . count _comment _unique ) . attr ( 'title' , 'Количество комментаторов' ) ;
2014-11-14 23:36:50 +00:00
postid . appendChild ( e1 ) ;
var e2 = document . createElement ( 'span' ) ;
2014-11-24 13:40:59 +00:00
$ ( e2 ) . addClass ( 'recommendation_count' ) . text ( '~' + answer . list [ id ] . count _recommendation ) . attr ( 'title' , 'Количество рекомендаций. Работает криво, спасибо @arts\'у за это' ) ;
2014-11-14 23:36:50 +00:00
postid . appendChild ( e2 ) ;
} ) ;
}
} )
}
2014-11-16 10:27:54 +00:00
2014-11-26 20:52:47 +00:00
function parse _pleercom _links ( current _options ) {
2014-11-26 20:48:08 +00:00
if ( current _options . option _embedding _pleercom _nokita _server . value ) {
parse _pleercom _links _nokita ( ) ;
} else {
2014-11-26 20:52:47 +00:00
parse _pleercom _links _ajax ( current _options ) ;
2014-11-26 20:48:08 +00:00
}
2014-11-16 12:10:11 +00:00
}
function parse _pleercom _links _nokita ( ) {
2014-11-26 20:48:08 +00:00
$ ( '.post-content a' ) . each ( function ( num , obj ) {
2014-11-16 10:27:54 +00:00
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'
2014-11-16 12:10:11 +00:00
} ) ;
2014-11-16 10:27:54 +00:00
2014-11-21 15:49:12 +00:00
var player _div = document . createElement ( 'div' ) ;
$ ( player _div ) . addClass ( 'embeded_audio' ) . addClass ( 'embeded_audio_' + n [ 1 ] ) ;
2014-11-16 12:10:11 +00:00
player _div . appendChild ( player ) ;
obj . parentElement . insertBefore ( player _div , obj ) ;
2014-11-16 10:27:54 +00:00
}
} ) ;
2014-11-16 12:10:11 +00:00
}
2014-11-16 10:27:54 +00:00
2014-11-26 20:52:47 +00:00
function parse _pleercom _links _ajax ( current _options ) {
2014-11-26 20:48:08 +00:00
$ ( '.post-content a' ) . each ( function ( num , obj ) {
2014-11-16 12:10:11 +00:00
var href = obj . href ;
var n = null ;
2014-11-16 10:27:54 +00:00
2014-11-16 12:10:11 +00:00
if ( n = href . match ( new RegExp ( '^https?:\\/\\/pleer\\.com\\/tracks\\/([0-9a-z]+)' , 'i' ) ) ) {
2014-11-21 15:49:12 +00:00
var player _div = document . createElement ( 'div' ) ;
$ ( player _div ) . addClass ( 'embeded_audio' ) . addClass ( 'embeded_audio_' + n [ 1 ] ) ;
2014-11-25 13:02:39 +00:00
$ ( obj ) . addClass ( 'pleercom_original_link_' + n [ 1 ] ) ;
2014-11-16 12:10:11 +00:00
obj . parentElement . insertBefore ( player _div , obj ) ;
2014-11-26 20:52:47 +00:00
create _pleercom _ajax ( n [ 1 ] , current _options ) ;
2014-11-16 12:10:11 +00:00
}
} ) ;
2014-11-16 10:27:54 +00:00
}
2014-11-16 12:10:11 +00:00
2014-11-26 20:52:47 +00:00
function create _pleercom _ajax ( id , current _options ) {
2014-11-16 12:10:11 +00:00
$ajax ( {
2014-11-21 15:49:12 +00:00
'url' : 'https://pleer.com/site_api/files/get_url' ,
'type' : 'post' ,
'postdata' : 'action=download&id=' + id ,
'dont_set_content_type' : true ,
'pleer_id' : id ,
2014-11-26 20:52:47 +00:00
'current_options' : current _options ,
2014-11-21 15:49:12 +00:00
'headers' : [ [ 'Accept' , '*' ] , [ 'Content-Type' , 'application/x-www-form-urlencoded; charset=UTF-8' ] ] ,
2014-11-23 09:10:35 +00:00
'success' : function ( a ) {
2014-11-16 12:10:11 +00:00
var answer = JSON . parse ( a ) ;
var player = document . createElement ( 'audio' ) ;
// @todo Проверять существование track_link
$ ( player ) . attr ( {
'src' : answer . track _link ,
'controls' : 'controls' ,
'preload' : 'auto'
} ) ;
2014-11-21 15:49:12 +00:00
$ ( '.embeded_audio_' + this . settings . pleer _id ) [ 0 ] . appendChild ( player ) ;
2014-11-25 13:02:39 +00:00
2014-11-26 20:52:47 +00:00
if ( this . settings . current _options . option _embedding _pleercom _orig _link . value == false ) {
2014-11-25 13:02:39 +00:00
$ ( '.pleercom_original_link_' + this . settings . pleer _id ) . hide ( ) ;
}
2014-11-16 12:10:11 +00:00
} ,
2014-11-23 09:10:35 +00:00
'error' : function ( ) {
2014-11-26 20:48:08 +00:00
console . log ( 'Can not get pleer.com url' ) ;
2014-11-21 15:49:12 +00:00
setTimeout ( new Function ( 'create_pleercom_ajax("' + this . settings . pleer _id + '");' ) , 1000 ) ;
2014-11-16 12:10:11 +00:00
}
} ) ;
2014-11-21 15:49:12 +00:00
}
// Проставляем теги у постов
2014-12-26 07:05:29 +00:00
// @hint В данный момент эта фича используются для NSFW, потом выборку по тегам можно будет использовать много где
2014-11-22 12:15:43 +00:00
function create _tag _system ( ) {
2014-12-26 10:14:21 +00:00
$ ( '.content-wrap > .post' ) . each ( function ( ) {
2014-11-22 12:15:43 +00:00
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 ) ;
}
} ) ;
}
2014-11-22 12:15:22 +00:00
// Скролл по пробелу
function set _space _key _skip _handler ( ) {
if ( $ ( '#comments' ) . length > 0 ) {
return ;
}
// @todo Свериться с Best-practice биндинга функций. М б там on или bind
2014-11-23 09:10:35 +00:00
$ ( document . body ) . keydown ( function ( e ) {
2014-11-22 12:15:22 +00:00
// @todo Я хотел по отпусканию кнопки, но там уже скролл срабатывает
// проверяем фокус
if ( $ ( ':focus' ) . length > 0 ) {
return ;
}
var k = event . keyCode ;
if ( k == 32 ) {
space _key _event ( ) ;
return false ;
}
} ) ;
}
function space _key _event ( ) {
var scroll _current = $ ( 'body' ) . scrollTop ( ) ;
var scroll _step _size = 0 ;
var scroll _real = Math . max ( scroll _current - scroll _step _size , 0 ) ;
2014-11-21 15:49:12 +00:00
2014-12-26 10:14:21 +00:00
var posts = $ ( '.content-wrap > .post' ) ;
2014-11-22 12:15:22 +00:00
for ( var i = 0 ; i < posts . length ; i ++ ) {
var this _top _px = $ ( posts [ i ] ) . offset ( ) . top ;
if ( this _top _px > scroll _real ) {
2014-11-21 15:49:12 +00:00
$ ( 'body' ) . animate ( {
2014-11-22 12:15:22 +00:00
'scrollTop' : this _top _px
2014-11-21 15:49:12 +00:00
} , 200 ) ;
return ;
}
}
2014-11-24 13:20:19 +00:00
}
/* Автосохранение черновиков */
2014-11-26 21:39:45 +00:00
var draft _last _text = '' ; // Последний зафиксированный текст
2014-12-26 06:15:14 +00:00
// Восстанавливаем черновик
2014-11-24 13:20:19 +00:00
function draft _restore ( ) {
2014-12-30 13:59:26 +00:00
chrome . storage . local . get ( 'point_draft_text' , function ( items ) {
2014-12-26 06:15:14 +00:00
if ( $ ( '#new-post-form #text-input' ) . val ( ) == '' ) {
$ ( '#new-post-form #text-input' ) . val ( items . point _draft _text ) ;
draft _last _text = items . point _draft _text ;
}
2014-11-24 13:20:19 +00:00
} ) ;
}
2014-12-26 06:15:14 +00:00
// Установка хандлера
2014-11-24 13:20:19 +00:00
function draft _set _save _handler ( ) {
2014-12-26 09:14:29 +00:00
// Господи, прости меня грешного за эту строку. Меня вынудили
$ ( '#text-input' ) . on ( 'keyup' , function ( ) {
draft _save _check ( ) ;
} ) ;
2014-12-26 06:15:14 +00:00
$ ( '#new-post-wrap .footnote' ) . append ( $ ( '<span id="draft-save-status">' ) ) ;
2014-11-24 13:20:19 +00:00
}
var draft _save _busy = false ;
2014-12-26 07:05:29 +00:00
// Фукнция, дёргающаяся по крону, проверяющая надо ли сохранять черновик
2014-11-24 13:20:19 +00:00
function draft _save _check ( ) {
if ( draft _save _busy ) {
return ;
}
draft _save _busy = true ;
var current _text = $ ( '#new-post-form #text-input' ) . val ( ) ;
if ( draft _last _text == current _text ) {
draft _save _busy = false ;
return ;
}
// @todo i18n
2014-11-26 21:39:45 +00:00
$ ( '#draft-save-status' ) . text ( 'Сохраняем черновик...' ) . show ( ) ;
2014-11-24 13:20:19 +00:00
// Сохраняем
2014-11-26 21:39:45 +00:00
draft _last _text = current _text ;
2014-11-24 13:20:19 +00:00
// Save it using the Chrome extension storage API.
2014-11-26 21:39:45 +00:00
chrome . storage . local . set ( { 'point_draft_text' : draft _last _text } , function ( ) {
2014-11-24 13:20:19 +00:00
// Notify that we saved.
2014-11-26 21:39:45 +00:00
draft _save _busy = false ;
$ ( '#draft-save-status' ) . text ( 'Черновик сохранён...' ) ;
setTimeout ( function ( ) {
$ ( '#draft-save-status' ) . fadeOut ( 1000 ) ;
2014-11-24 13:20:19 +00:00
} , 1000 ) ;
} ) ;
}
2014-11-25 13:43:21 +00:00
// Парсим ссылки на coub
2014-11-26 20:52:47 +00:00
function parse _coub _links ( current _options ) {
2014-11-25 13:43:21 +00:00
$ ( '.post-content a' ) . each ( function ( num , obj ) {
var href = obj . href ;
var n = null ;
if ( n = href . match ( new RegExp ( '^https?:\\/\\/coub\\.com\\/view\\/([0-9a-z]+)' , 'i' ) ) ) {
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 ] ) ;
obj . parentElement . insertBefore ( player , obj ) ;
if ( current _options . option _embedding _coubcom _orig _link . value == false ) {
$ ( obj ) . hide ( ) ;
}
}
} ) ;
}
2014-12-26 06:45:36 +00:00
// Правим хинт в FancyBox
function fancybox _set _smart _hints ( ) {
$ ( '.post' ) . each ( function ( ) {
var all _post _images = $ ( this ) . find ( '.postimg' ) ;
if ( all _post _images . length == 0 ) {
return ;
}
var tags = $ ( this ) . find ( 'div.tags a.tag' ) ;
2015-01-02 15:53:46 +00:00
var default _hint _text = '' ; // Дефолтный текст для хинта в FancyBox, если не нашлость другого
2014-12-26 06:45:36 +00:00
// Сначала теги
for ( var i = 0 ; i < tags . length ; i ++ ) {
var tag _name = $ ( tags [ i ] ) . html ( ) . toLowerCase ( ) ;
2015-01-02 15:53:46 +00:00
default _hint _text += ' ' + tag _name ;
2014-12-26 06:45:36 +00:00
}
// Потом текст
var textcontent = $ ( this ) . find ( '.text-content' ) ;
if ( textcontent . length > 0 ) {
textcontent = textcontent [ 0 ] ;
for ( var i = 0 ; i < textcontent . childNodes . length ; i ++ ) {
var current _child _node = textcontent . childNodes [ i ] ;
if ( ( current _child _node . nodeName !== 'P' ) && ( current _child _node . nodeName !== '#text' ) ) {
continue ;
}
var a = $ ( current _child _node ) . find ( 'a.postimg' ) ;
if ( a . length > 0 ) {
continue ;
}
var tmp _str = current _child _node . textContent . replace ( /(\n(\r)?)/g , ' ' ) ;
tmp _str = tmp _str . replace ( "\t" , " " ) ;
2015-01-02 15:53:46 +00:00
default _hint _text += ' ' + tmp _str ;
2014-12-26 06:45:36 +00:00
}
}
2015-01-02 15:53:46 +00:00
// Режем текст
default _hint _text = default _hint _text . replace ( new RegExp ( ' {2,}' ) , ' ' ) . replace ( new RegExp ( ' +$' ) , '' ) . substr ( 1 ) ;
if ( default _hint _text . length > 140 ) {
default _hint _text = default _hint _text . substr ( 0 , 140 - 3 ) + '...' ;
2014-12-26 06:45:36 +00:00
}
2015-01-02 15:53:46 +00:00
// Выставляем дефолтный
all _post _images . attr ( 'data-fancybox-title' , default _hint _text ) ;
// А теперь перебираем по одному все картинки
var paragraphs = $ ( this ) . find ( '.post-content > .text > p, .post-content > .text, .text-content > p, .text-content' ) ;
paragraphs . each ( function ( ) {
var nodes = this . childNodes ;
for ( var i = 0 ; i < nodes . length - 2 ; i ++ ) {
if ( $ ( nodes [ i ] ) . hasClass ( 'booru_pic' ) ) {
if ( nodes [ i + 2 ] . nodeName == '#text' ) {
$ ( nodes [ i ] ) . attr ( 'data-fancybox-title' , nodes [ i + 2 ] . textContent ) ;
i += 2 ;
continue ;
}
}
}
} ) ;
2014-12-26 06:45:36 +00:00
} ) ;
}
2014-12-26 08:42:48 +00:00
/ * *
* Система заметок о пользователях
* https : //bitbucket.org/skobkin/chrome_point_plus/issue/50/---------------------------
* /
// Инициализируем
function hints _init _user _system ( ) {
2014-12-30 13:59:26 +00:00
chrome . storage . sync . get ( 'point_user_hints' , function ( items ) {
2014-12-26 08:42:48 +00:00
if ( typeof ( items . point _user _hints ) == 'undefined' ) {
// Первый запуск системы
2014-12-30 13:59:26 +00:00
chrome . storage . sync . set ( { 'point_user_hints' : { } } , function ( ) {
2014-12-26 08:42:48 +00:00
hints _draw _main _user _hint ( { } ) ;
hints _set _titles _on _users ( { } ) ;
} ) ;
} else {
// Второй+ запуск системы
hints _draw _main _user _hint ( items . point _user _hints ) ;
hints _set _titles _on _users ( items . point _user _hints ) ;
}
} ) ;
}
// Рисуем хинт и кнопку под текущим пользователем
function hints _draw _main _user _hint ( items ) {
var current _user _name = $ ( '.aside .info h1' ) . text ( ) . toLowerCase ( ) ;
2014-12-30 13:59:26 +00:00
if ( current _user _name . length == 0 ) {
2014-12-26 08:42:48 +00:00
return ;
}
var current _user _hint _block = document . createElement ( 'div' ) ;
$ ( '.aside .aside-content #counters' ) [ 0 ] . parentElement .
insertBefore ( current _user _hint _block , $ ( '.aside .aside-content #counters' ) [ 0 ] ) ;
$ ( current _user _hint _block ) . addClass ( 'current-user-hint' ) ;
// Рисуем кнопки управления
var buttons _block = document . createElement ( 'div' ) ;
$ ( buttons _block ) . addClass ( 'buttons' ) .
html ( '<a class="edit" href="javascript:" title="Редактировать"></a>' ) ;
current _user _hint _block . appendChild ( buttons _block ) ;
2014-12-30 13:59:26 +00:00
$ ( buttons _block ) . find ( '.edit' ) . on ( 'click' , function ( ) {
chrome . storage . sync . get ( 'point_user_hints' , function ( items ) {
2014-12-26 08:42:48 +00:00
var current _text = '' ;
if ( typeof ( items . point _user _hints [ current _user _name ] ) !== 'undefined' ) {
current _text = items . point _user _hints [ current _user _name ] ;
}
$ ( '.current-user-hint .change_hint_block' ) . slideDown ( 500 ) ;
$ ( '.current-user-hint .change_hint_block textarea' ) . val ( current _text ) ;
} ) ;
} ) ;
// Рисуем текст
var current _text = '' ;
if ( typeof ( items [ current _user _name ] ) !== 'undefined' ) {
current _text = items [ current _user _name ] ;
}
var text _block = document . createElement ( 'div' ) ;
2014-12-30 14:57:43 +00:00
$ ( text _block ) . addClass ( 'text' ) ;
safe _saned _text ( current _text , $ ( text _block ) ) ;
2014-12-26 08:42:48 +00:00
current _user _hint _block . appendChild ( text _block ) ;
// Рисуем невидимый блок для управления
var change _hint _block = document . createElement ( 'div' ) ;
$ ( change _hint _block ) . addClass ( 'change_hint_block' ) . hide ( ) .
html ( '<textarea></textarea><input class="button_save" type="submit" value="Сохранить">' +
'<a href="javascript:" class="button_cancel">Отмена</a>' ) ;
2014-12-30 13:59:26 +00:00
$ ( change _hint _block ) . find ( '.button_save' ) . on ( 'click' , function ( ) {
2014-12-26 08:42:48 +00:00
$ ( '.current-user-hint .change_hint_block' ) . slideUp ( 500 ) ;
var new _text = $ ( '.current-user-hint .change_hint_block textarea' ) . val ( ) ;
2014-12-30 14:57:43 +00:00
safe _saned _text ( new _text , $ ( '.current-user-hint > .text' ) . hide ( ) . fadeIn ( 750 ) ) ;
2014-12-26 08:42:48 +00:00
hints _save _new _hint ( current _user _name , new _text ) ;
} ) ;
2014-12-30 13:59:26 +00:00
$ ( change _hint _block ) . find ( '.button_cancel' ) . on ( 'click' , function ( ) {
2014-12-26 08:42:48 +00:00
$ ( '.current-user-hint .change_hint_block' ) . slideUp ( 500 ) ;
} ) ;
current _user _hint _block . appendChild ( change _hint _block ) ;
}
2014-12-30 14:57:43 +00:00
// Nokita Kaze снимает с себя все претензии по этому коду, обращайтесь к фаундеру проекта
function safe _saned _text ( text , object ) {
var n = text . split ( /\r?\n/ ) ;
object . text ( '' ) ;
for ( var i = 0 ; i < n . length ; i ++ ) {
var d = document . createElement ( 'p' ) ;
$ ( d ) . text ( n [ i ] ) ;
object [ 0 ] . appendChild ( d ) ;
}
2014-12-26 08:42:48 +00:00
}
// Рисуем title'ы на всех доступных пользователях, точнее на их аватарках
function hints _set _titles _on _users ( items ) {
2014-12-30 13:59:26 +00:00
$ ( 'a' ) . each ( function ( ) {
2014-12-26 09:14:29 +00:00
var href = $ ( this ) . attr ( 'href' ) ;
if ( typeof ( href ) == 'undefined' ) {
return ;
}
2014-12-27 17:34:58 +00:00
var n = href . match ( new RegExp ( '^https?\\://([0-9a-z-]+)\\.point\\.im/$' , 'i' ) ) ;
2014-12-26 08:42:48 +00:00
if ( n == null ) {
return ;
}
var this _user _name = n [ 1 ] . toLowerCase ( ) ;
if ( typeof ( items [ this _user _name ] ) == 'undefined' ) {
return ;
}
$ ( this ) . attr ( {
'title' : items [ this _user _name ]
} ) ;
} ) ;
}
// Сохраняем новый хинт
function hints _save _new _hint ( username , new _hint ) {
2014-12-30 13:59:26 +00:00
chrome . storage . sync . get ( 'point_user_hints' , function ( items ) {
2014-12-26 08:42:48 +00:00
items . point _user _hints [ username ] = new _hint ;
chrome . storage . sync . set ( { 'point_user_hints' : items . point _user _hints } ) ;
} ) ;
}
2014-12-26 10:14:21 +00:00
/ * *
* Nesting level indicator
* Шваброшвабровские точки
* /
function draw _nesting _level _indicator ( ) {
$ ( '.comments' ) . css ( { 'margin-left' : '0px' } ) ;
draw _nesting _level _indicator _level ( $ ( '#comments > .comments' ) , 1 ) ;
}
function draw _nesting _level _indicator _level ( obj , level ) {
2014-12-30 13:59:26 +00:00
obj . find ( '> .post' ) . each ( function ( ) {
2014-12-26 10:14:21 +00:00
var nesting = document . createElement ( 'div' ) ;
$ ( nesting ) . addClass ( 'nesting' ) . css ( {
'width' : ( 10 * level ) + 'px'
} ) ;
this . insertBefore ( nesting , $ ( this ) . find ( '.info' ) [ 0 ] ) ;
$ ( this ) . find ( '> .post-content' ) . css ( {
'padding-left' : ( 10 * level ) + 'px'
} ) ;
} ) ;
2014-12-30 13:59:26 +00:00
obj . each ( function ( ) {
2014-12-26 10:14:21 +00:00
var comments = $ ( this ) . find ( '> .comments' ) ;
if ( comments . length > 0 ) {
draw _nesting _level _indicator _level ( comments , level + 1 ) ;
}
} ) ;
2014-12-29 07:27:24 +00:00
}
/ * *
* Обновляем кол - во комментариев и непрочитанных новых постов в ленте
* /
2015-01-02 19:10:02 +00:00
function set _comments _refresh _tick ( current _options ) {
2014-12-29 07:27:24 +00:00
// Проверяем, чтобы были баджи
if ( $ ( '#main #left-menu #menu-recent .unread' ) . length == 0 ) {
2014-12-29 07:50:59 +00:00
$ ( '#main #left-menu #menu-recent' ) . append ( '<span class="unread" style="display: none;">0</span>' ) ;
2014-12-29 07:27:24 +00:00
}
if ( $ ( '#main #left-menu #menu-comments .unread' ) . length == 0 ) {
2014-12-29 07:50:59 +00:00
$ ( '#main #left-menu #menu-comments' ) . append ( '<span class="unread" style="display: none;">0</span>' ) ;
2014-12-29 07:27:24 +00:00
}
// Ставим тик
2015-01-02 19:10:02 +00:00
setInterval ( function ( ) {
comments _count _refresh _tick ( current _options ) ;
} , 60000 ) ;
2015-01-02 21:32:17 +00:00
// Ставим слежение за позицией мыши
if ( current _options . option _other _comments _count _refresh _title . value == true ) {
$ ( document ) .
on ( 'mouseenter' , function ( ) {
set _comments _refresh _clear _title _marks ( ) ;
} ) . on ( 'mouseleave' , function ( ) {
window _focused = false ;
} ) ;
$ ( window ) .
on ( 'focus' , function ( ) {
set _comments _refresh _clear _title _marks ( ) ;
} ) . on ( 'blur' , function ( ) {
window _focused = false ;
} ) ;
}
}
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 ;
window _focused = true ;
2014-12-29 07:27:24 +00:00
}
// Проверка обновления комментариев, обновляется по крону
2015-01-02 19:10:02 +00:00
function comments _count _refresh _tick ( current _options ) {
2014-12-29 07:27:24 +00:00
$ ( '#debug_iframe' ) . remove ( ) ;
var iframe = document . createElement ( 'iframe' ) ;
document . body . appendChild ( iframe ) ;
2014-12-30 13:59:26 +00:00
$ ( iframe ) . on ( 'load' , function ( ) {
2014-12-29 07:27:24 +00:00
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 ( ) ) ;
2014-12-30 13:59:26 +00:00
console . log ( 'Comments: %d, Recent: %d' , count _comments , count _recent ) ;
2014-12-29 07:27:24 +00:00
if ( count _recent > 0 ) {
2014-12-29 07:50:59 +00:00
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'
} ) ;
2014-12-30 13:59:26 +00:00
setTimeout ( function ( ) {
2014-12-29 07:50:59 +00:00
$ ( '#main #left-menu #menu-recent .unread' ) . css ( {
2015-01-03 00:07:04 +00:00
'background-color' : '' ,
'color' : ''
2014-12-29 07:50:59 +00:00
} ) ;
} , 15000 ) ;
}
2014-12-29 07:27:24 +00:00
} else {
$ ( '#main #left-menu #menu-recent .unread' ) . text ( '0' ) . hide ( ) ;
}
if ( count _comments > 0 ) {
2014-12-29 07:50:59 +00:00
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'
} ) ;
2014-12-30 13:59:26 +00:00
setTimeout ( function ( ) {
2014-12-29 07:50:59 +00:00
$ ( '#main #left-menu #menu-comments .unread' ) . css ( {
2015-01-03 00:07:04 +00:00
'background-color' : '' ,
'color' : ''
2014-12-29 07:50:59 +00:00
} ) ;
} , 15000 ) ;
}
2014-12-29 07:27:24 +00:00
} else {
$ ( '#main #left-menu #menu-comments .unread' ) . text ( '0' ) . hide ( ) ;
}
2015-01-02 21:32:17 +00:00
if ( ( current _options . option _other _comments _count _refresh _title . value == true ) &&
( ! window _focused ) ) {
2015-01-02 19:10:02 +00:00
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 ;
}
2014-12-29 07:27:24 +00:00
$ ( '#debug_iframe' ) . remove ( ) ;
} ) . attr ( {
2014-12-29 07:50:59 +00:00
// Из-за Same Origin'а я дёргаю несуществующую страницу на том же домене, чтобы получить баджи и,
// в то же время не прочитать новые сообщения в ленте, которые могли появиться, если их написал
// этот пользователь
2014-12-30 13:59:26 +00:00
'src' : '//' + document . domain + '/?tag=' + Math . random ( ) ,
2014-12-29 07:27:24 +00:00
'id' : 'debug_iframe'
} ) . css ( {
'width' : '600px' ,
'height' : '300px'
} ) . hide ( ) ;
}
2015-01-05 16:17:00 +00:00
/ * *
* Встраиваем твиты из Твиттера
* /
function twitter _tweet _embedding _init ( ) {
// Чёрная магия. Выбираемся из манямирка, прихватив с собой пару сраных функций
// https://developer.chrome.com/extensions/content_scripts Isolated World
var e = document . createElement ( "script" ) ;
e . appendChild ( document . createTextNode ( twitter _tweet _embedding _wait _for _ready _injected . toString ( ) +
twitter _tweet _embedding _parse _links . toString ( ) + 'twitter_tweet_embedding_wait_for_ready_injected();' ) ) ;
document . head . appendChild ( e ) ;
// Встраиваем скрипт так, как описано в best twitter practice https://dev.twitter.com/web/javascript/loading
window . twttr = ( function ( d , s , id ) {
var t , js , fjs = d . getElementsByTagName ( s ) [ 0 ] ;
if ( d . getElementById ( id ) ) return ;
js = d . createElement ( s ) ;
js . id = id ;
js . src = "https://platform.twitter.com/widgets.js" ;
fjs . parentNode . insertBefore ( js , fjs ) ;
return window . twttr || ( t = {
_e : [ ] , ready : function ( f ) {
t . _e . push ( f ) ;
}
} ) ;
} ( document , "script" , "twitter-wjs" ) ) ;
}
/ * *
* Проверяем загрузились ли мы . Эта функция запускается из page scope
* /
function twitter _tweet _embedding _wait _for _ready _injected ( ) {
if ( typeof ( window . twttr ) == 'undefined' ) {
setTimeout ( twitter _tweet _embedding _wait _for _ready _injected , 100 ) ;
return ;
}
if ( typeof ( window . twttr . widgets ) == 'undefined' ) {
setTimeout ( twitter _tweet _embedding _wait _for _ready _injected , 100 ) ;
return ;
}
twitter _tweet _embedding _parse _links ( ) ;
}
/ * *
* Парсим все ссылки . Эта функция запускается из page scope
* /
function twitter _tweet _embedding _parse _links ( ) {
// Обрабатываем все твиты
var twitter _tweet _count = 0 ;
$ ( '.post-content a' ) . each ( function ( num , obj ) {
if ( $ ( obj ) . hasClass ( 'booru_pic' ) ) {
return ;
}
var href = obj . href ;
var n ;
if ( n = href . match ( new RegExp ( '^https?://(www\\.)?twitter\\.com/[^/]+/status/([0-9]+)' , 'i' ) ) ) {
var image = document . createElement ( 'div' ) ;
$ ( image ) . attr ( {
'id' : 'tweet-' + twitter _tweet _count ,
'data-tweet-id' : n [ 2 ]
} ) . addClass ( 'twitter-tweet-embedded' ) ;
obj . parentElement . insertBefore ( image , obj ) ;
window . twttr . widgets . createTweet (
n [ 2 ] ,
image ,
{
2015-01-05 16:34:53 +00:00
'lang' : 'ru'
2015-01-05 16:17:00 +00:00
}
) ;
twitter _tweet _count ++ ;
}
} ) ;
}