2014-03-11 14:48:26 +00:00
$ ( document ) . ready ( function ( ) {
2014-04-01 20:37:30 +00:00
// Grouping console log
console . group ( 'point-plus' ) ;
2014-04-04 00:21:01 +00:00
2014-04-04 21:12:11 +00:00
console . info ( 'Point+ %s' , getVersion ( ) ) ;
2014-03-11 14:48:26 +00:00
// Loading options
2014-04-03 21:38:34 +00:00
chrome . storage . sync . get ( ppOptions , function ( options ) {
2014-04-04 00:21:01 +00:00
// Options debug
console . debug ( 'Options loaded: %O' , options ) ;
2014-11-15 10:08:53 +00:00
// Embedding
if ( options . option _embedding == true ) {
// Load pictures from Booru, Tumblr and some other sites
if ( options . option _images _load _booru == true ) {
load _all _booru _images ( ) ;
}
// Parse webm-links and create video instead
if ( options . option _videos _parse _webm == true ) {
parse _webm ( ) ;
}
2014-11-16 02:01:31 +00:00
// Soundcloud
if ( options . option _embedding _soundcloud == true ) {
// Injecting JS API
chrome . extension . sendMessage ( {
type : 'injectJSFile' ,
file : 'js/soundcloud/soundcloud.player.api.js'
} ) ;
// Processing links
2014-11-16 06:42:11 +00:00
$ ( '.post .post-content a[href*="\\:\\/\\/soundcloud\\.com\\/"]' ) . each ( function ( index ) {
2014-11-16 02:01:31 +00:00
console . log ( $ ( this ) ) ;
$player = $ ( ' < div class = "pp-soundcloud" > \
< object height = "81" width = "100%" id = "pp-soundcloud-' + index + '" classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" > \
< param name = "movie" value = " http : //player.soundcloud.com/player.swf?url=' + encodeURIComponent($(this).prop('href'))
+ '&enable_api=true&object_id=pp-soundcloud-' + index + ' " > < / p a r a m > \
< param name = "allowscriptaccess" value = "always" > < / p a r a m > \
< embed allowscriptaccess = "always" height = "81" src = " http : //player.soundcloud.com/player.swf?url='
+ encodeURIComponent ( $ ( this ) . prop ( 'href' ) ) + '&enable_api=true&object_id=pp-soundcloud-' + index
+ '" type="application/x-shockwave-flash" width="100%" name="pp-soundcloud-' + index + ' " > < / e m b e d > \
< / o b j e c t > \
< / d i v > ' ) ;
// Replace or prepend
if ( options . option _embedding _soundcloud _orig _link == true ) {
// Before
$ ( this ) . before ( $player ) ;
} else {
// Replace
$ ( this ) . replaceWith ( $player ) ;
}
} ) ;
}
2014-11-15 10:08:53 +00:00
}
2014-03-14 12:16:06 +00:00
// Fancybox
2014-04-03 21:48:37 +00:00
if ( options . option _fancybox == true ) {
2014-11-15 10:08:53 +00:00
if ( options . option _fancybox _bind _images _to _one _flow == true ) {
2014-04-03 21:48:37 +00:00
// Linking images in posts to the galleries
2014-11-15 10:08:53 +00:00
$ ( '.post-content .text' ) . each ( function ( ) {
$ ( this ) . find ( 'a.postimg:not(.youtube)' ) . attr ( 'rel' , 'one_flow_gallery' ) ;
2014-04-03 21:48:37 +00:00
} ) ;
2014-11-15 10:08:53 +00:00
}
// Images
if ( options . option _fancybox _images == true ) {
if ( options . option _fancybox _bind _images _to _one _flow !== true ) {
// Linking images in posts to the galleries
$ ( '.post-content .text' ) . each ( function ( idxPost ) {
$ ( this ) . find ( 'a.postimg:not(.youtube)' ) . attr ( 'rel' , 'post' + idxPost ) ;
} ) ;
}
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
}
// Videos
if ( options . option _fancybox _videos == true ) {
$ ( '.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
if ( options . option _fancybox _posts == 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-15 02:44:36 +00:00
2014-03-19 17:43:04 +00:00
// Hotkeys
2014-03-11 14:48:26 +00:00
// Send by CTRL+Enter
if ( options . option _ctrl _enter == true ) {
2014-03-20 01:55:21 +00:00
// Reply
2014-04-04 21:12:11 +00:00
// Delegated event for all comments
$ ( '.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-04-04 21:12:11 +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
if ( options . option _fluid _layout == 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
if ( options . option _images _load _original == true ) {
// Setting new image source
2014-04-04 00:21:01 +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-03-20 04:36:40 +00:00
if ( options . option _visual _editor _post == true ) {
// 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
if ( options . option _ctrl _enter == true ) {
// New post
$ ( '#new-post-form #text-input, .post-content #text-input' ) . on ( 'keydown.point_plus' , function ( e ) {
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
if ( options . option _search _with _google == true ) {
$ ( '#search-form 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 ( ) ;
}
} ) ;
}
2014-04-01 20:37:30 +00:00
// WebSocket
2014-04-03 21:48:37 +00:00
if ( options . option _ws == 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 ) ;
// 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 ) ;
// Error handler
ws . onerror = function ( err ) {
console . error ( 'WebSocket error: %O' , err ) ;
} ;
// Message handler
ws . onmessage = function ( evt ) {
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
if ( options . option _ws _comments != true ) {
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 ;
}
// 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-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
} ) ;
// Loading HTML template
$commentTemplate . load ( chrome . extension . getURL ( 'includes/comment.html' ) , function ( ) {
// 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 ( ) ;
// 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 ( ) ;
// 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' )
. 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 ( ) ) ) ) ) ;
// 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 )
// Adding answer label
. after ( ( wsMessage . to _comment _id !== null ) ? ( ' в ответ на <a href="#' + wsMessage . to _comment _id + '">/' + wsMessage . to _comment _id + '</a>' ) : ( '' ) ) ;
// 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-04-04 00:21:01 +00:00
2014-04-04 01:35:09 +00:00
// Fading out highlight if needed
if ( options . option _ws _comments _color _fadeout == true ) {
console . log ( 'Fading out the highlight' ) ;
$commentTemplate . children ( '.pp-highlight' ) . fadeOut ( 20000 ) ;
}
2014-04-04 23:57:26 +00:00
// Desktop notifications
if ( options . option _ws _comments _notifications == true ) {
console . log ( 'Showing desktop notification' ) ;
chrome . extension . sendMessage ( {
type : 'showNotification' ,
notificationId : wsMessage . post _id + '_' + wsMessage . comment _id ,
avatarUrl : ( ( location . protocol == 'http:' ) ? 'http:' : 'https:' ) + userAvatar + '/80' ,
title : '@' + wsMessage . author + ' commented #' + wsMessage . post _id + '(/' + wsMessage . comment _id + ')' ,
text : wsMessage . text
} ) ;
}
2014-04-04 00:21:01 +00:00
console . groupEnd ( ) ;
2014-04-03 21:48:37 +00:00
} ) ;
2014-04-04 00:21:01 +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 ( ) ;
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-04-21 19:40:08 +00:00
}
// Font size
if ( ( options . option _enlarge _font == true ) && ( options . option _enlarge _font _size !== undefined ) ) {
$ ( 'body' ) . css ( 'font-size' , ( options . option _enlarge _font _size / 100 ) + 'em' ) ;
2014-04-01 20:37:30 +00:00
}
2014-04-21 20:42:53 +00:00
// @ before username
if ( options . option _at _before _username == true ) {
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
if ( options . option _other _hightlight _post _comments == true ) {
mark _unread _post ( ) ;
}
// Show recommendation count and unique commentators count
if ( options . option _other _show _recommendation _count == true ) {
set _posts _count _label ( ) ;
}
2014-03-11 14:48:26 +00:00
} ) ;
// Showing page action
chrome . extension . sendMessage ( { type : 'showPageAction' } ) ;
2014-04-01 20:37:30 +00:00
} ) ;
function escapeHtml ( text ) {
2014-04-04 00:21:01 +00:00
return text
. 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
] ;
/* Nokita's functions */
// Картинки с бурятников
var booru _picture _count = 0 ;
function load _all _booru _images ( ) {
$ ( 'a' ) . each ( function ( num , obj ) {
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 ++ ;
/ *
} else if ( n = href . match ( new RegExp ( '^https?\\://(www\\.)?konachan\\.net\\/post\\/show\\/([0-9]+)\\/' , 'i' ) ) ) {
var image = create _image ( 'konachannet' , n [ 2 ] ) ;
obj . parentElement . insertBefore ( image , obj ) ;
booru _picture _count ++ ;
} else if ( n = href . match ( new RegExp ( '^https?\\://(www\\.)?konachan\\.com\\/post\\/show\\/([0-9]+)\\/' , 'i' ) ) ) {
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 ;
}
/* point */
// Эта часть написана @RainbowSpike
function mark _unread _post ( ) {
// @todo Проверить работает ли
var divs = $ ( ".post" ) ; // массив постов
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
function parse _webm ( ) {
$ ( 'a' ) . each ( function ( num , obj ) {
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' ) ;
// @todo Там может быть не vp8+vorbis
$ ( 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 ) ;
}
} ) ;
}
// Плашки у постов
function set _posts _count _label ( ) {
var ids = [ ] ;
$ ( 'div.post' ) . each ( function ( num , obj ) {
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 ( ',' ) ) ,
'success' : function ( a ) {
var answer = JSON . parse ( a ) ;
$ ( 'div.post' ) . each ( function ( num , obj ) {
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' ) ;
$ ( e1 ) . addClass ( 'authors_unique_count' ) . html ( answer . list [ id ] . count _comment _unique ) . attr ( 'title' , 'Количество комментаторов' ) ;
postid . appendChild ( e1 ) ;
var e2 = document . createElement ( 'span' ) ;
$ ( e2 ) . addClass ( 'recomendation_count' ) . html ( '~' + answer . list [ id ] . count _recommendation ) . attr ( 'title' , 'Количество рекомендаций. Работает криво, спасибо @arts\'у за это' ) ;
postid . appendChild ( e2 ) ;
} ) ;
}
} )
}