mirror of
https://bitbucket.org/skobkin/chrome_point_plus.git
synced 2024-11-23 18:56:04 +00:00
Merged in NokitaKaze/chrome_point_plus (pull request #1)
Первые четыре фичи из point_extension_booru
This commit is contained in:
commit
ab4abe7337
|
@ -154,4 +154,29 @@ div#markItUpText-input {
|
|||
.pp-options #pp-version {
|
||||
margin-top: 6px;
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
|
89
chrome_point_plus/js/bquery_ajax.js
Normal file
89
chrome_point_plus/js/bquery_ajax.js
Normal file
|
@ -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;i<settings.headers.length;i++){
|
||||
this.xhr.setRequestHeader(settings.headers[i][0], settings.headers[i][1]);
|
||||
}
|
||||
}
|
||||
this.xhr.send(this.postdata);
|
||||
}
|
||||
|
||||
$ajax_prot.prototype={
|
||||
version: '0.0.4a',
|
||||
url: '',
|
||||
type: 'GET',
|
||||
async: true,
|
||||
postdata:null,
|
||||
xhr: null,
|
||||
change:function(){
|
||||
if (this.readyState!==4){return;}
|
||||
if (this.status==200){
|
||||
if (this.success!==undefined){this.success(this.responseText,this.textStatus,this);}
|
||||
}else{
|
||||
if (this.error !==undefined){this.error(this.responseText,this.textStatus,this);}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ajax=function (settings){return new $ajax_prot(settings);}
|
||||
|
||||
function urlencode(text){return encodeURIComponent(text);}
|
||||
|
||||
function sad_safe_reg(text){
|
||||
var ar='.-\\/[]{}?+';
|
||||
var s=''; for (var i=0;i<text.length;i++){
|
||||
if ((' '+ar).indexOf(text[i])>0){
|
||||
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<node.childNodes.length;i++){
|
||||
if (r.test(node.childNodes[i].nodeName)){
|
||||
k--;if (k==0){return sad_xml_getnode(node.childNodes[i],t[4]);}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function sad_xml_attribute(node,name){
|
||||
if (node==undefined){return undefined;}
|
||||
var r=new RegExp('^'+sad_safe_reg(name)+'$','i');
|
||||
for (var i=0;i<node.attributes.length;i++){
|
||||
if (r.test(node.attributes[i].nodeName)){return node.attributes[i].nodeValue;}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function sad_x2n(xml){
|
||||
return xml.responseXML.childNodes[xml.responseXML.childNodes.length-1];
|
||||
}
|
|
@ -20,7 +20,15 @@ var ppOptions = [
|
|||
// Font size
|
||||
'option_enlarge_font', 'option_enlarge_font_size',
|
||||
// @ before username
|
||||
'option_at_before_username'
|
||||
'option_at_before_username',
|
||||
//
|
||||
'option_images_load_booru',
|
||||
//
|
||||
'option_videos_parse_webm',
|
||||
//
|
||||
'option_other_hightlight_post_comments',
|
||||
//
|
||||
'option_other_show_recommendation_count',
|
||||
];
|
||||
|
||||
// Saves options to localStorage.
|
||||
|
@ -86,7 +94,13 @@ function pp_save_options() {
|
|||
'option_ws_feeds_blogs': option_ws_feeds_blogs.checked,
|
||||
'option_enlarge_font': option_enlarge_font.checked,
|
||||
'option_enlarge_font_size': option_enlarge_font_size.value,
|
||||
'option_at_before_username': option_at_before_username.checked
|
||||
'option_at_before_username': option_at_before_username.checked,
|
||||
|
||||
'option_images_load_booru' :document.getElementById('option-images-load-booru').checked,
|
||||
'option_videos_parse_webm' :document.getElementById('option-videos-parse-webm').checked,
|
||||
'option_other_hightlight_post_comments' :document.getElementById('option-other-hightlight-post-comments').checked,
|
||||
'option_other_show_recommendation_count':document.getElementById('option-other-show-recommendation-count').checked
|
||||
|
||||
}, function() {
|
||||
// Update status to let user know options were saved.
|
||||
var status = document.getElementById('status');
|
||||
|
@ -183,7 +197,21 @@ function pp_restore_options() {
|
|||
if (options.option_at_before_username == true) {
|
||||
document.getElementById('option-at-before-username').checked = true;
|
||||
}
|
||||
|
||||
|
||||
if (options.option_images_load_booru == true) {
|
||||
document.getElementById('option-images-load-booru').checked = true;
|
||||
}
|
||||
if (options.option_videos_parse_webm == true) {
|
||||
document.getElementById('option-videos-parse-webm').checked = true;
|
||||
}
|
||||
if (options.option_other_hightlight_post_comments == true) {
|
||||
document.getElementById('option-other-hightlight-post-comments').checked = true;
|
||||
}
|
||||
if (options.option_other_show_recommendation_count == true) {
|
||||
document.getElementById('option-other-show-recommendation-count').checked = true;
|
||||
}
|
||||
|
||||
|
||||
// Showing version
|
||||
document.getElementById('pp-version').innerHTML = 'Point+ ' + getVersion() + ' by <a href="http://skobkin-ru.point.im/" target="_blank">@skobkin-ru</a>';
|
||||
});
|
||||
|
@ -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() {
|
||||
|
|
|
@ -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'
|
||||
];
|
||||
];
|
||||
|
||||
|
||||
/* 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('<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);
|
||||
});
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
],
|
||||
|
|
|
@ -33,11 +33,19 @@
|
|||
<input type="checkbox" id="option-fancybox-posts"><label for="option-fancybox-posts">Use for post links (including comments)</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="option">
|
||||
<input type="checkbox" id="option-images-load-original"><label for="option-images-load-original">Load original images instead of thumbnails</label>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="option">
|
||||
<input type="checkbox" id="option-images-load-booru"><label for="option-images-load-booru">Load pictures from Booru, Tumblr and some other sites</label>
|
||||
</div>
|
||||
|
||||
<div class="option">
|
||||
<input type="checkbox" id="option-videos-parse-webm"><label for="option-videos-parse-webm">Parse webm-links and create video instead</label>
|
||||
</div>
|
||||
|
||||
<div class="option">
|
||||
<input type="checkbox" id="option-embedding" disabled><label for="option-embedding">Enable embedding</label>
|
||||
|
||||
|
@ -81,6 +89,15 @@
|
|||
<div class="option">
|
||||
<input type="checkbox" id="option-at-before-username"><label for="option-at-before-username">@ before username</label>
|
||||
</div>
|
||||
|
||||
<div class="option">
|
||||
<input type="checkbox" id="option-other-hightlight-post-comments"><label for="option-other-hightlight-post-comments">Hightlight post with new comments</label>
|
||||
</div>
|
||||
|
||||
<div class="option">
|
||||
<input type="checkbox" id="option-other-show-recommendation-count"><label for="option-other-show-recommendation-count">Show recommendation count and unique commentators count</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="tab-content" id="websocket">
|
||||
|
|
Loading…
Reference in a new issue