diff --git a/chrome_point_plus/css/point-plus.css b/chrome_point_plus/css/point-plus.css index d3adbb3..70ed23d 100644 --- a/chrome_point_plus/css/point-plus.css +++ b/chrome_point_plus/css/point-plus.css @@ -154,4 +154,29 @@ div#markItUpText-input { .pp-options #pp-version { margin-top: 6px; text-align: right; -} \ No newline at end of file +} + +/* Auto-loaded Booru pictures */ +.booru_pic{ + display: block; +} + +.booru_pic img{ + border: none; + max-width: 60%; + max-height: 300px; +} + +/* Labels in post */ +.post .post-id a .authors_unique_count, .post .post-id a .recomendation_count{ + padding: 0 .5em; + font-weight: normal; + color: #35587c; + background: #f2f2eb; +} + +.post .post-id a .recomendation_count{ + margin-left: 0.2em; + background: #f2eceb; +} + diff --git a/chrome_point_plus/js/bquery_ajax.js b/chrome_point_plus/js/bquery_ajax.js new file mode 100644 index 0000000..44f1c8d --- /dev/null +++ b/chrome_point_plus/js/bquery_ajax.js @@ -0,0 +1,89 @@ +function $ajax_prot(settings){ + if (settings==undefined){return;} + if (settings['url'] ==undefined){return;}this.url=settings['url']; + if (settings['async'] !==undefined){this.async =settings['async'];} + if (settings['type'] !==undefined){this.type =settings['type'];} + if (settings['postdata']!==undefined){this.postdata=settings['postdata'];} + + this.xhr=new XMLHttpRequest(); + this.xhr.parent =this; + this.xhr.settings=settings; + this.xhr.success =settings['success']; + this.xhr.error =settings['error']; + this.xhr.onreadystatechange=this.change; + this.xhr.open(this.type, this.url, this.async); + if (this.type=='POST'){this.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');} + if (settings.headers!==undefined){ + for (var i=0;i0){ + s+='\\'+text[i]; + }else{ + s+=text[i]; + } + } + return s; +} + +function sad_xml_getnode(node,path){//node as domNode + if ('' ==path){return node;} + if ('#'==path){return node.textContent || node.text;} + + var ri=new RegExp('^([a-z0-9.:_-]*)(\\|[0-9]+)?(/?(.*))?','i'); + var t=path.match(ri); + if (t[1].length<1){return undefined;} + if (t[2]==undefined){t[2]='';} + if (t[4]==undefined){t[4]='';} + + var k=parseInt(t[2].substr(1)); + if (!(k>0)){k=1;} + var r=new RegExp('^'+sad_safe_reg(t[1])+'$'); + for (var i=0;i@skobkin-ru'; }); @@ -191,7 +219,10 @@ function pp_restore_options() { } document.addEventListener('DOMContentLoaded', pp_restore_options); -document.querySelector('#save').addEventListener('click', pp_save_options); +var point_plus_options_save_button = document.querySelector('#save'); +if (point_plus_options_save_button !== null) { + point_plus_options_save_button.addEventListener('click', pp_save_options); +} // Getting version from manifest.json function getVersion() { diff --git a/chrome_point_plus/js/point-plus.js b/chrome_point_plus/js/point-plus.js index 3a8b973..97fe039 100644 --- a/chrome_point_plus/js/point-plus.js +++ b/chrome_point_plus/js/point-plus.js @@ -332,6 +332,24 @@ $(document).ready(function() { }); } + // 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(); + } + // 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(); + } + + }); // Showing page action @@ -352,4 +370,172 @@ function escapeHtml(text) { var months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' -]; \ No newline at end of file +]; + + +/* 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]); + } + } + a.id = 'booru_pic_' + booru_picture_count; + $(a).addClass('booru_pic').addClass('booru-' + domain + '-' + id); + a.title = domain + ' image #' + id; + a.target = '_blank'; + + 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('').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); + }); + } + + }) + +} diff --git a/chrome_point_plus/manifest.json b/chrome_point_plus/manifest.json index cc3b29b..cb32808 100644 --- a/chrome_point_plus/manifest.json +++ b/chrome_point_plus/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Point+", - "version": "1.8", + "version": "1.8.1", "author": "Alexey Skobkin", "homepage_url": "https://bitbucket.org/skobkin/chrome_point_plus", "description": "More features for point.im", @@ -29,6 +29,7 @@ "js/jquery-1.10.1.min.js", "js/jquery.fancybox.pack.js", "js/jquery.fancybox-media.js", "js/markitup/jquery.markitup.js", "js/markitup/sets/markdown/set.js", + "js/bquery_ajax.js", "js/options.js", "js/point-plus.js" ], diff --git a/chrome_point_plus/options.html b/chrome_point_plus/options.html index 4931a2e..b434de1 100644 --- a/chrome_point_plus/options.html +++ b/chrome_point_plus/options.html @@ -33,11 +33,19 @@ - +
- + +
+ +
+ +
+ +
+
@@ -81,6 +89,15 @@
+ +
+ +
+ +
+ +
+